/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Aaron Bentley
  • Date: 2006-11-17 04:06:03 UTC
  • mfrom: (2139 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2162.
  • Revision ID: aaron.bentley@utoronto.ca-20061117040603-pgebxndswvwk26tt
Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
28
28
# TODO: "--profile=cum", to change sort order.  Is there any value in leaving
29
29
# the profile output behind so it can be interactively examined?
30
30
 
 
31
import os
 
32
import sys
 
33
 
 
34
from bzrlib.lazy_import import lazy_import
 
35
lazy_import(globals(), """
31
36
import codecs
32
37
import errno
33
 
import os
34
38
from warnings import warn
35
 
import sys
36
39
 
37
40
import bzrlib
38
 
import bzrlib.errors as errors
39
 
from bzrlib.errors import (BzrError,
40
 
                           BzrCommandError,
41
 
                           BzrCheckError,
42
 
                           NotBranchError)
43
 
from bzrlib import option
 
41
from bzrlib import (
 
42
    debug,
 
43
    errors,
 
44
    option,
 
45
    osutils,
 
46
    trace,
 
47
    )
 
48
""")
 
49
 
 
50
from bzrlib.symbol_versioning import (
 
51
    deprecated_function,
 
52
    deprecated_method,
 
53
    zero_eight,
 
54
    zero_eleven,
 
55
    )
 
56
# Compatibility
44
57
from bzrlib.option import Option
45
 
import bzrlib.osutils
46
 
from bzrlib.symbol_versioning import (deprecated_method, zero_eight)
47
 
import bzrlib.trace
48
 
from bzrlib.trace import mutter, note, log_error, warning, be_quiet
 
58
 
49
59
 
50
60
plugin_cmds = {}
51
61
 
66
76
        k_unsquished = k
67
77
    if k_unsquished not in plugin_cmds:
68
78
        plugin_cmds[k_unsquished] = cmd
69
 
        mutter('registered plugin command %s', k_unsquished)
 
79
        trace.mutter('registered plugin command %s', k_unsquished)
70
80
        if decorate and k_unsquished in builtin_command_names():
71
81
            return _builtin_commands()[k_unsquished]
72
82
    elif decorate:
74
84
        plugin_cmds[k_unsquished] = cmd
75
85
        return result
76
86
    else:
77
 
        log_error('Two plugins defined the same command: %r' % k)
78
 
        log_error('Not loading the one in %r' % sys.modules[cmd.__module__])
 
87
        trace.log_error('Two plugins defined the same command: %r' % k)
 
88
        trace.log_error('Not loading the one in %r' % sys.modules[cmd.__module__])
79
89
 
80
90
 
81
91
def _squish_command_name(cmd):
150
160
    if cmd_obj:
151
161
        return cmd_obj
152
162
 
153
 
    raise BzrCommandError('unknown command "%s"' % cmd_name)
 
163
    raise errors.BzrCommandError('unknown command "%s"' % cmd_name)
154
164
 
155
165
 
156
166
class Command(object):
222
232
 
223
233
        Maps from long option name to option object."""
224
234
        r = dict()
225
 
        r['help'] = Option.OPTIONS['help']
 
235
        r['help'] = option.Option.OPTIONS['help']
226
236
        for o in self.takes_options:
227
237
            if isinstance(o, basestring):
228
 
                o = Option.OPTIONS[o]
 
238
                o = option.Option.OPTIONS[o]
229
239
            r[o.name] = o
230
240
        return r
231
241
 
239
249
            self.outf = sys.stdout
240
250
            return
241
251
 
242
 
        output_encoding = bzrlib.osutils.get_terminal_encoding()
 
252
        output_encoding = osutils.get_terminal_encoding()
243
253
 
244
254
        # use 'replace' so that we don't abort if trying to write out
245
255
        # in e.g. the default C locale.
316
326
            return None
317
327
 
318
328
 
 
329
# Technically, this function hasn't been use in a *really* long time
 
330
# but we are only deprecating it now.
 
331
@deprecated_function(zero_eleven)
319
332
def parse_spec(spec):
320
333
    """
321
334
    >>> parse_spec(None)
385
398
                argdict[argname + '_list'] = None
386
399
        elif ap[-1] == '+':
387
400
            if not args:
388
 
                raise BzrCommandError("command %r needs one or more %s"
389
 
                        % (cmd, argname.upper()))
 
401
                raise errors.BzrCommandError("command %r needs one or more %s"
 
402
                                             % (cmd, argname.upper()))
390
403
            else:
391
404
                argdict[argname + '_list'] = args[:]
392
405
                args = []
393
406
        elif ap[-1] == '$': # all but one
394
407
            if len(args) < 2:
395
 
                raise BzrCommandError("command %r needs one or more %s"
396
 
                        % (cmd, argname.upper()))
 
408
                raise errors.BzrCommandError("command %r needs one or more %s"
 
409
                                             % (cmd, argname.upper()))
397
410
            argdict[argname + '_list'] = args[:-1]
398
411
            args[:-1] = []
399
412
        else:
400
413
            # just a plain arg
401
414
            argname = ap
402
415
            if not args:
403
 
                raise BzrCommandError("command %r requires argument %s"
404
 
                        % (cmd, argname.upper()))
 
416
                raise errors.BzrCommandError("command %r requires argument %s"
 
417
                               % (cmd, argname.upper()))
405
418
            else:
406
419
                argdict[argname] = args.pop(0)
407
420
            
408
421
    if args:
409
 
        raise BzrCommandError("extra argument to command %s: %s"
410
 
                              % (cmd, args[0]))
 
422
        raise errors.BzrCommandError("extra argument to command %s: %s"
 
423
                                     % (cmd, args[0]))
411
424
 
412
425
    return argdict
413
426
 
520
533
        elif a == '--builtin':
521
534
            opt_builtin = True
522
535
        elif a in ('--quiet', '-q'):
523
 
            be_quiet()
 
536
            trace.be_quiet()
 
537
        elif a.startswith('-D'):
 
538
            debug.debug_flags.add(a[2:])
524
539
        else:
525
540
            argv_copy.append(a)
526
541
        i += 1
574
589
        return ret or 0
575
590
    finally:
576
591
        # reset, in case we may do other commands later within the same process
577
 
        be_quiet(False)
 
592
        trace.be_quiet(False)
578
593
 
579
594
def display_command(func):
580
595
    """Decorator that suppresses pipe/interrupt errors."""
602
617
    bzrlib.ui.ui_factory = TextUIFactory()
603
618
    argv = [a.decode(bzrlib.user_encoding) for a in argv[1:]]
604
619
    ret = run_bzr_catch_errors(argv)
605
 
    mutter("return code %d", ret)
 
620
    trace.mutter("return code %d", ret)
606
621
    return ret
607
622
 
608
623
 
611
626
        return run_bzr(argv)
612
627
        # do this here inside the exception wrappers to catch EPIPE
613
628
        sys.stdout.flush()
614
 
    except Exception, e:
 
629
    except (KeyboardInterrupt, Exception), e:
615
630
        # used to handle AssertionError and KeyboardInterrupt
616
631
        # specially here, but hopefully they're handled ok by the logger now
617
 
        bzrlib.trace.report_exception(sys.exc_info(), sys.stderr)
 
632
        trace.report_exception(sys.exc_info(), sys.stderr)
618
633
        if os.environ.get('BZR_PDB'):
619
634
            print '**** entering debugger'
620
635
            import pdb