提交 a951a6cd 编写于 作者: L Lukáš Doktor

Merge pull request #1124 from clebergnu/plugin_improvements

Plugin Improvements
......@@ -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:
......
......@@ -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__())
......@@ -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
......
......@@ -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)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册