Ejemplo n.º 1
0
 def quit(self):
     """
     Quit the IRC bot
     :return:
     """
     if self.inject_before_shutdown and self.entry_queue:
         self.run_tasks()
     SimpleIRCBot.quit(self)
Ejemplo n.º 2
0
 def quit(self):
     """
     Quit the IRC bot
     :return:
     """
     if self.inject_before_shutdown and self.entry_queue:
         self.run_tasks()
     SimpleIRCBot.quit(self)
Ejemplo n.º 3
0
    def __init__(self, config, config_name):
        self.config = config
        self.connection_name = config_name
        self.tracker_config = None
        self.server_list = []
        self.announcer_list = []
        self.ignore_lines = []
        self.message_regex = []

        # If we have a tracker config file, load it
        tracker_config_file = config.get('tracker_file')
        if tracker_config_file:
            self.tracker_config = self.retrieve_tracker_config(
                tracker_config_file)

        channel_list = []
        if self.tracker_config is not None:

            # Validate config with the settings in the torrent file
            for param in self.tracker_config.find('settings'):

                # Handle textbox entries
                if param.tag == 'textbox':
                    value_name = param.get('name')
                else:
                    value_name = param.tag

                # Strip the gazelle prefix
                if value_name.startswith('gazelle_'):
                    value_name = value_name.replace('gazelle_', '')

                # Skip descriptions
                if 'description' in value_name:
                    continue

                if self.config.get(value_name) is None:
                    raise MissingConfigOption(
                        'missing configuration option on irc config %s: %s' %
                        (self.connection_name, value_name))

            # Get the tracker name, for use in the connection name
            self.connection_name = self.tracker_config.get(
                'longName', config_name)

            # Extract the IRC server information
            for server in self.tracker_config.find('servers'):
                self.server_list.extend(server.get('serverNames').split(','))
                channel_list.extend(server.get('channelNames').split(','))
                self.announcer_list.extend(
                    server.get('announcerNames').split(','))

            # Process ignore lines
            for regex_values in self.tracker_config.findall(
                    'parseinfo/ignore/regex'):
                rx = re.compile(regex_values.get('value'),
                                re.UNICODE | re.MULTILINE)
                self.ignore_lines.append(
                    (rx, regex_values.get('expected') != 'false'))

            # Parse patterns
            self.multilinepatterns = self.parse_patterns(
                list(
                    self.tracker_config.findall(
                        'parseinfo/multilinepatterns/extract')))
            self.linepatterns = self.parse_patterns(
                list(
                    self.tracker_config.findall(
                        'parseinfo/linepatterns/extract')))

        # overwrite tracker config with flexget config
        if self.config.get('server'):
            self.server_list = [self.config['server']]
            logger.debug('Using server specified from config')
        channels = config.get('channels')
        if channels:
            channel_list = channels if isinstance(channels,
                                                  list) else [channels]
            logger.debug('Using channel(s) specified from config')

        logger.debug('Servers: {}', self.server_list)
        logger.debug('Channels: {}', channel_list)
        logger.debug('Announcers: {}', self.announcer_list)
        logger.debug('Ignore Lines: {}', len(self.ignore_lines))
        logger.debug('Message Regexs: {}',
                     len(self.multilinepatterns) + len(self.linepatterns))
        for rx, vals, optional in self.multilinepatterns:
            msg = '    Multilinepattern "{}" extracts {}'
            if optional:
                msg += ' (optional)'
            logger.debug(msg, rx.pattern, vals)
        for rx, vals, optional in self.linepatterns:
            msg = '    Linepattern "{}" extracts {}'
            if optional:
                msg += ' (optional)'
            logger.debug(msg, rx.pattern, vals)

        # Init the IRC Bot
        ircbot_config = {
            'servers': self.server_list,
            'port': config['port'],
            'channels': channel_list,
            'nickname': config.get('nickname', 'Flexget-%s' % str(uuid4())),
            'password': config.get('password'),
            'invite_nickname': config.get('invite_nickname'),
            'invite_message': config.get('invite_message'),
            'nickserv_password': config.get('nickserv_password'),
            'use_ssl': config.get('use_ssl'),
        }
        SimpleIRCBot.__init__(self, ircbot_config)

        self.inject_before_shutdown = False
        self.entry_queue = []
        self.line_cache = {}
        self.processing_message = (
            False  # if set to True, it means there's a message processing queued
        )
        self.thread = create_thread(self.connection_name, self)
