提交 5fc33362 编写于 作者: C Cleber Rosa

New Plugin Architecture: introduce command extensions dispatcher

The `CLICmdDispatcher` is responsible for loading and configuring all
plugins based on `CLICmdBase`. After registering the entry point to
the documented namespace (avocado.plugins.cli.cmd) the new command
should be visible just by running `$ avocado` or `$ avocado --help`.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 e76af8fc
......@@ -20,6 +20,7 @@ import os
from .log import configure as configure_log
from .parser import Parser
from .dispatcher import CLICmdDispatcher
class AvocadoApp(object):
......@@ -35,13 +36,12 @@ class AvocadoApp(object):
configure_log()
self.parser = Parser()
self.cli_cmd_dispatcher = CLICmdDispatcher()
self.parser.start()
if self.cli_cmd_dispatcher.extensions:
self.cli_cmd_dispatcher.map_method('configure', self.parser)
self.parser.finish()
self.ready = True
try:
self.parser.resume()
self.parser.finish()
except IOError:
self.ready = False
def run(self):
if self.ready:
......
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: Red Hat Inc. 2015
# Author: Cleber Rosa <cleber@redhat.com>
"""Extensions/plugins dispatchers."""
from stevedore import ExtensionManager
class Dispatcher(ExtensionManager):
"""
Base dispatcher for various extension types
"""
def __init__(self, namespace):
self.load_failures = []
super(Dispatcher, self).__init__(namespace=namespace,
invoke_on_load=True,
on_load_failure_callback=self.store_load_failure)
@staticmethod
def store_load_failure(manager, entrypoint, exception):
manager.load_failures.append((entrypoint, exception))
class CLICmdDispatcher(Dispatcher):
"""
Calls extensions on configure/run
Automatically adds all the extension with entry points registered under
'avocado.plugins.cli.cmd'
"""
def __init__(self):
super(CLICmdDispatcher, self).__init__('avocado.plugins.cli.cmd')
......@@ -70,12 +70,6 @@ class Parser(object):
description='valid subcommands',
help='subcommand help')
def resume(self):
"""
Resume the parsing of arguments.
Side effect: update attribute `args` (the namespace).
"""
if tree.MULTIPLEX_CAPABLE:
# Allow overriding multiplex variants by plugins args
self.args.default_multiplex_tree = tree.TreeNode()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册