32
32
from warnings import warn
33
33
from inspect import getdoc
37
36
import bzrlib.trace
38
from bzrlib.trace import mutter, note, log_error, warning, be_quiet
39
from bzrlib.errors import (BzrError,
37
from bzrlib.trace import mutter, note, log_error, warning
38
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
44
39
from bzrlib.revisionspec import RevisionSpec
45
40
from bzrlib import BZRDIR
46
41
from bzrlib.option import Option
59
54
if not plugin_cmds.has_key(k_unsquished):
60
55
plugin_cmds[k_unsquished] = cmd
61
56
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
69
58
log_error('Two plugins defined the same command: %r' % k)
70
59
log_error('Not loading the one in %r' % sys.modules[cmd.__module__])
168
157
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
180
161
List of options that may be given for this command. These can
181
162
be either strings, referring to globally-defined options,
317
mutter(" got option %r", a)
299
mutter(" got option %r" % a)
319
301
optname, optarg = a[2:].split('=', 1)
322
304
if optname not in cmd_options:
323
raise BzrOptionError('unknown long option %r for command %s'
324
% (a, command.name()))
305
raise BzrCommandError('unknown long option %r for command %s'
327
309
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()))
360
339
if optname in opts:
361
340
# XXX: Do we ever want to support this, e.g. for -r?
362
341
raise BzrError('repeated option %r' % a)
514
491
cmd_obj = get_cmd_object(cmd, plugins_override=not opt_builtin)
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:
494
ret = apply_profiled(cmd_obj.run_argv, argv)
496
ret = cmd_obj.run_argv(argv)
546
from bzrlib.ui.text import TextUIFactory
547
## bzrlib.trace.enable_default_logging()
548
502
bzrlib.trace.log_startup(argv)
549
bzrlib.ui.ui_factory = TextUIFactory()
550
ret = run_bzr_catch_errors(argv[1:])
551
mutter("return code %d", ret)
503
bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
505
return run_bzr_catch_errors(argv[1:])
555
508
def run_bzr_catch_errors(argv):
560
513
# do this here inside the exception wrappers to catch EPIPE
561
514
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')
562
528
except Exception, e:
563
# used to handle AssertionError and KeyboardInterrupt
564
# specially here, but hopefully they're handled ok by the logger now
566
530
if (isinstance(e, IOError)
567
531
and hasattr(e, 'errno')
568
532
and e.errno == errno.EPIPE):
569
533
bzrlib.trace.note('broken pipe')
572
538
bzrlib.trace.log_exception()
573
if os.environ.get('BZR_PDB'):
574
print '**** entering debugger'
576
pdb.post_mortem(sys.exc_traceback)
579
541
if __name__ == '__main__':
580
542
sys.exit(main(sys.argv))