fix command system

This commit is contained in:
Yann Leboulanger 2013-01-27 19:51:11 +01:00
parent f82dfed644
commit 7ebbad43cb
4 changed files with 9 additions and 7 deletions

View file

@ -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):

View file

@ -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):

View file

@ -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

View file

@ -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.