~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Aaron Bentley
  • Date: 2008-02-24 16:42:13 UTC
  • mfrom: (3234 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3235.
  • Revision ID: aaron@aaronbentley.com-20080224164213-eza1lzru5bwuwmmj
Merge with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
590
590
 
591
591
    return argdict
592
592
 
 
593
def apply_coveraged(dirname, the_callable, *args, **kwargs):
 
594
    # Cannot use "import trace", as that would import bzrlib.trace instead of
 
595
    # the standard library's trace.
 
596
    trace = __import__('trace')
 
597
 
 
598
    tracer = trace.Trace(count=1, trace=0)
 
599
    sys.settrace(tracer.globaltrace)
 
600
 
 
601
    ret = the_callable(*args, **kwargs)
 
602
 
 
603
    sys.settrace(None)
 
604
    results = tracer.results()
 
605
    results.write_results(show_missing=1, summary=False,
 
606
                          coverdir=dirname)
593
607
 
594
608
 
595
609
def apply_profiled(the_callable, *args, **kwargs):
627
641
    return ret
628
642
 
629
643
 
 
644
def shlex_split_unicode(unsplit):
 
645
    import shlex
 
646
    return [u.decode('utf-8') for u in shlex.split(unsplit.encode('utf-8'))]
 
647
 
 
648
 
630
649
def get_alias(cmd, config=None):
631
650
    """Return an expanded alias, or None if no alias exists.
632
651
 
642
661
        config = bzrlib.config.GlobalConfig()
643
662
    alias = config.get_alias(cmd)
644
663
    if (alias):
645
 
        import shlex
646
 
        return [a.decode('utf-8') for a in shlex.split(alias.encode('utf-8'))]
 
664
        return shlex_split_unicode(alias)
647
665
    return None
648
666
 
649
667
 
678
696
 
679
697
    --lsprof
680
698
        Run under the Python lsprof profiler.
 
699
 
 
700
    --coverage
 
701
        Generate line coverage report in the specified directory.
681
702
    """
682
703
    argv = list(argv)
683
704
    trace.mutter("bzr arguments: %r", argv)
684
705
 
685
706
    opt_lsprof = opt_profile = opt_no_plugins = opt_builtin =  \
686
707
                opt_no_aliases = False
687
 
    opt_lsprof_file = None
 
708
    opt_lsprof_file = opt_coverage_dir = None
688
709
 
689
710
    # --no-plugins is handled specially at a very early stage. We need
690
711
    # to load plugins before doing other command parsing so that they
708
729
            opt_no_aliases = True
709
730
        elif a == '--builtin':
710
731
            opt_builtin = True
 
732
        elif a == '--coverage':
 
733
            opt_coverage_dir = argv[i + 1]
 
734
            i += 1
711
735
        elif a.startswith('-D'):
712
736
            debug.debug_flags.add(a[2:])
713
737
        else:
751
775
 
752
776
    try:
753
777
        if opt_lsprof:
 
778
            if opt_coverage_dir:
 
779
                trace.warning(
 
780
                    '--coverage ignored, because --lsprof is in use.')
754
781
            ret = apply_lsprofiled(opt_lsprof_file, run, *run_argv)
755
782
        elif opt_profile:
 
783
            if opt_coverage_dir:
 
784
                trace.warning(
 
785
                    '--coverage ignored, because --profile is in use.')
756
786
            ret = apply_profiled(run, *run_argv)
 
787
        elif opt_coverage_dir:
 
788
            ret = apply_coveraged(opt_coverage_dir, run, *run_argv)
757
789
        else:
758
790
            ret = run(*run_argv)
759
791
        return ret or 0