~jeanfrancois.roy/bzr/url-safe-escape

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

[merge] robertc's integration, updated tests to check for retcode=3

Show diffs side-by-side

added added

removed removed

Lines of Context:
306
306
            a = str(a)
307
307
            optarg = None
308
308
            if a[1] == '-':
309
 
                mutter("  got option %r" % a)
 
309
                mutter("  got option %r", a)
310
310
                if '=' in a:
311
311
                    optname, optarg = a[2:].split('=', 1)
312
312
                else:
346
346
                            # into the array
347
347
                            optarg = a[2:]
348
348
            
 
349
                if optname not in cmd_options:
 
350
                    raise BzrOptionError('unknown short option %r for command'
 
351
                        ' %s' % (shortopt, command.name()))
349
352
            if optname in opts:
350
353
                # XXX: Do we ever want to support this, e.g. for -r?
351
354
                raise BzrError('repeated option %r' % a)
507
510
    return ret or 0
508
511
 
509
512
def display_command(func):
 
513
    """Decorator that suppresses pipe/interrupt errors."""
510
514
    def ignore_pipe(*args, **kwargs):
511
515
        try:
512
 
            return func(*args, **kwargs)
 
516
            result = func(*args, **kwargs)
 
517
            sys.stdout.flush()
 
518
            return result
513
519
        except IOError, e:
 
520
            if not hasattr(e, 'errno'):
 
521
                raise
514
522
            if e.errno != errno.EPIPE:
515
523
                raise
 
524
            pass
516
525
        except KeyboardInterrupt:
517
526
            pass
518
527
    return ignore_pipe
532
541
        finally:
533
542
            # do this here inside the exception wrappers to catch EPIPE
534
543
            sys.stdout.flush()
535
 
    except BzrCommandError, e:
536
 
        # command line syntax error, etc
537
 
        log_error(str(e))
538
 
        return 1
539
 
    except BzrError, e:
540
 
        bzrlib.trace.log_exception()
541
 
        return 1
542
 
    except AssertionError, e:
543
 
        bzrlib.trace.log_exception('assertion failed: ' + str(e))
544
 
        return 3
545
 
    except KeyboardInterrupt, e:
546
 
        bzrlib.trace.log_exception('interrupted')
547
 
        return 2
548
544
    except Exception, e:
 
545
        # used to handle AssertionError and KeyboardInterrupt
 
546
        # specially here, but hopefully they're handled ok by the logger now
549
547
        import errno
550
548
        if (isinstance(e, IOError) 
551
549
            and hasattr(e, 'errno')
552
550
            and e.errno == errno.EPIPE):
553
551
            bzrlib.trace.note('broken pipe')
554
 
            return 2
 
552
            return 3
555
553
        else:
556
 
            ## import pdb
557
 
            ## pdb.pm()
558
554
            bzrlib.trace.log_exception()
559
 
            return 2
 
555
            if os.environ.get('BZR_PDB'):
 
556
                print '**** entering debugger'
 
557
                import pdb
 
558
                pdb.post_mortem(sys.exc_traceback)
 
559
            return 3
560
560
 
561
561
if __name__ == '__main__':
562
562
    sys.exit(main(sys.argv))