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

Merge pull request #1124 from clebergnu/plugin_improvements

Plugin Improvements
...@@ -16,14 +16,12 @@ ...@@ -16,14 +16,12 @@
The core Avocado application. The core Avocado application.
""" """
import logging
import os import os
import signal import signal
from .parser import Parser from .parser import Parser
from . import output from . import output
from .output import STD_OUTPUT from .output import STD_OUTPUT
from .settings import settings
from .dispatcher import CLIDispatcher from .dispatcher import CLIDispatcher
from .dispatcher import CLICmdDispatcher from .dispatcher import CLICmdDispatcher
...@@ -46,7 +44,8 @@ class AvocadoApp(object): ...@@ -46,7 +44,8 @@ class AvocadoApp(object):
try: try:
self.cli_dispatcher = CLIDispatcher() self.cli_dispatcher = CLIDispatcher()
self.cli_cmd_dispatcher = CLICmdDispatcher() 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() self.parser.start()
if self.cli_cmd_dispatcher.extensions: if self.cli_cmd_dispatcher.extensions:
self.cli_cmd_dispatcher.map_method('configure', self.parser) self.cli_cmd_dispatcher.map_method('configure', self.parser)
...@@ -59,21 +58,6 @@ class AvocadoApp(object): ...@@ -59,21 +58,6 @@ class AvocadoApp(object):
finally: finally:
output.reconfigure(self.parser.args) 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): def run(self):
try: try:
try: try:
......
...@@ -671,3 +671,23 @@ class Throbber(object): ...@@ -671,3 +671,23 @@ class Throbber(object):
result = self.MOVES[self.position] result = self.MOVES[self.position]
self._update_position() self._update_position()
return result 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 ...@@ -18,6 +18,8 @@ import abc
class Plugin(object): class Plugin(object):
__metaclass__ = abc.ABCMeta
""" """
Base for all plugins Base for all plugins
""" """
...@@ -31,10 +33,6 @@ class CLI(Plugin): ...@@ -31,10 +33,6 @@ class CLI(Plugin):
Plugins that want to add extra options to the core command line application Plugins that want to add extra options to the core command line application
or to sub commands should use the 'avocado.plugins.cli' namespace. or to sub commands should use the 'avocado.plugins.cli' namespace.
""" """
__metaclass__ = abc.ABCMeta
def __init__(self):
super(CLI, self).__init__()
@abc.abstractmethod @abc.abstractmethod
def configure(self, parser): def configure(self, parser):
...@@ -63,13 +61,9 @@ class CLICmd(Plugin): ...@@ -63,13 +61,9 @@ class CLICmd(Plugin):
Plugins that want to add extensions to the run command should use the Plugins that want to add extensions to the run command should use the
'avocado.plugins.cli.cmd' namespace. 'avocado.plugins.cli.cmd' namespace.
""" """
__metaclass__ = abc.ABCMeta
name = None name = None
description = None description = None
def __init__(self):
super(CLICmd, self).__init__()
def configure(self, parser): def configure(self, parser):
""" """
Lets the extension add command line options and do early configuration Lets the extension add command line options and do early configuration
......
...@@ -41,22 +41,20 @@ class Plugins(CLICmd): ...@@ -41,22 +41,20 @@ class Plugins(CLICmd):
def run(self, args): def run(self, args):
log = logging.getLogger("avocado.app") log = logging.getLogger("avocado.app")
cli_cmds = dispatcher.CLICmdDispatcher() plugin_types = [
msg = 'Plugins that add new commands (avocado.plugins.cli.cmd):' (dispatcher.CLICmdDispatcher(),
log.info(msg) 'Plugins that add new commands (avocado.plugins.cli.cmd):'),
plugin_matrix = [] (dispatcher.CLIDispatcher(),
for plugin in sorted(cli_cmds): 'Plugins that add new options to commands (avocado.plugins.cli):')
plugin_matrix.append((plugin.name, plugin.obj.description)) ]
for plugins_active, msg in plugin_types:
for line in astring.iter_tabular_output(plugin_matrix): log.info(msg)
log.debug(line) plugin_matrix = []
for plugin in sorted(plugins_active):
msg = 'Plugins that add new options to commands (avocado.plugins.cli):' plugin_matrix.append((plugin.name, plugin.obj.description))
cli = dispatcher.CLIDispatcher()
log.info(msg) if not plugin_matrix:
plugin_matrix = [] log.debug("(No active plugin)")
for plugin in sorted(cli): else:
plugin_matrix.append((plugin.name, plugin.obj.description)) for line in astring.iter_tabular_output(plugin_matrix):
log.debug(line)
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.
先完成此消息的编辑!
想要评论请 注册