diff --git a/avocado/core/app.py b/avocado/core/app.py index ab882f83abb157b24fb816d8882cffafb549bc7f..4463bafa109c36e8e2d3ba1d3290a05d0f58ebea 100644 --- a/avocado/core/app.py +++ b/avocado/core/app.py @@ -16,14 +16,12 @@ The core Avocado application. """ -import logging import os import signal from .parser import Parser from . import output from .output import STD_OUTPUT -from .settings import settings from .dispatcher import CLIDispatcher from .dispatcher import CLICmdDispatcher @@ -46,7 +44,8 @@ class AvocadoApp(object): try: self.cli_dispatcher = CLIDispatcher() self.cli_cmd_dispatcher = CLICmdDispatcher() - self._print_plugin_failures() + output.log_plugin_failures(self.cli_dispatcher.load_failures + + self.cli_cmd_dispatcher.load_failures) self.parser.start() if self.cli_cmd_dispatcher.extensions: self.cli_cmd_dispatcher.map_method('configure', self.parser) @@ -59,21 +58,6 @@ class AvocadoApp(object): finally: output.reconfigure(self.parser.args) - def _print_plugin_failures(self): - failures = (self.cli_dispatcher.load_failures + - self.cli_cmd_dispatcher.load_failures) - if failures: - log = logging.getLogger("avocado.app") - msg_fmt = 'Failed to load plugin from module "%s": %s' - silenced = settings.get_value('plugins', - 'skip_broken_plugin_notification', - list, []) - for failure in failures: - if failure[0].module_name in silenced: - continue - log.error(msg_fmt, failure[0].module_name, - failure[1].__repr__()) - def run(self): try: try: diff --git a/avocado/core/output.py b/avocado/core/output.py index 2de4cab1014cece8d2bfc3e50809f18687d71efc..752929f3dc0d3a26a7d1f1a33c90bf36f998443a 100644 --- a/avocado/core/output.py +++ b/avocado/core/output.py @@ -671,3 +671,23 @@ class Throbber(object): result = self.MOVES[self.position] self._update_position() return result + + +def log_plugin_failures(failures): + """ + Log in the application UI failures to load a set of plugins + + :param failures: a list of load failures, usually comming from a + :class:`avocado.core.dispatcher.Dispatcher` + attribute `load_failures` + """ + log = logging.getLogger("avocado.app") + msg_fmt = 'Failed to load plugin from module "%s": %s' + silenced = settings.get_value('plugins', + 'skip_broken_plugin_notification', + list, []) + for failure in failures: + if failure[0].module_name in silenced: + continue + log.error(msg_fmt, failure[0].module_name, + failure[1].__repr__()) diff --git a/avocado/plugins/base.py b/avocado/plugins/base.py index 2954efad5369d20521cdaccb5dd2f177b9742bbb..03337b79b454d9fd2103d9d9e596243ca2d7bb3a 100644 --- a/avocado/plugins/base.py +++ b/avocado/plugins/base.py @@ -18,6 +18,8 @@ import abc class Plugin(object): + __metaclass__ = abc.ABCMeta + """ Base for all plugins """ @@ -31,10 +33,6 @@ class CLI(Plugin): Plugins that want to add extra options to the core command line application or to sub commands should use the 'avocado.plugins.cli' namespace. """ - __metaclass__ = abc.ABCMeta - - def __init__(self): - super(CLI, self).__init__() @abc.abstractmethod def configure(self, parser): @@ -63,13 +61,9 @@ class CLICmd(Plugin): Plugins that want to add extensions to the run command should use the 'avocado.plugins.cli.cmd' namespace. """ - __metaclass__ = abc.ABCMeta name = None description = None - def __init__(self): - super(CLICmd, self).__init__() - def configure(self, parser): """ Lets the extension add command line options and do early configuration diff --git a/avocado/plugins/plugins.py b/avocado/plugins/plugins.py index c2ca2a143fbff404b472ae3186678d2cdf813f01..e35e67f2a3e0f3c5fab4bacedcb9b621ce1016eb 100644 --- a/avocado/plugins/plugins.py +++ b/avocado/plugins/plugins.py @@ -41,22 +41,20 @@ class Plugins(CLICmd): def run(self, args): log = logging.getLogger("avocado.app") - cli_cmds = dispatcher.CLICmdDispatcher() - msg = 'Plugins that add new commands (avocado.plugins.cli.cmd):' - log.info(msg) - plugin_matrix = [] - for plugin in sorted(cli_cmds): - plugin_matrix.append((plugin.name, plugin.obj.description)) - - for line in astring.iter_tabular_output(plugin_matrix): - log.debug(line) - - msg = 'Plugins that add new options to commands (avocado.plugins.cli):' - cli = dispatcher.CLIDispatcher() - log.info(msg) - plugin_matrix = [] - for plugin in sorted(cli): - plugin_matrix.append((plugin.name, plugin.obj.description)) - - for line in astring.iter_tabular_output(plugin_matrix): - log.debug(line) + plugin_types = [ + (dispatcher.CLICmdDispatcher(), + 'Plugins that add new commands (avocado.plugins.cli.cmd):'), + (dispatcher.CLIDispatcher(), + 'Plugins that add new options to commands (avocado.plugins.cli):') + ] + for plugins_active, msg in plugin_types: + log.info(msg) + plugin_matrix = [] + for plugin in sorted(plugins_active): + plugin_matrix.append((plugin.name, plugin.obj.description)) + + if not plugin_matrix: + log.debug("(No active plugin)") + else: + for line in astring.iter_tabular_output(plugin_matrix): + log.debug(line)