Exemple #1
0
    def on_process_start(self, feed, config):
        if config is False: # handles 'preset: no' form to turn off preset on this feed
            return
        config = self.prepare_config(config)

        # implements --preset NAME
        if feed.manager.options.preset:
            if feed.manager.options.preset not in config:
                feed.enabled = False
                return

        # add global in except when disabled with no_global
        if 'no_global' in config:
            config.remove('no_global')
            if 'global' in config:
                config.remove('global')
        elif not 'global' in config:
            config.append('global')

        log.trace('presets: %s' % config)

        toplevel_presets = feed.manager.config.get('presets', {})

        # check for indentation error (plugin as a preset)
        if (feed.manager.options.test or feed.manager.options.validate) and not self.warned:
            plugins = get_plugin_keywords()
            for name in toplevel_presets.iterkeys():
                if name in plugins:
                    log.warning('Plugin \'%s\' seems to be in the wrong place? You probably wanted to put it in a preset. Please fix the indentation level!' % name)
            self.warned = True

        # apply presets
        for preset in config:
            if preset not in toplevel_presets:
                if preset == 'global':
                    continue
                raise PluginError('Unable to find preset %s for feed %s' % (preset, feed.name), log)
            log.debug('Merging preset %s into feed %s' % (preset, feed.name))

            # We make a copy here because we need to remove
            preset_config = toplevel_presets[preset]
            # When there are presets within presets we remove the preset
            # key from the config and append it's items to our own
            if 'preset' in preset_config:
                nested_presets = self.prepare_config(preset_config['preset'])
                for nested_preset in nested_presets:
                    if nested_preset not in config:
                        config.append(nested_preset)
                    else:
                        log.warning('Presets contain eachother in a loop.')
                # Replace preset_config with a copy without the preset key, to avoid merging errors
                preset_config = dict(preset_config)
                del preset_config['preset']

            # merge
            from flexget.utils.tools import MergeException, merge_dict_from_to
            try:
                merge_dict_from_to(preset_config, feed.config)
            except MergeException, exc:
                raise PluginError('Failed to merge preset %s to feed %s due to %s' % (preset, feed.name, exc))
Exemple #2
0
 def validator(self):
     from flexget import validator
     root = validator.factory()
     valid_plugins = root.accept('list').accept('dict')
     for plugin_name in get_plugin_keywords():
         plugin = get_plugin_by_name(plugin_name)
         if plugin.api_ver > 1 and hasattr(plugin.instance, 'validator'):
             valid_plugins.accept(plugin.instance.validator, key=plugin_name)
     return root
Exemple #3
0
    def validator(self):
        from flexget import validator

        def build_list(series):
            """Build series list to series."""
            series.accept('text')
            series.accept('number')
            bundle = series.accept('dict')
            # prevent invalid indentation level
            bundle.reject_keys(['set', 'path', 'timeframe', 'name_regexp',
                'ep_regexp', 'id_regexp', 'watched', 'quality', 'min_quality',
                'max_quality', 'qualities', 'exact', 'from_group'],
                'Option \'$key\' has invalid indentation level. It needs 2 more spaces.')
            bundle.accept_any_key('path')
            options = bundle.accept_any_key('dict')
            self.build_options_validator(options)

        root = validator.factory()

        # simple format:
        #   - series
        #   - another series

        simple = root.accept('list')
        build_list(simple)

        # advanced format:
        #   settings:
        #     group: {...}
        #   group:
        #     {...}

        advanced = root.accept('dict')
        settings = advanced.accept('dict', key='settings')
        settings.reject_keys(get_plugin_keywords())
        settings_group = settings.accept_any_key('dict')
        self.build_options_validator(settings_group)

        group = advanced.accept_any_key('list')
        build_list(group)

        return root