From 7ebbad43cb730459a050d6f5bd587e7582356642 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 27 Jan 2013 19:51:11 +0100 Subject: [PATCH] fix command system --- src/command_system/dispatcher.py | 4 +++- src/command_system/framework.py | 6 +++--- src/command_system/mapping.py | 4 ++-- src/plugins/pluginmanager.py | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/command_system/dispatcher.py b/src/command_system/dispatcher.py index 4b88e5fb3..488dfa341 100644 --- a/src/command_system/dispatcher.py +++ b/src/command_system/dispatcher.py @@ -66,11 +66,13 @@ def traverse_commands(container): yield attribute def is_command(attribute): - from framework import Command + from .framework import Command return isinstance(attribute, Command) def is_root(namespace): metaclass = namespace.get("__metaclass__", None) + if not metaclass: + return False return issubclass(metaclass, Dispatchable) def get_command(host, name): diff --git a/src/command_system/framework.py b/src/command_system/framework.py index 463aee890..ca2469522 100644 --- a/src/command_system/framework.py +++ b/src/command_system/framework.py @@ -28,7 +28,7 @@ from .dispatcher import get_command, list_commands from .mapping import parse_arguments, adapt_arguments from .errors import DefinitionError, CommandError, NoCommandError -class CommandHost(object): +class CommandHost(metaclass=Host): """ Command host is a hub between numerous command processors and command containers. Aimed to participate in a dispatching process in @@ -40,7 +40,7 @@ class CommandHost(object): """ __metaclass__ = Host -class CommandContainer(object): +class CommandContainer(metaclass=Container): """ Command container is an entity which holds defined commands, allowing them to be dispatched and proccessed correctly. Each @@ -143,7 +143,7 @@ class CommandProcessor(object): def list_commands(self): commands = list_commands(self.COMMAND_HOST) commands = dict(commands) - return sorted(commands.values()) + return sorted(list(commands.values()), key=lambda k: k.__repr__()) class Command(object): diff --git a/src/command_system/mapping.py b/src/command_system/mapping.py index 82283df71..7e224907a 100644 --- a/src/command_system/mapping.py +++ b/src/command_system/mapping.py @@ -230,8 +230,8 @@ def adapt_arguments(command, arguments, args, opts): # Stripping down position information supplied with arguments and # options as it won't be needed again. - args = map(lambda t: t[0], t[1]) - opts = map(lambda t: (t[0], t[1]), opts) + args = list(map(lambda t: t[0], args)) + opts = list(map(lambda t: (t[0], t[1]), opts)) # If command has extra option enabled - collect all extra arguments # and pass them to a last positional argument command defines as a diff --git a/src/plugins/pluginmanager.py b/src/plugins/pluginmanager.py index 8f8899d97..395a82a41 100644 --- a/src/plugins/pluginmanager.py +++ b/src/plugins/pluginmanager.py @@ -41,7 +41,7 @@ from plugins.helpers import log, log_calls, Singleton from plugins.helpers import GajimPluginActivateException from plugins.plugin import GajimPlugin, GajimPluginException -class PluginManager(object): +class PluginManager(metaclass=Singleton): ''' Main plug-in management class.