/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: John Arbash Meinel
  • Date: 2006-09-12 20:02:29 UTC
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20060912200229-4a1c12aead0f0b30
Demandloading builtins.py drops our load time from 350ms to 291ms

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
    errors,
 
43
    option,
 
44
    osutils,
 
45
    trace,
 
46
    )
 
47
""")
 
48
 
 
49
from bzrlib.symbol_versioning import (deprecated_method, zero_eight)
 
50
# Compatibility
44
51
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
 
52
 
49
53
 
50
54
plugin_cmds = {}
51
55
 
66
70
        k_unsquished = k
67
71
    if k_unsquished not in plugin_cmds:
68
72
        plugin_cmds[k_unsquished] = cmd
69
 
        mutter('registered plugin command %s', k_unsquished)
 
73
        trace.mutter('registered plugin command %s', k_unsquished)
70
74
        if decorate and k_unsquished in builtin_command_names():
71
75
            return _builtin_commands()[k_unsquished]
72
76
    elif decorate:
74
78
        plugin_cmds[k_unsquished] = cmd
75
79
        return result
76
80
    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__])
 
81
        trace.log_error('Two plugins defined the same command: %r' % k)
 
82
        trace.log_error('Not loading the one in %r' % sys.modules[cmd.__module__])
79
83
 
80
84
 
81
85
def _squish_command_name(cmd):
150
154
    if cmd_obj:
151
155
        return cmd_obj
152
156
 
153
 
    raise BzrCommandError('unknown command "%s"' % cmd_name)
 
157
    raise errors.BzrCommandError('unknown command "%s"' % cmd_name)
154
158
 
155
159
 
156
160
class Command(object):
222
226
 
223
227
        Maps from long option name to option object."""
224
228
        r = dict()
225
 
        r['help'] = Option.OPTIONS['help']
 
229
        r['help'] = option.Option.OPTIONS['help']
226
230
        for o in self.takes_options:
227
231
            if isinstance(o, basestring):
228
 
                o = Option.OPTIONS[o]
 
232
                o = option.Option.OPTIONS[o]
229
233
            r[o.name] = o
230
234
        return r
231
235
 
239
243
            self.outf = sys.stdout
240
244
            return
241
245
 
242
 
        output_encoding = bzrlib.osutils.get_terminal_encoding()
 
246
        output_encoding = osutils.get_terminal_encoding()
243
247
 
244
248
        # use 'replace' so that we don't abort if trying to write out
245
249
        # in e.g. the default C locale.
385
389
                argdict[argname + '_list'] = None
386
390
        elif ap[-1] == '+':
387
391
            if not args:
388
 
                raise BzrCommandError("command %r needs one or more %s"
389
 
                        % (cmd, argname.upper()))
 
392
                raise errors.BzrCommandError("command %r needs one or more %s"
 
393
                                             % (cmd, argname.upper()))
390
394
            else:
391
395
                argdict[argname + '_list'] = args[:]
392
396
                args = []
393
397
        elif ap[-1] == '$': # all but one
394
398
            if len(args) < 2:
395
 
                raise BzrCommandError("command %r needs one or more %s"
396
 
                        % (cmd, argname.upper()))
 
399
                raise errors.BzrCommandError("command %r needs one or more %s"
 
400
                                             % (cmd, argname.upper()))
397
401
            argdict[argname + '_list'] = args[:-1]
398
402
            args[:-1] = []
399
403
        else:
400
404
            # just a plain arg
401
405
            argname = ap
402
406
            if not args:
403
 
                raise BzrCommandError("command %r requires argument %s"
404
 
                        % (cmd, argname.upper()))
 
407
                raise errors.BzrCommandError("command %r requires argument %s"
 
408
                               % (cmd, argname.upper()))
405
409
            else:
406
410
                argdict[argname] = args.pop(0)
407
411
            
408
412
    if args:
409
 
        raise BzrCommandError("extra argument to command %s: %s"
410
 
                              % (cmd, args[0]))
 
413
        raise errors.BzrCommandError("extra argument to command %s: %s"
 
414
                                     % (cmd, args[0]))
411
415
 
412
416
    return argdict
413
417
 
520
524
        elif a == '--builtin':
521
525
            opt_builtin = True
522
526
        elif a in ('--quiet', '-q'):
523
 
            be_quiet()
 
527
            trace.be_quiet()
524
528
        else:
525
529
            argv_copy.append(a)
526
530
        i += 1
574
578
        return ret or 0
575
579
    finally:
576
580
        # reset, in case we may do other commands later within the same process
577
 
        be_quiet(False)
 
581
        trace.be_quiet(False)
578
582
 
579
583
def display_command(func):
580
584
    """Decorator that suppresses pipe/interrupt errors."""
602
606
    bzrlib.ui.ui_factory = TextUIFactory()
603
607
    argv = [a.decode(bzrlib.user_encoding) for a in argv[1:]]
604
608
    ret = run_bzr_catch_errors(argv)
605
 
    mutter("return code %d", ret)
 
609
    trace.mutter("return code %d", ret)
606
610
    return ret
607
611
 
608
612
 
614
618
    except Exception, e:
615
619
        # used to handle AssertionError and KeyboardInterrupt
616
620
        # specially here, but hopefully they're handled ok by the logger now
617
 
        bzrlib.trace.report_exception(sys.exc_info(), sys.stderr)
 
621
        trace.report_exception(sys.exc_info(), sys.stderr)
618
622
        if os.environ.get('BZR_PDB'):
619
623
            print '**** entering debugger'
620
624
            import pdb