예제 #1
0
    def __getattr__(self, item):
        """Returns a function for all on_task_* and on_process_* events, that runs all the configured plugins."""
        for phase, method in phase_methods.iteritems():
            # TODO: Deal with entry phases
            if item == method and phase not in ['accept', 'reject', 'fail']:
                break
        else:
            raise AttributeError(item)

        def handle_phase(task, config):
            """Function that runs all of the configured plugins which act on the current phase."""
            # Keep a list of all results, for input plugin combining
            results = []
            for item in config:
                for plugin_name, plugin_config in item.iteritems():
                    if phase in get_phases_by_plugin(plugin_name):
                        method = get_plugin_by_name(
                            plugin_name).phase_handlers[phase]
                        log.debug('Running plugin %s' % plugin_name)
                        result = method(task, plugin_config)
                        if isinstance(result, list):
                            results.extend(result)
            return results

        return handle_phase
예제 #2
0
    def __getattr__(self, item):
        """Provides handlers for all phases except input and entry phases."""
        for phase, method in phase_methods.iteritems():
            # TODO: Deal with entry phases
            if item == method and phase not in ['accept', 'reject', 'fail', 'input']:
                break
        else:
            raise AttributeError(item)

        def handle_phase(feed, config):
            if feed.name not in self.feed_phases:
                log.debug('No config dict was generated for this feed.')
                return
            entry_actions = {
                'accept': feed.accept,
                'reject': feed.reject,
                'fail': feed.fail}
            for item in self.feed_phases[feed.name][phase]:
                requirement, action = item.items()[0]
                passed_entries = [e for e in feed.entries if self.check_condition(requirement, e)]
                if passed_entries:
                    if isinstance(action, basestring):
                        # Simple entry action (accept, reject or fail) was specified as a string
                        for entry in passed_entries:
                            entry_actions[action](entry, 'Matched requirement: %s' % requirement)
                    else:
                        # Other plugins were specified to run on this entry
                        fake_feed = Feed(feed.manager, feed.name, feed.config)
                        fake_feed.session = feed.session
                        fake_feed.entries = passed_entries
                        fake_feed.accepted = [e for e in feed.accepted if self.check_condition(requirement, e)]
                        fake_feed.rejected = [e for e in feed.rejected if self.check_condition(requirement, e)]
                        try:
                            for plugin_name, plugin_config in action.iteritems():
                                plugin = get_plugin_by_name(plugin_name)
                                method = plugin.phase_handlers[phase]
                                method(fake_feed, plugin_config)
                        except Exception:
                            raise
                        else:
                            # Populate changes from the fake feed to the real one
                            for e in fake_feed.accepted:
                                feed.accept(e, e.get('reason'))
                            for e in fake_feed.rejected:
                                feed.reject(e, e.get('reason'))
                            for e in fake_feed.failed:
                                feed.fail(e, e.get('reason'))
                feed.purge()

        handle_phase.priority = 80
        return handle_phase
예제 #3
0
    def __getattr__(self, item):
        """Provides handlers for all phases except input and entry phases."""
        for phase, method in phase_methods.iteritems():
            # TODO: Deal with entry phases
            if item == method and phase not in [
                    'accept', 'reject', 'fail', 'input'
            ]:
                break
        else:
            raise AttributeError(item)

        def handle_phase(task, config):
            if task.name not in self.task_phases:
                log.debug('No config dict was generated for this task.')
                return
            entry_actions = {
                'accept': Entry.accept,
                'reject': Entry.reject,
                'fail': Entry.fail
            }
            for item in self.task_phases[task.name][phase]:
                requirement, action = item.items()[0]
                passed_entries = [
                    e for e in task.entries
                    if self.check_condition(requirement, e)
                ]
                if passed_entries:
                    if isinstance(action, basestring):
                        # Simple entry action (accept, reject or fail) was specified as a string
                        for entry in passed_entries:
                            entry_actions[action](
                                entry, 'Matched requirement: %s' % requirement)
                    else:
                        # Other plugins were specified to run on this entry
                        fake_task = Task(task.manager, task.name, task.config)
                        fake_task.session = task.session
                        # This entry still belongs to our feed, accept/reject etc. will carry through.
                        fake_task.all_entries[:] = passed_entries

                        try:
                            for plugin_name, plugin_config in action.iteritems(
                            ):
                                plugin = get_plugin_by_name(plugin_name)
                                method = plugin.phase_handlers[phase]
                                method(fake_task, plugin_config)
                        except Exception:
                            raise

        handle_phase.priority = 80
        return handle_phase
예제 #4
0
    def __getattr__(self, item):
        """Provides handlers for all phases except input and entry phases."""
        for phase, method in phase_methods.iteritems():
            # TODO: Deal with entry phases
            if item == method and phase not in ['accept', 'reject', 'fail', 'input']:
                break
        else:
            raise AttributeError(item)

        def handle_phase(task, config):
            if task.name not in self.task_phases:
                log.debug('No config dict was generated for this task.')
                return
            entry_actions = {
                'accept': Entry.accept,
                'reject': Entry.reject,
                'fail': Entry.fail}
            for item in self.task_phases[task.name][phase]:
                requirement, action = item.items()[0]
                passed_entries = [e for e in task.entries if self.check_condition(requirement, e)]
                if passed_entries:
                    if isinstance(action, basestring):
                        # Simple entry action (accept, reject or fail) was specified as a string
                        for entry in passed_entries:
                            entry_actions[action](entry, 'Matched requirement: %s' % requirement)
                    else:
                        # Other plugins were specified to run on this entry
                        fake_task = Task(task.manager, task.name, task.config)
                        fake_task.session = task.session
                        # This entry still belongs to our feed, accept/reject etc. will carry through.
                        fake_task.all_entries[:] = passed_entries

                        try:
                            for plugin_name, plugin_config in action.iteritems():
                                plugin = get_plugin_by_name(plugin_name)
                                method = plugin.phase_handlers[phase]
                                method(fake_task, plugin_config)
                        except Exception:
                            raise

        handle_phase.priority = 80
        return handle_phase
예제 #5
0
파일: sequence.py 프로젝트: Gyran/Flexget
    def __getattr__(self, item):
        """Returns a function for all on_task_* and on_process_* events, that runs all the configured plugins."""
        for phase, method in phase_methods.iteritems():
            if item == method and phase not in ['accept', 'reject', 'fail']:
                break
        else:
            raise AttributeError(item)

        def handle_phase(task, config):
            """Function that runs all of the configured plugins which act on the current phase."""
            # Keep a list of all results, for input plugin combining
            results = []
            for item in config:
                for plugin_name, plugin_config in item.iteritems():
                    if phase in get_phases_by_plugin(plugin_name):
                        method = get_plugin_by_name(plugin_name).phase_handlers[phase]
                        log.debug('Running plugin %s' % plugin_name)
                        result = method(task, plugin_config)
                        if isinstance(result, list):
                            results.extend(result)
            return results

        return handle_phase