~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Robert Collins
  • Date: 2005-11-22 21:28:30 UTC
  • mfrom: (1185.33.32 bzr.dev)
  • Revision ID: robertc@robertcollins.net-20051122212830-885c284847f0b17b
Merge from mpool.

Show diffs side-by-side

added added

removed removed

Lines of Context:
168
168
        List of argument forms, marked with whether they are optional,
169
169
        repeated, etc.
170
170
 
 
171
                Examples:
 
172
 
 
173
                ['to_location', 'from_branch?', 'file*']
 
174
 
 
175
                'to_location' is required
 
176
                'from_branch' is optional
 
177
                'file' can be specified 0 or more times
 
178
 
171
179
    takes_options
172
180
        List of options that may be given for this command.  These can
173
181
        be either strings, referring to globally-defined options,
346
354
                            # into the array
347
355
                            optarg = a[2:]
348
356
            
 
357
                if optname not in cmd_options:
 
358
                    raise BzrOptionError('unknown short option %r for command'
 
359
                        ' %s' % (shortopt, command.name()))
349
360
            if optname in opts:
350
361
                # XXX: Do we ever want to support this, e.g. for -r?
351
362
                raise BzrError('repeated option %r' % a)
507
518
    return ret or 0
508
519
 
509
520
def display_command(func):
 
521
    """Decorator that suppresses pipe/interrupt errors."""
510
522
    def ignore_pipe(*args, **kwargs):
511
523
        try:
512
 
            return func(*args, **kwargs)
 
524
            result = func(*args, **kwargs)
 
525
            sys.stdout.flush()
 
526
            return result
513
527
        except IOError, e:
 
528
            if not hasattr(e, 'errno'):
 
529
                raise
514
530
            if e.errno != errno.EPIPE:
515
531
                raise
 
532
            pass
516
533
        except KeyboardInterrupt:
517
534
            pass
518
535
    return ignore_pipe
532
549
        finally:
533
550
            # do this here inside the exception wrappers to catch EPIPE
534
551
            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
552
    except Exception, e:
 
553
        # used to handle AssertionError and KeyboardInterrupt
 
554
        # specially here, but hopefully they're handled ok by the logger now
549
555
        import errno
550
556
        if (isinstance(e, IOError) 
551
557
            and hasattr(e, 'errno')
552
558
            and e.errno == errno.EPIPE):
553
559
            bzrlib.trace.note('broken pipe')
554
 
            return 2
 
560
            return 3
555
561
        else:
556
 
            ## import pdb
557
 
            ## pdb.pm()
558
562
            bzrlib.trace.log_exception()
559
 
            return 2
 
563
            if os.environ.get('BZR_PDB'):
 
564
                print '**** entering debugger'
 
565
                import pdb
 
566
                pdb.post_mortem(sys.exc_traceback)
 
567
            return 3
560
568
 
561
569
if __name__ == '__main__':
562
570
    sys.exit(main(sys.argv))