Ejemplo n.º 4
0
    def __init__(self, config, config_name):
        self.config = config
        self.connection_name = config_name
        self.tracker_config = None
        self.server_list = []
        self.announcer_list = []
        self.ignore_lines = []
        self.message_regex = []

        # If we have a tracker config file, load it
        tracker_config_file = config.get('tracker_file')
        if tracker_config_file:
            self.tracker_config = self.retrieve_tracker_config(tracker_config_file)

        channel_list = []
        if self.tracker_config is not None:

            # Validate config with the settings in the torrent file
            for param in self.tracker_config.find('settings'):

                # Handle textbox entries
                if param.tag == 'textbox':
                    value_name = param.get('name')
                else:
                    value_name = param.tag

                # Strip the gazelle prefix
                if value_name.startswith('gazelle_'):
                    value_name = value_name.replace('gazelle_', '')

                # Skip descriptions
                if 'description' in value_name:
                    continue

                if self.config.get(value_name) is None:
                    raise MissingConfigOption(
                        'missing configuration option on irc config %s: %s'
                        % (self.connection_name, value_name)
                    )

            # Get the tracker name, for use in the connection name
            self.connection_name = self.tracker_config.get('longName', config_name)

            # Extract the IRC server information
            for server in self.tracker_config.find('servers'):
                self.server_list.extend(server.get('serverNames').split(','))
                channel_list.extend(server.get('channelNames').split(','))
                self.announcer_list.extend(server.get('announcerNames').split(','))

            # Process ignore lines
            for regex_values in self.tracker_config.findall('parseinfo/ignore/regex'):
                rx = re.compile(regex_values.get('value'), re.UNICODE | re.MULTILINE)
                self.ignore_lines.append((rx, regex_values.get('expected') != 'false'))

            # Parse patterns
            self.multilinepatterns = self.parse_patterns(
                list(self.tracker_config.findall('parseinfo/multilinepatterns/extract'))
            )
            self.linepatterns = self.parse_patterns(
                list(self.tracker_config.findall('parseinfo/linepatterns/extract'))
            )

        # overwrite tracker config with flexget config
        if self.config.get('server'):
            self.server_list = [self.config['server']]
            log.debug('Using server specified from config')
        channels = config.get('channels')
        if channels:
            channel_list = channels if isinstance(channels, list) else [channels]
            log.debug('Using channel(s) specified from config')

        log.debug('Servers: %s', self.server_list)
        log.debug('Channels: %s', channel_list)
        log.debug('Announcers: %s', self.announcer_list)
        log.debug('Ignore Lines: %d', len(self.ignore_lines))
        log.debug('Message Regexs: %d', len(self.multilinepatterns) + len(self.linepatterns))
        for rx, vals, optional in self.multilinepatterns:
            msg = '    Multilinepattern "%s" extracts %s'
            if optional:
                msg += ' (optional)'
            log.debug(msg, rx.pattern, vals)
        for rx, vals, optional in self.linepatterns:
            msg = '    Linepattern "%s" extracts %s'
            if optional:
                msg += ' (optional)'
            log.debug(msg, rx.pattern, vals)

        # Init the IRC Bot
        ircbot_config = {
            'servers': self.server_list,
            'port': config['port'],
            'channels': channel_list,
            'nickname': config.get('nickname', 'Flexget-%s' % str(uuid4())),
            'invite_nickname': config.get('invite_nickname'),
            'invite_message': config.get('invite_message'),
            'nickserv_password': config.get('nickserv_password'),
            'use_ssl': config.get('use_ssl'),
        }
        SimpleIRCBot.__init__(self, ircbot_config)

        self.inject_before_shutdown = False
        self.entry_queue = []
        self.line_cache = {}
        self.processing_message = (
            False
        )  # if set to True, it means there's a message processing queued
        self.thread = create_thread(self.connection_name, self)