53
53
from bzrlib.option import Option
56
class CommandRegistry(registry.Registry):
58
def register(self, cmd, decorate=False):
59
"""Utility function to help register a command
61
:param cmd: Command subclass to register
62
:param decorate: If true, allow overriding an existing command
63
of the same name; the old command is returned by this function.
64
Otherwise it is an error to try to override an existing command.
67
if k.startswith("cmd_"):
68
k_unsquished = _unsquish_command_name(k)
72
previous = self.get(k_unsquished)
74
previous = _builtin_commands().get(k_unsquished)
76
registry.Registry.register(self, k_unsquished, cmd,
77
override_existing=decorate)
79
trace.log_error('Two plugins defined the same command: %r' % k)
80
trace.log_error('Not loading the one in %r' %
81
sys.modules[cmd.__module__])
82
trace.log_error('Previously this command was registered from %r' %
83
sys.modules[previous.__module__])
87
plugin_cmds = CommandRegistry()
59
90
def register_command(cmd, decorate=False):
60
"""Utility function to help register a command
62
:param cmd: Command subclass to register
63
:param decorate: If true, allow overriding an existing command
64
of the same name; the old command is returned by this function.
65
Otherwise it is an error to try to override an existing command.
69
if k.startswith("cmd_"):
70
k_unsquished = _unsquish_command_name(k)
73
if k_unsquished not in plugin_cmds:
74
plugin_cmds[k_unsquished] = cmd
75
## trace.mutter('registered plugin command %s', k_unsquished)
76
if decorate and k_unsquished in builtin_command_names():
77
return _builtin_commands()[k_unsquished]
79
result = plugin_cmds[k_unsquished]
80
plugin_cmds[k_unsquished] = cmd
83
trace.log_error('Two plugins defined the same command: %r' % k)
84
trace.log_error('Not loading the one in %r' % sys.modules[cmd.__module__])
85
trace.log_error('Previously this command was registered from %r' %
86
sys.modules[plugin_cmds[k_unsquished].__module__])
92
return plugin_cmds.register(cmd, decorate)
89
95
def _squish_command_name(cmd):