~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Martin Pool
  • Date: 2005-11-11 23:22:03 UTC
  • mto: (1185.33.43 bzr.dev)
  • mto: This revision was merged to the branch mainline in revision 1512.
  • Revision ID: mbp@sourcefrog.net-20051111232203-e1c6e4437f6fe9a7
Don't enable default logging twice

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
import os
32
32
from warnings import warn
33
33
from inspect import getdoc
 
34
import errno
34
35
 
35
36
import bzrlib
36
37
import bzrlib.trace
37
38
from bzrlib.trace import mutter, note, log_error, warning
38
 
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
 
39
from bzrlib.errors import (BzrError, 
 
40
                           BzrCheckError,
 
41
                           BzrCommandError,
 
42
                           BzrOptionError,
 
43
                           NotBranchError)
39
44
from bzrlib.revisionspec import RevisionSpec
40
45
from bzrlib import BZRDIR
41
46
from bzrlib.option import Option
43
48
plugin_cmds = {}
44
49
 
45
50
 
46
 
def register_command(cmd):
 
51
def register_command(cmd, decorate=False):
47
52
    "Utility function to help register a command"
48
53
    global plugin_cmds
49
54
    k = cmd.__name__
54
59
    if not plugin_cmds.has_key(k_unsquished):
55
60
        plugin_cmds[k_unsquished] = cmd
56
61
        mutter('registered plugin command %s', k_unsquished)      
 
62
        if decorate and k_unsquished in builtin_command_names():
 
63
            return _builtin_commands()[k_unsquished]
 
64
    elif decorate:
 
65
        result = plugin_cmds[k_unsquished]
 
66
        plugin_cmds[k_unsquished] = cmd
 
67
        return result
57
68
    else:
58
69
        log_error('Two plugins defined the same command: %r' % k)
59
70
        log_error('Not loading the one in %r' % sys.modules[cmd.__module__])
212
223
        all_cmd_args.update(cmdopts)
213
224
 
214
225
        return self.run(**all_cmd_args)
215
 
 
216
226
    
217
227
    def run(self):
218
228
        """Actually run the command.
302
312
                else:
303
313
                    optname = a[2:]
304
314
                if optname not in cmd_options:
305
 
                    raise BzrCommandError('unknown long option %r for command %s' 
306
 
                            % (a, command.name))
 
315
                    raise BzrOptionError('unknown long option %r for command %s'
 
316
                        % (a, command.name()))
307
317
            else:
308
318
                shortopt = a[1:]
309
319
                if shortopt in Option.SHORT_OPTIONS:
496
506
        ret = cmd_obj.run_argv(argv)
497
507
    return ret or 0
498
508
 
 
509
def display_command(func):
 
510
    def ignore_pipe(*args, **kwargs):
 
511
        try:
 
512
            return func(*args, **kwargs)
 
513
        except IOError, e:
 
514
            if e.errno != errno.EPIPE:
 
515
                raise
 
516
        except KeyboardInterrupt:
 
517
            pass
 
518
    return ignore_pipe
 
519
 
499
520
 
500
521
def main(argv):
501
522
    import bzrlib.ui
 
523
    ## bzrlib.trace.enable_default_logging()
502
524
    bzrlib.trace.log_startup(argv)
503
525
    bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
504
 
 
505
 
    return run_bzr_catch_errors(argv[1:])
 
526
    ret = run_bzr_catch_errors(argv[1:])
 
527
    mutter("return code %d", ret)
 
528
    return ret
506
529
 
507
530
 
508
531
def run_bzr_catch_errors(argv):