def initialize(self): if self.instance is not None: # We already initialized return # Create plugin instance self.instance = self.plugin_class() self.instance.plugin_info = self # give plugin easy access to its own info self.instance.log = logging.getLogger(getattr(self.instance, "LOGGER_NAME", None) or self.name) if hasattr(self.instance, 'schema'): self.schema = self.instance.schema elif hasattr(self.instance, 'validator'): self.schema = self.instance.validator().schema() else: # TODO: I think plugins without schemas should not be allowed in config, maybe rethink this self.schema = {} if self.schema is not None: location = '/schema/plugin/%s' % self.name self.schema['id'] = location config_schema.register_schema(location, self.schema) self.build_phase_handlers()
def initialize(self): if self.instance is not None: # We already initialized return # Create plugin instance self.instance = self.plugin_class() self.instance.plugin_info = self # give plugin easy access to its own info self.instance.log = logging.getLogger(getattr(self.instance, "LOGGER_NAME", None) or self.name) if hasattr(self.instance, 'schema'): self.schema = self.instance.schema elif hasattr(self.instance, 'validator'): self.schema = self.instance.validator().schema() else: # TODO: I think plugins without schemas should not be allowed in config, maybe rethink this self.schema = {} if self.schema is not None: location = '/schema/plugin/%s' % self.name self.schema['id'] = location config_schema.register_schema(location, self.schema) self.build_phase_handlers()
def initialize(self) -> None: if self.instance is not None: # We already initialized return # Create plugin instance self.instance = self.plugin_class() self.instance.plugin_info = self # give plugin easy access to its own info self.instance.logger = logger.bind( name=getattr(self.instance, "LOGGER_NAME", None) or self.name) if hasattr(self.instance, 'schema'): self.schema = self.instance.schema elif hasattr(self.instance, 'validator'): self.schema = self.instance.validator().schema() else: # TODO: I think plugins without schemas should not be allowed in config, maybe rethink this self.schema = {} if self.schema is not None: self.schema_id = f'/schema/plugin/{self.name}' config_schema.register_schema(self.schema_id, self.schema) self.build_phase_handlers()
def register_config(): register_config_key('schedules', main_schema) register_schema('/schema/config/schedule', schedule_schema)
def register_config(): register_config_key('schedules', main_schema) register_schema('/schema/config/schedule', schedule_schema)
if min_api is not None and plugin.api_ver < min_api: return False return True return ifilter(matches, plugins.itervalues()) def plugin_schemas(**kwargs): """Create a dict schema that matches plugins specified by `kwargs`""" return {'type': 'object', 'properties': dict((p.name, {'$ref': p.schema['id']}) for p in get_plugins(**kwargs)), 'additionalProperties': False, 'error_additionalProperties': '{{message}} Only known plugin names are valid keys.', 'patternProperties': {'^_': {'title': 'Disabled Plugin'}}} config_schema.register_schema('/schema/plugins', plugin_schemas) def get_plugins_by_phase(phase): """ .. deprecated:: 1.0.3328 Use :func:`get_plugins` instead Return an iterator over all plugins that hook :phase: """ warnings.warn('Deprecated API', DeprecationWarning, stacklevel=2) if not phase in phase_methods: raise Exception('Unknown phase %s' % phase) return get_plugins(phase=phase)
def register_config(): register_config_key("schedules", main_schema) register_schema("/schema/config/schedule", schedule_schema)
dict((p.name, { '$ref': p.schema['id'] }) for p in get_plugins(**kwargs)), 'additionalProperties': False, 'error_additionalProperties': '{{message}} Only known plugin names are valid keys.', 'patternProperties': { '^_': { 'title': 'Disabled Plugin' } } } config_schema.register_schema('/schema/plugins', plugin_schemas) def get_plugins_by_phase(phase): """ .. deprecated:: 1.0.3328 Use :func:`get_plugins` instead Return an iterator over all plugins that hook :phase: """ warnings.warn('Deprecated API', DeprecationWarning, stacklevel=2) if not phase in phase_methods: raise Exception('Unknown phase %s' % phase) return get_plugins(phase=phase)
def __init__(self, plugin_class, name=None, groups=None, builtin=False, debug=False, api_ver=1, contexts=None, category=None): """ Register a plugin. :param plugin_class: The plugin factory. :param string name: Name of the plugin (if not given, default to factory class name in underscore form). :param list groups: Groups this plugin belongs to. :param bool builtin: Auto-activated? :param bool debug: True if plugin is for debugging purposes. :param int api_ver: Signature of callback hooks (1=task; 2=task,config). :param list contexts: List of where this plugin is configurable. Can be 'task', 'root', or None :param string category: The type of plugin. Can be one of the task phases. Defaults to the package name containing the plugin. """ dict.__init__(self) if groups is None: groups = [] if name is None: # Convention is to take camel-case class name and rewrite it to an underscore form, # e.g. 'PluginName' to 'plugin_name' name = re.sub('[A-Z]+', lambda i: '_' + i.group(0).lower(), plugin_class.__name__).lstrip('_') if contexts is None: contexts = ['task'] elif isinstance(contexts, basestring): contexts = [contexts] if category is None and plugin_class.__module__.startswith('flexget.plugins'): # By default look at the containing package of the plugin. category = plugin_class.__module__.split('.')[-2] # Set basic info attributes self.api_ver = api_ver self.name = name self.groups = groups self.builtin = builtin self.debug = debug self.contexts = contexts self.category = category self.phase_handlers = {} # Create plugin instance self.plugin_class = plugin_class self.instance = self.plugin_class() self.instance.plugin_info = self # give plugin easy access to its own info self.instance.log = logging.getLogger(getattr(self.instance, "LOGGER_NAME", None) or self.name) if hasattr(self.instance, 'schema'): self.schema = self.instance.schema elif hasattr(self.instance, 'validator'): self.schema = self.instance.validator().schema() else: # TODO: I think plugins without schemas should not be allowed in config, maybe rethink this self.schema = {} if self.schema is not None: location = '/schema/plugin/%s' % self.name self.schema['id'] = location config_schema.register_schema(location, self.schema) if self.name in plugins: PluginInfo.dupe_counter += 1 log.critical('Error while registering plugin %s. %s' % (self.name, ('A plugin with the name %s is already registered' % self.name))) else: self.build_phase_handlers() plugins[self.name] = self
from flexget import config_schema from flexget.event import fire_event from flexget.utils.tools import pid_exists log = logging.getLogger('manager') Base = declarative_base() Session = sessionmaker() manager = None DB_CLEANUP_INTERVAL = timedelta(days=7) # Validator that handles root structure of config. _root_config_schema = {'type': 'object', 'additionalProperties': False} # TODO: Is /schema/root this the best place for this? config_schema.register_schema('/schema/root', _root_config_schema) def register_config_key(key, schema, required=False): """ Registers a valid root level key for the config. :param string key: Name of the root level key being registered. :param dict schema: Schema for the key. :param bool required: Specify whether this is a mandatory key. """ _root_config_schema.setdefault('properties', {})[key] = schema if required: _root_config_schema.setdefault('required', []).append(key)
from sqlalchemy.pool import SingletonThreadPool from flexget.event import fire_event from flexget import config_schema log = logging.getLogger('manager') Base = declarative_base() Session = sessionmaker() manager = None DB_CLEANUP_INTERVAL = timedelta(days=7) # Validator that handles root structure of config. _root_config_schema = {'type': 'object', 'additionalProperties': False} # TODO: Is /schema/root this the best place for this? config_schema.register_schema('/schema/root', _root_config_schema) def register_config_key(key, schema, required=False): """ Registers a valid root level key for the config. :param string key: Name of the root level key being registered. :param dict schema: Schema for the key. :param bool required: Specify whether this is a mandatory key. """ _root_config_schema.setdefault('properties', {})[key] = schema if required: _root_config_schema.setdefault('required', []).append(key)
def __init__(self, plugin_class, name=None, groups=None, builtin=False, debug=False, api_ver=1, contexts=None, category=None): """ Register a plugin. :param plugin_class: The plugin factory. :param string name: Name of the plugin (if not given, default to factory class name in underscore form). :param list groups: Groups this plugin belongs to. :param bool builtin: Auto-activated? :param bool debug: True if plugin is for debugging purposes. :param int api_ver: Signature of callback hooks (1=task; 2=task,config). :param list contexts: List of where this plugin is configurable. Can be 'task', 'root', or None :param string category: The type of plugin. Can be one of the task phases. Defaults to the package name containing the plugin. """ dict.__init__(self) if groups is None: groups = [] if name is None: # Convention is to take camel-case class name and rewrite it to an underscore form, # e.g. 'PluginName' to 'plugin_name' name = re.sub('[A-Z]+', lambda i: '_' + i.group(0).lower(), plugin_class.__name__).lstrip('_') if contexts is None: contexts = ['task'] elif isinstance(contexts, basestring): contexts = [contexts] if category is None: # By default look at the containing package of the plugin. category = plugin_class.__module__.split('.')[-2] # Set basic info attributes self.api_ver = api_ver self.name = name self.groups = groups self.builtin = builtin self.debug = debug self.contexts = contexts self.category = category self.phase_handlers = {} # Create plugin instance self.plugin_class = plugin_class self.instance = self.plugin_class() self.instance.plugin_info = self # give plugin easy access to its own info self.instance.log = logging.getLogger(getattr(self.instance, "LOGGER_NAME", None) or self.name) if hasattr(self.instance, 'schema'): self.schema = self.instance.schema elif hasattr(self.instance, 'validator'): self.schema = self.instance.validator().schema() else: # TODO: I think plugins without schemas should not be allowed in config, maybe rethink this self.schema = {} if self.schema is not None: config_schema.register_schema('/schema/plugin/%s' % self.name, self.schema) if self.name in plugins: PluginInfo.dupe_counter += 1 log.critical('Error while registering plugin %s. %s' % (self.name, ('A plugin with the name %s is already registered' % self.name))) else: self.build_phase_handlers() plugins[self.name] = self