fix command system
This commit is contained in:
parent
f82dfed644
commit
7ebbad43cb
4 changed files with 9 additions and 7 deletions
|
@ -66,11 +66,13 @@ def traverse_commands(container):
|
||||||
yield attribute
|
yield attribute
|
||||||
|
|
||||||
def is_command(attribute):
|
def is_command(attribute):
|
||||||
from framework import Command
|
from .framework import Command
|
||||||
return isinstance(attribute, Command)
|
return isinstance(attribute, Command)
|
||||||
|
|
||||||
def is_root(namespace):
|
def is_root(namespace):
|
||||||
metaclass = namespace.get("__metaclass__", None)
|
metaclass = namespace.get("__metaclass__", None)
|
||||||
|
if not metaclass:
|
||||||
|
return False
|
||||||
return issubclass(metaclass, Dispatchable)
|
return issubclass(metaclass, Dispatchable)
|
||||||
|
|
||||||
def get_command(host, name):
|
def get_command(host, name):
|
||||||
|
|
|
@ -28,7 +28,7 @@ from .dispatcher import get_command, list_commands
|
||||||
from .mapping import parse_arguments, adapt_arguments
|
from .mapping import parse_arguments, adapt_arguments
|
||||||
from .errors import DefinitionError, CommandError, NoCommandError
|
from .errors import DefinitionError, CommandError, NoCommandError
|
||||||
|
|
||||||
class CommandHost(object):
|
class CommandHost(metaclass=Host):
|
||||||
"""
|
"""
|
||||||
Command host is a hub between numerous command processors and
|
Command host is a hub between numerous command processors and
|
||||||
command containers. Aimed to participate in a dispatching process in
|
command containers. Aimed to participate in a dispatching process in
|
||||||
|
@ -40,7 +40,7 @@ class CommandHost(object):
|
||||||
"""
|
"""
|
||||||
__metaclass__ = Host
|
__metaclass__ = Host
|
||||||
|
|
||||||
class CommandContainer(object):
|
class CommandContainer(metaclass=Container):
|
||||||
"""
|
"""
|
||||||
Command container is an entity which holds defined commands,
|
Command container is an entity which holds defined commands,
|
||||||
allowing them to be dispatched and proccessed correctly. Each
|
allowing them to be dispatched and proccessed correctly. Each
|
||||||
|
@ -143,7 +143,7 @@ class CommandProcessor(object):
|
||||||
def list_commands(self):
|
def list_commands(self):
|
||||||
commands = list_commands(self.COMMAND_HOST)
|
commands = list_commands(self.COMMAND_HOST)
|
||||||
commands = dict(commands)
|
commands = dict(commands)
|
||||||
return sorted(commands.values())
|
return sorted(list(commands.values()), key=lambda k: k.__repr__())
|
||||||
|
|
||||||
class Command(object):
|
class Command(object):
|
||||||
|
|
||||||
|
|
|
@ -230,8 +230,8 @@ def adapt_arguments(command, arguments, args, opts):
|
||||||
|
|
||||||
# Stripping down position information supplied with arguments and
|
# Stripping down position information supplied with arguments and
|
||||||
# options as it won't be needed again.
|
# options as it won't be needed again.
|
||||||
args = map(lambda t: t[0], t[1])
|
args = list(map(lambda t: t[0], args))
|
||||||
opts = map(lambda t: (t[0], t[1]), opts)
|
opts = list(map(lambda t: (t[0], t[1]), opts))
|
||||||
|
|
||||||
# If command has extra option enabled - collect all extra arguments
|
# If command has extra option enabled - collect all extra arguments
|
||||||
# and pass them to a last positional argument command defines as a
|
# and pass them to a last positional argument command defines as a
|
||||||
|
|
|
@ -41,7 +41,7 @@ from plugins.helpers import log, log_calls, Singleton
|
||||||
from plugins.helpers import GajimPluginActivateException
|
from plugins.helpers import GajimPluginActivateException
|
||||||
from plugins.plugin import GajimPlugin, GajimPluginException
|
from plugins.plugin import GajimPlugin, GajimPluginException
|
||||||
|
|
||||||
class PluginManager(object):
|
class PluginManager(metaclass=Singleton):
|
||||||
'''
|
'''
|
||||||
Main plug-in management class.
|
Main plug-in management class.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue