~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

Merge from integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
import bzrlib
37
37
import bzrlib.trace
38
 
from bzrlib.trace import mutter, note, log_error, warning
 
38
from bzrlib.trace import mutter, note, log_error, warning, be_quiet
39
39
from bzrlib.errors import (BzrError, 
40
40
                           BzrCheckError,
41
41
                           BzrCommandError,
447
447
        os.remove(pfname)
448
448
 
449
449
 
 
450
def apply_lsprofiled(the_callable, *args, **kwargs):
 
451
    from bzrlib.lsprof import profile
 
452
    ret,stats = profile(the_callable,*args,**kwargs)
 
453
    stats.sort()
 
454
    stats.pprint()
 
455
    return ret
 
456
 
450
457
def run_bzr(argv):
451
458
    """Execute a command.
452
459
 
469
476
        other behaviour.)
470
477
 
471
478
    --profile
472
 
        Run under the Python profiler.
 
479
        Run under the Python hotshot profiler.
 
480
 
 
481
    --lsprof
 
482
        Run under the Python lsprof profiler.
473
483
    """
474
484
    argv = [a.decode(bzrlib.user_encoding) for a in argv]
475
485
 
476
 
    opt_profile = opt_no_plugins = opt_builtin = False
 
486
    opt_lsprof = opt_profile = opt_no_plugins = opt_builtin = False
477
487
 
478
488
    # --no-plugins is handled specially at a very early stage. We need
479
489
    # to load plugins before doing other command parsing so that they
482
492
    for a in argv:
483
493
        if a == '--profile':
484
494
            opt_profile = True
 
495
        elif a == '--lsprof':
 
496
            opt_lsprof = True
485
497
        elif a == '--no-plugins':
486
498
            opt_no_plugins = True
487
499
        elif a == '--builtin':
488
500
            opt_builtin = True
 
501
        elif a in ('--quiet', '-q'):
 
502
            be_quiet()
489
503
        else:
490
 
            break
 
504
            continue
491
505
        argv.remove(a)
492
506
 
493
507
    if (not argv) or (argv[0] == '--help'):
511
525
 
512
526
    cmd_obj = get_cmd_object(cmd, plugins_override=not opt_builtin)
513
527
 
514
 
    if opt_profile:
515
 
        ret = apply_profiled(cmd_obj.run_argv, argv)
516
 
    else:
517
 
        ret = cmd_obj.run_argv(argv)
518
 
    return ret or 0
 
528
    try:
 
529
        if opt_lsprof:
 
530
            ret = apply_lsprofiled(cmd_obj.run_argv, argv)
 
531
        elif opt_profile:
 
532
            ret = apply_profiled(cmd_obj.run_argv, argv)
 
533
        else:
 
534
            ret = cmd_obj.run_argv(argv)
 
535
        return ret or 0
 
536
    finally:
 
537
        # reset, in case we may do other commands later within the same process
 
538
        be_quiet(False)
519
539
 
520
540
def display_command(func):
521
541
    """Decorator that suppresses pipe/interrupt errors."""
534
554
            pass
535
555
    return ignore_pipe
536
556
 
 
557
 
537
558
def main(argv):
538
559
    import bzrlib.ui
 
560
    from bzrlib.ui.text import TextUIFactory
 
561
    ## bzrlib.trace.enable_default_logging()
539
562
    bzrlib.trace.log_startup(argv)
540
 
    bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
541
 
 
542
 
    return run_bzr_catch_errors(argv[1:])
 
563
    bzrlib.ui.ui_factory = TextUIFactory()
 
564
    ret = run_bzr_catch_errors(argv[1:])
 
565
    mutter("return code %d", ret)
 
566
    return ret
543
567
 
544
568
 
545
569
def run_bzr_catch_errors(argv):