core: plugins now accepts recommendations:
- "recommendations" key can be used in PLUGIN_INFO
- if a plugin can't be found an ImportError is raised if it's a dependency, if it's a recommendation only a warning message is shown, and plugins importation continue
This commit is contained in:
parent
032c34cfdb
commit
1339efa9f0
1 changed files with 15 additions and 6 deletions
|
|
@ -172,9 +172,13 @@ class SAT(service.Service):
|
|||
if not __plugins_to_import:
|
||||
break
|
||||
|
||||
def _import_plugins_from_dict(self, plugins_to_import, import_name=None):
|
||||
def _import_plugins_from_dict(self, plugins_to_import, import_name=None, optional=False):
|
||||
"""Recursively import and their dependencies in the right order
|
||||
@param plugins_to_import: dict where key=import_name and values= (plugin_path, module, plugin_info)"""
|
||||
@param plugins_to_import: dict where key=import_name and values= (plugin_path, module, plugin_info)
|
||||
@param import_name: name of the plugin to import as found in PLUGIN_INFO['import_name']
|
||||
@param optional: if False and plugin is not found, an ImportError exception is raised
|
||||
|
||||
"""
|
||||
if import_name in self.plugins:
|
||||
debug('Plugin [%s] already imported, passing' % import_name)
|
||||
return
|
||||
|
|
@ -182,13 +186,18 @@ class SAT(service.Service):
|
|||
import_name, (plugin_path, mod, plugin_info) = plugins_to_import.popitem()
|
||||
else:
|
||||
if not import_name in plugins_to_import:
|
||||
if optional:
|
||||
warning(_("Recommended plugin not found: %s") % import_name)
|
||||
return
|
||||
error(_("Dependency not found: %s") % import_name)
|
||||
raise ImportError(_('Dependency plugin not found: [%s]') % import_name)
|
||||
plugin_path, mod, plugin_info = plugins_to_import.pop(import_name)
|
||||
dependencies = plugin_info.setdefault("dependencies", [])
|
||||
for dependency in dependencies:
|
||||
if dependency not in self.plugins:
|
||||
debug('Recursively import dependency of [%s]: [%s]' % (import_name, dependency))
|
||||
self._import_plugins_from_dict(plugins_to_import, dependency)
|
||||
recommendations = plugin_info.setdefault("recommendations", [])
|
||||
for to_import in dependencies + recommendations:
|
||||
if to_import not in self.plugins:
|
||||
debug('Recursively import dependency of [%s]: [%s]' % (import_name, to_import))
|
||||
self._import_plugins_from_dict(plugins_to_import, to_import, to_import not in dependencies)
|
||||
info(_("importing plugin: %s"), plugin_info['name'])
|
||||
self.plugins[import_name] = getattr(mod, plugin_info['main'])(self)
|
||||
if 'handler' in plugin_info and plugin_info['handler'] == 'yes':
|
||||
|
|
|
|||
Loading…
Reference in a new issue