~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

Harald Meland's xml escaping on commit patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
# Those objects can specify the expected type of the argument, which
25
25
# would help with validation and shell completion.
26
26
 
27
 
# TODO: "--profile=cum", to change sort order.  Is there any value in leaving
28
 
# the profile output behind so it can be interactively examined?
 
27
 
 
28
# TODO: Help messages for options.
 
29
 
 
30
# TODO: Define arguments by objects, rather than just using names.
 
31
# Those objects can specify the expected type of the argument, which
 
32
# would help with validation and shell completion.
 
33
 
 
34
 
29
35
 
30
36
import sys
31
37
import os
135
141
    return revs
136
142
 
137
143
 
 
144
def get_merge_type(typestring):
 
145
    """Attempt to find the merge class/factory associated with a string."""
 
146
    from merge import merge_types
 
147
    try:
 
148
        return merge_types[typestring][0]
 
149
    except KeyError:
 
150
        templ = '%s%%7s: %%s' % (' '*12)
 
151
        lines = [templ % (f[0], f[1][1]) for f in merge_types.iteritems()]
 
152
        type_list = '\n'.join(lines)
 
153
        msg = "No known merge type %s. Supported types are:\n%s" %\
 
154
            (typestring, type_list)
 
155
        raise BzrCommandError(msg)
 
156
 
 
157
 
138
158
def _builtin_commands():
139
159
    import bzrlib.builtins
140
160
    r = {}
332
352
# the type.
333
353
OPTIONS = {
334
354
    'all':                    None,
335
 
    'basis':                  str,
336
355
    'diff-options':           str,
337
356
    'help':                   None,
338
357
    'file':                   unicode,
354
373
    'long':                   None,
355
374
    'root':                   str,
356
375
    'no-backup':              None,
 
376
    'merge-type':             get_merge_type,
357
377
    'pattern':                str,
358
 
    'remember':               None,
359
378
    }
360
379
 
361
380
SHORT_OPTIONS = {
520
539
def apply_profiled(the_callable, *args, **kwargs):
521
540
    import hotshot
522
541
    import tempfile
523
 
    import hotshot.stats
524
542
    pffileno, pfname = tempfile.mkstemp()
525
543
    try:
526
544
        prof = hotshot.Profile(pfname)
528
546
            ret = prof.runcall(the_callable, *args, **kwargs) or 0
529
547
        finally:
530
548
            prof.close()
 
549
 
 
550
        import hotshot.stats
531
551
        stats = hotshot.stats.load(pfname)
532
 
        stats.strip_dirs()
533
 
        stats.sort_stats('cum')   # 'time'
 
552
        #stats.strip_dirs()
 
553
        stats.sort_stats('time')
534
554
        ## XXX: Might like to write to stderr or the trace file instead but
535
555
        ## print_stats seems hardcoded to stdout
536
556
        stats.print_stats(20)
 
557
 
537
558
        return ret
538
559
    finally:
539
560
        os.close(pffileno)
564
585
    --profile
565
586
        Run under the Python profiler.
566
587
    """
567
 
    # Load all of the transport methods
568
 
    import bzrlib.transport.local, bzrlib.transport.http
569
588
    
570
589
    argv = [a.decode(bzrlib.user_encoding) for a in argv]
571
590
 
619
638
    bzrlib.trace.log_startup(argv)
620
639
    bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
621
640
 
622
 
    return run_bzr_catch_errors(argv[1:])
623
 
 
624
 
 
625
 
def run_bzr_catch_errors(argv):
626
641
    try:
627
642
        try:
628
 
            return run_bzr(argv)
629
 
        finally:
630
 
            # do this here inside the exception wrappers to catch EPIPE
631
 
            sys.stdout.flush()
 
643
            try:
 
644
                return run_bzr(argv[1:])
 
645
            finally:
 
646
                # do this here inside the exception wrappers to catch EPIPE
 
647
                sys.stdout.flush()
 
648
        #wrap common errors as CommandErrors.
 
649
        except (NotBranchError,), e:
 
650
            raise BzrCommandError(str(e))
632
651
    except BzrCommandError, e:
633
652
        # command line syntax error, etc
634
653
        log_error(str(e))
640
659
        bzrlib.trace.log_exception('assertion failed: ' + str(e))
641
660
        return 3
642
661
    except KeyboardInterrupt, e:
643
 
        bzrlib.trace.log_exception('interrupted')
 
662
        bzrlib.trace.note('interrupted')
644
663
        return 2
645
664
    except Exception, e:
646
665
        import errno
650
669
            bzrlib.trace.note('broken pipe')
651
670
            return 2
652
671
        else:
653
 
            ## import pdb
654
 
            ## pdb.pm()
655
672
            bzrlib.trace.log_exception()
656
673
            return 2
657
674
 
 
675
 
658
676
if __name__ == '__main__':
659
677
    sys.exit(main(sys.argv))