/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

Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
        k_unsquished = k
77
77
    if k_unsquished not in plugin_cmds:
78
78
        plugin_cmds[k_unsquished] = cmd
79
 
        trace.mutter('registered plugin command %s', k_unsquished)
 
79
        ## trace.mutter('registered plugin command %s', k_unsquished)
80
80
        if decorate and k_unsquished in builtin_command_names():
81
81
            return _builtin_commands()[k_unsquished]
82
82
    elif decorate:
214
214
            replace - put in a bogus character (typically '?')
215
215
            exact - do not encode sys.stdout
216
216
 
 
217
            NOTE: by default on Windows, sys.stdout is opened as a text
 
218
            stream, therefore LF line-endings are converted to CRLF.
 
219
            When a command uses encoding_type = 'exact', then
 
220
            sys.stdout is forced to be a binary stream, and line-endings
 
221
            will not mangled.
 
222
 
217
223
    """
218
224
    aliases = []
219
225
    takes_args = []
246
252
        # Originally I was using self.stdout, but that looks
247
253
        # *way* too much like sys.stdout
248
254
        if self.encoding_type == 'exact':
 
255
            # force sys.stdout to be binary stream on win32
 
256
            if sys.platform == 'win32':
 
257
                fileno = getattr(sys.stdout, 'fileno', None)
 
258
                if fileno:
 
259
                    import msvcrt
 
260
                    msvcrt.setmode(fileno(), os.O_BINARY)
249
261
            self.outf = sys.stdout
250
262
            return
251
263
 
270
282
    def run_argv_aliases(self, argv, alias_argv=None):
271
283
        """Parse the command line and run with extra aliases in alias_argv."""
272
284
        if argv is None:
273
 
            warn("Passing None for [] is deprecated from bzrlib 0.10", 
 
285
            warn("Passing None for [] is deprecated from bzrlib 0.10",
274
286
                 DeprecationWarning, stacklevel=2)
275
287
            argv = []
276
288
        args, opts = parse_args(self, argv, alias_argv)
301
313
        shell error code if not.  It's OK for this method to allow
302
314
        an exception to raise up.
303
315
        """
304
 
        raise NotImplementedError('no implementation of command %r' 
 
316
        raise NotImplementedError('no implementation of command %r'
305
317
                                  % self.name())
306
318
 
307
319
    def help(self):
376
388
        args = argv
377
389
 
378
390
    options, args = parser.parse_args(args)
379
 
    opts = dict([(k, v) for k, v in options.__dict__.iteritems() if 
 
391
    opts = dict([(k, v) for k, v in options.__dict__.iteritems() if
380
392
                 v is not option.OptionParser.DEFAULT_VALUE])
381
393
    return args, opts
382
394
 
463
475
    return ret
464
476
 
465
477
 
466
 
def get_alias(cmd):
467
 
    """Return an expanded alias, or None if no alias exists"""
468
 
    import bzrlib.config
469
 
    alias = bzrlib.config.GlobalConfig().get_alias(cmd)
 
478
def get_alias(cmd, config=None):
 
479
    """Return an expanded alias, or None if no alias exists.
 
480
 
 
481
    cmd
 
482
        Command to be checked for an alias.
 
483
    config
 
484
        Used to specify an alternative config to use,
 
485
        which is especially useful for testing.
 
486
        If it is unspecified, the global config will be used.
 
487
    """
 
488
    if config is None:
 
489
        import bzrlib.config
 
490
        config = bzrlib.config.GlobalConfig()
 
491
    alias = config.get_alias(cmd)
470
492
    if (alias):
471
 
        return alias.split(' ')
 
493
        import shlex
 
494
        return [a.decode('utf-8') for a in shlex.split(alias.encode('utf-8'))]
472
495
    return None
473
496
 
474
497
 
505
528
        Run under the Python lsprof profiler.
506
529
    """
507
530
    argv = list(argv)
 
531
    trace.mutter("bzr arguments: %r", argv)
508
532
 
509
533
    opt_lsprof = opt_profile = opt_no_plugins = opt_builtin =  \
510
534
                opt_no_aliases = False