当前位置: 首页>>代码示例>>Python>>正文


Python task.Task类代码示例

本文整理汇总了Python中flexget.task.Task的典型用法代码示例。如果您正苦于以下问题:Python Task类的具体用法?Python Task怎么用?Python Task使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Task类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_phase

        def handle_phase(task, config):
            entry_actions = {'accept': Entry.accept, 'reject': Entry.reject, 'fail': Entry.fail}
            for item in config:
                requirement, action = list(item.items())[0]
                passed_entries = (e for e in task.entries if self.check_condition(requirement, e))
                if isinstance(action, str):
                    if not phase == 'filter':
                        continue
                    # 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, config=action, options=task.options)
                    fake_task.session = task.session
                    # This entry still belongs to our feed, accept/reject etc. will carry through.
                    fake_task.all_entries[:] = passed_entries

                    methods = {}
                    for plugin_name, plugin_config in action.items():
                        p = plugin.get_plugin_by_name(plugin_name)
                        method = p.phase_handlers.get(phase)
                        if method:
                            methods[method] = (fake_task, plugin_config)
                    # Run the methods in priority order
                    for method in sorted(methods, reverse=True):
                        method(*methods[method])
开发者ID:Flexget,项目名称:Flexget,代码行数:27,代码来源:if_condition.py

示例2: handle_phase

        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
开发者ID:Crupuk,项目名称:Flexget,代码行数:30,代码来源:if_condition.py

示例3: create_tasks

    def create_tasks(self):
        """Creates instances of all configured tasks"""
        from flexget.task import Task
        # Clear tasks dict
        self.tasks = {}

        # Backwards compatibility with feeds key
        if 'feeds' in self.config:
            log.warning('`feeds` key has been deprecated and replaced by `tasks`. Please update your config.')
            if 'tasks' in self.config:
                log.error('You have defined both `feeds` and `tasks`. Stop that.')
            self.config['tasks'] = self.config.pop('feeds')
        # construct task list
        tasks = self.config.get('tasks', {}).keys()
        for name in tasks:
            # Make sure numeric task names are turned into strings. #1763, #1961
            if not isinstance(name, basestring):
                self.config['tasks'][unicode(name)] = self.config['tasks'].pop(name)
                name = unicode(name)
            # create task
            task = Task(self, name, self.config['tasks'][name])
            # if task name is prefixed with _ it's disabled
            if name.startswith('_'):
                task.enabled = False
            self.tasks[name] = task
开发者ID:Klaboe,项目名称:Flexget,代码行数:25,代码来源:manager.py

示例4: update_tasks

    def update_tasks(self):
        """Updates instances of all configured tasks from config"""
        from flexget.task import Task

        if not isinstance(self.config['tasks'], dict):
            log.critical('Tasks is in wrong datatype, please read configuration guides')
            return

        # construct task list
        for name in self.config.get('tasks', {}):
            if not isinstance(self.config['tasks'][name], dict):
                continue
            if name in self.tasks:
                # This task already has an instance, update it
                self.tasks[name].config = deepcopy(self.config['tasks'][name])
                if not name.startswith('_'):
                    self.tasks[name].enabled = True
            else:
                # Create task
                task = Task(self, name, deepcopy(self.config['tasks'][name]))
                # If task name is prefixed with _ it's disabled
                if name.startswith('_'):
                    task.enabled = False
                self.tasks[name] = task
        # Delete any task instances that are no longer in the config
        for name in [n for n in self.tasks if n not in self.config['tasks']]:
            del self.tasks[name]
开发者ID:Donavan,项目名称:Flexget,代码行数:27,代码来源:manager.py

示例5: execute_task

 def execute_task(self, name, abort_ok=False, options=None):
     """Use to execute one test task from config"""
     log.info('********** Running task: %s ********** ' % name)
     config = self.manager.config['tasks'][name]
     if hasattr(self, 'task'):
         if hasattr(self, 'session'):
             self.task.session.close() # pylint: disable-msg=E0203
     self.task = Task(self.manager, name, config=config, options=options)
     try:
         self.task.execute()
     except TaskAbort:
         if not abort_ok:
             raise
开发者ID:DSchau,项目名称:Flexget,代码行数:13,代码来源:__init__.py

示例6: execute

    def execute(task_name, abort=False, options=None):
        """
        Use to execute one test task from config.

        :param abort: If `True` expect (and require) this task to abort.
        """
        log.info('********** Running task: %s ********** ' % task_name)
        config = manager.config['tasks'][task_name]
        task = Task(manager, task_name, config=config, options=options)

        try:
            if abort:
                with pytest.raises(TaskAbort):
                    task.execute()
            else:
                task.execute()
        finally:
            try:
                task.session.close()
            except Exception:
                pass
        return task
