~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Robert Collins
  • Date: 2005-12-24 02:20:45 UTC
  • mto: (1185.50.57 bzr-jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1550.
  • Revision ID: robertc@robertcollins.net-20051224022045-14efc8dfa0e1a4e9
Start tests for api usage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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':
514
526
    cmd_obj = get_cmd_object(cmd, plugins_override=not opt_builtin)
515
527
 
516
528
    try:
517
 
        if opt_profile:
 
529
        if opt_lsprof:
 
530
            ret = apply_lsprofiled(cmd_obj.run_argv, argv)
 
531
        elif opt_profile:
518
532
            ret = apply_profiled(cmd_obj.run_argv, argv)
519
533
        else:
520
534
            ret = cmd_obj.run_argv(argv)
543
557
 
544
558
def main(argv):
545
559
    import bzrlib.ui
 
560
    from bzrlib.ui.text import TextUIFactory
546
561
    ## bzrlib.trace.enable_default_logging()
547
562
    bzrlib.trace.log_startup(argv)
548
 
    bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
 
563
    bzrlib.ui.ui_factory = TextUIFactory()
549
564
    ret = run_bzr_catch_errors(argv[1:])
550
565
    mutter("return code %d", ret)
551
566
    return ret