~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Robert Collins
  • Date: 2005-10-30 01:40:16 UTC
  • Revision ID: robertc@robertcollins.net-20051030014016-98a4fba7d6a4176c
Support decoration of commands.

Commands.register_command now takes an optional flag to signal that the
registrant is planning to decorate an existing command. When given
multiple plugins registering a command is not an error, and the original
command class (whether built in or a plugin based one) is returned to the
caller. There is a new error 'MustUseDecorated' for signalling when a
wrapping command should switch to the original version. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
plugin_cmds = {}
45
45
 
46
46
 
47
 
def register_command(cmd):
 
47
def register_command(cmd, decorate=False):
48
48
    "Utility function to help register a command"
49
49
    global plugin_cmds
50
50
    k = cmd.__name__
55
55
    if not plugin_cmds.has_key(k_unsquished):
56
56
        plugin_cmds[k_unsquished] = cmd
57
57
        mutter('registered plugin command %s', k_unsquished)      
 
58
        if decorate and k_unsquished in builtin_command_names():
 
59
            return _builtin_commands()[k_unsquished]
 
60
    elif decorate:
 
61
        result = plugin_cmds[k_unsquished]
 
62
        plugin_cmds[k_unsquished] = cmd
 
63
        return result
58
64
    else:
59
65
        log_error('Two plugins defined the same command: %r' % k)
60
66
        log_error('Not loading the one in %r' % sys.modules[cmd.__module__])