提交 a7db64a4 编写于 作者: R Rudá Moura 提交者: Ruda Moura

avocado.plugins.builtin: Builtin plugins are dynamic.

the builtin plugin list were once static coded, but now
they are search and loaded by run-time,
by inspecting the directory <avocado_home>/avocado/plugins.
Signed-off-by: NRuda Moura <rmoura@redhat.com>
上级 e76464d7
...@@ -14,41 +14,43 @@ ...@@ -14,41 +14,43 @@
"""Builtin plugins.""" """Builtin plugins."""
import os
import logging import logging
from importlib import import_module from importlib import import_module
from avocado.plugins.plugin import Plugin
log = logging.getLogger("avocado.plugins") log = logging.getLogger("avocado.plugins")
__all__ = ['load_builtins'] __all__ = ['load_builtins']
Builtins = [('avocado.plugins.runner', 'TestLister'), Modules = ['avocado.plugins.' + x.rstrip('.py')
('avocado.plugins.runner', 'SystemInformation'), for x in os.listdir(os.path.dirname(__file__))
('avocado.plugins.runner', 'TestRunner'), if x.endswith('.py')]
('avocado.plugins.silentresult', 'Silent'),
('avocado.plugins.xunit', 'XUnit'), Exclude = ['avocado.plugins.__init__',
('avocado.plugins.lister', 'PluginsList'), 'avocado.plugins.builtin',
('avocado.plugins.journal', 'Journal'), 'avocado.plugins.plugin',
('avocado.plugins.datadir', 'DataDirList'), 'avocado.plugins.manager']
('avocado.plugins.multiplexer', 'Multiplexer'),
('avocado.plugins.jsonresult', 'JSON'), Builtins = [x for x in Modules if x not in Exclude]
('avocado.plugins.vm', 'RunVM')]
def load_builtins(set_globals=True): def load_builtins():
"""Load builtin plugins.""" """Load builtin plugins."""
plugins = [] plugins = []
for module, klass in Builtins: for module in Builtins:
try: try:
plugin_mod = import_module(module) plugin_mod = import_module(module)
except ImportError as err: except ImportError as err:
log.error("Could not import plugin '%s': %s", klass, err) log.error("Could not import module plugin '%s': %s", module, err)
continue continue
except SyntaxError as err: except Exception as err:
log.error("Plugin '%s' with syntax error: %s", klass, err) log.error("Module plugin '%s' with error: %s", module, err)
continue continue
if hasattr(plugin_mod, klass): for name in plugin_mod.__dict__:
plugin = getattr(plugin_mod, klass) obj = getattr(plugin_mod, name)
if isinstance(obj, type) and issubclass(obj, Plugin):
plugin = getattr(plugin_mod, name)
plugins.append(plugin) plugins.append(plugin)
if set_globals is True:
globals()[klass] = plugin
return plugins return plugins
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册