开发者ID:jawilson,项目名称:Flexget,代码行数:22,代码来源:conftest.py

示例7: edit_text

def edit_text(root, name):
    config_type = root.rstrip('s')
    context = {
        'name': name,
        'root': root,
        'config_type': config_type}

    if request.method == 'POST':
        context['config'] = request.form['config']
        try:
            config = yaml.load(request.form['config'])
        except yaml.scanner.ScannerError as e:
            flash('Invalid YAML document: %s' % e, 'error')
            log.exception(e)
        else:
            # valid yaml, now run validator
            errors = Task.validate_config(config)
            if errors:
                for error in errors:
                    flash(error, 'error')
                context['config'] = request.form['config']
            else:
                manager.config[root][name] = config
                manager.save_config()
                context['config'] = yaml.dump(config, default_flow_style=False)
                if request.form.get('name') != name:
                    # Renaming
                    new_name = request.form.get('name')
                    if new_name in manager.config[root]:
                        flash('%s with name %s already exists' % (config_type.capitalize(), new_name), 'error')
                    else:
                        # Do the rename
                        manager.config[root][new_name] = manager.config[root][name]
                        del manager.config[root][name]
                        manager.save_config()
                        flash('%s %s renamed to %s.' % (config_type.capitalize(), name, new_name), 'success')
                        return redirect(url_for('edit_text', root=root, name=new_name))
                else:
                    flash('Configuration saved', 'success')
    else:
        config = manager.config[root][name]
        if config:
            context['config'] = yaml.dump(config, default_flow_style=False)
        else:
            context['config'] = ''
    context['related'] = get_related(root, name)
    return render_template('configure/edit_text.html', **context)
开发者ID:Crupuk,项目名称:Flexget,代码行数:47,代码来源:configure.py

示例8: FlexGetBase

class FlexGetBase(object):
    __yaml__ = """# Yaml goes here"""

    # Set this to True to get a UNIQUE tmpdir; the tmpdir is created on
    # setup as "./tmp/<testname>" and automatically removed on teardown.
    #
    # The instance variable __tmp__ is set to the absolute name of the tmpdir
    # (ending with "os.sep"), and any occurrence of "__tmp__" in __yaml__ or
    # a @with_filecopy destination is also replaced with it.

    __tmp__ = False

    def __init__(self):
        self.log = log
        self.manager = None
        self.task = None
        self.database_uri = None
        self.base_path = os.path.dirname(__file__)

    def setup(self):
        """Set up test env"""
        setup_once()
        if self.__tmp__:
            self.__tmp__ = util.maketemp() + '/'
            self.__yaml__ = self.__yaml__.replace("__tmp__", self.__tmp__)
        self.manager = MockManager(self.__yaml__, self.__class__.__name__, db_uri=self.database_uri)

    def teardown(self):
        try:
            try:
                self.task.session.close()
            except:
                pass
            self.manager.shutdown()
            self.manager.__del__()
        finally:
            if self.__tmp__:
                import shutil
                log.trace('Removing tmpdir %r' % self.__tmp__)
                shutil.rmtree(self.__tmp__.rstrip(os.sep))

    def execute_task(self, name, abort_ok=False, options=None):
        """Use to execute one test task from config"""
        log.info('********** Running task: %s ********** ' % name)
        config = self.manager.config['tasks'][name]
        if hasattr(self, 'task'):
            if hasattr(self, 'session'):
                self.task.session.close() # pylint: disable-msg=E0203
        self.task = Task(self.manager, name, config=config, options=options)
        try:
            self.task.execute()
        except TaskAbort:
            if not abort_ok:
                raise

    def dump(self):
        """Helper method for debugging"""
        from flexget.plugins.output.dump import dump
        #from flexget.utils.tools import sanitize
        # entries = sanitize(self.task.entries)
        # accepted = sanitize(self.task.accepted)
        # rejected = sanitize(self.task.rejected)
        print '\n-- ENTRIES: -----------------------------------------------------'
        # print yaml.safe_dump(entries)
        dump(self.task.entries, True)
        print '-- ACCEPTED: ----------------------------------------------------'
        # print yaml.safe_dump(accepted)
        dump(self.task.entries, True)
        print '-- REJECTED: ----------------------------------------------------'
        # print yaml.safe_dump(rejected)
        dump(self.task.entries, True)
开发者ID:DSchau,项目名称:Flexget,代码行数:71,代码来源:__init__.py


注:本文中的flexget.task.Task类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。