32
32
from warnings import warn
33
33
from inspect import getdoc
36
37
import bzrlib.trace
37
from bzrlib.trace import mutter, note, log_error, warning
38
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
38
from bzrlib.trace import mutter, note, log_error, warning, be_quiet
39
from bzrlib.errors import (BzrError,
39
44
from bzrlib.revisionspec import RevisionSpec
40
45
from bzrlib import BZRDIR
41
46
from bzrlib.option import Option
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]
65
result = plugin_cmds[k_unsquished]
66
plugin_cmds[k_unsquished] = cmd
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__])
157
168
List of argument forms, marked with whether they are optional,
173
['to_location', 'from_branch?', 'file*']
175
'to_location' is required
176
'from_branch' is optional
177
'file' can be specified 0 or more times
161
180
List of options that may be given for this command. These can
162
181
be either strings, referring to globally-defined options,
299
mutter(" got option %r" % a)
317
mutter(" got option %r", a)
301
319
optname, optarg = a[2:].split('=', 1)
304
322
if optname not in cmd_options:
305
raise BzrCommandError('unknown long option %r for command %s'
323
raise BzrOptionError('unknown long option %r for command %s'
324
% (a, command.name()))
309
327
if shortopt in Option.SHORT_OPTIONS:
357
if optname not in cmd_options:
358
raise BzrOptionError('unknown short option %r for command'
359
' %s' % (shortopt, command.name()))
339
360
if optname in opts:
340
361
# XXX: Do we ever want to support this, e.g. for -r?
341
362
raise BzrError('repeated option %r' % a)
491
514
cmd_obj = get_cmd_object(cmd, plugins_override=not opt_builtin)
494
ret = apply_profiled(cmd_obj.run_argv, argv)
496
ret = cmd_obj.run_argv(argv)
518
ret = apply_profiled(cmd_obj.run_argv, argv)
520
ret = cmd_obj.run_argv(argv)
523
# reset, in case we may do other commands later within the same process
526
def display_command(func):
527
"""Decorator that suppresses pipe/interrupt errors."""
528
def ignore_pipe(*args, **kwargs):
530
result = func(*args, **kwargs)
534
if not hasattr(e, 'errno'):
536
if e.errno != errno.EPIPE:
539
except KeyboardInterrupt:
546
from bzrlib.ui.text import TextUIFactory
547
## bzrlib.trace.enable_default_logging()
502
548
bzrlib.trace.log_startup(argv)
503
bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
505
return run_bzr_catch_errors(argv[1:])
549
bzrlib.ui.ui_factory = TextUIFactory()
550
ret = run_bzr_catch_errors(argv[1:])
551
mutter("return code %d", ret)
508
555
def run_bzr_catch_errors(argv):
513
560
# do this here inside the exception wrappers to catch EPIPE
514
561
sys.stdout.flush()
515
except BzrCommandError, e:
516
# command line syntax error, etc
520
bzrlib.trace.log_exception()
522
except AssertionError, e:
523
bzrlib.trace.log_exception('assertion failed: ' + str(e))
525
except KeyboardInterrupt, e:
526
bzrlib.trace.log_exception('interrupted')
528
562
except Exception, e:
563
# used to handle AssertionError and KeyboardInterrupt
564
# specially here, but hopefully they're handled ok by the logger now
530
566
if (isinstance(e, IOError)
531
567
and hasattr(e, 'errno')
532
568
and e.errno == errno.EPIPE):
533
569
bzrlib.trace.note('broken pipe')
538
572
bzrlib.trace.log_exception()
573
if os.environ.get('BZR_PDB'):
574
print '**** entering debugger'
576
pdb.post_mortem(sys.exc_traceback)
541
579
if __name__ == '__main__':
542
580
sys.exit(main(sys.argv))