~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Robert Collins
  • Date: 2005-08-24 06:53:07 UTC
  • mto: (974.1.50) (1185.1.10) (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: robertc@robertcollins.net-20050824065307-bca8ae89734a53f8
merge from mpool

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
# TODO: probably should say which arguments are candidates for glob
21
21
# expansion on windows and do that at the command level.
22
22
 
 
23
# TODO: Help messages for options.
 
24
 
 
25
# TODO: Define arguments by objects, rather than just using names.
 
26
# Those objects can specify the expected type of the argument, which
 
27
# would help with validation and shell completion.
 
28
 
 
29
 
23
30
import sys
24
31
import os
25
32
 
1603
1610
        return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1604
1611
 
1605
1612
 
 
1613
 
1606
1614
class cmd_plugins(Command):
1607
1615
    """List plugins"""
1608
1616
    hidden = True
1866
1874
        return 0
1867
1875
    
1868
1876
    if not args:
1869
 
        print >>sys.stderr, "please try 'bzr help' for help"
1870
 
        return 1
 
1877
        from bzrlib.help import help
 
1878
        help(None)
 
1879
        return 0
1871
1880
    
1872
1881
    cmd = str(args.pop(0))
1873
1882
 
1916
1925
    import traceback
1917
1926
    
1918
1927
    log_error('bzr: ' + summary)
1919
 
    bzrlib.trace.log_exception()
1920
 
 
1921
 
    if os.environ.get('BZR_DEBUG'):
1922
 
        traceback.print_exc()
1923
1928
 
1924
1929
    if not quiet:
1925
1930
        sys.stderr.write('\n')
1932
1937
 
1933
1938
 
1934
1939
def main(argv):
1935
 
    
1936
1940
    bzrlib.trace.open_tracefile(argv)
1937
1941
 
1938
1942
    try:
1939
1943
        try:
1940
 
            try:
1941
 
                return run_bzr(argv[1:])
1942
 
            finally:
1943
 
                # do this here inside the exception wrappers to catch EPIPE
1944
 
                sys.stdout.flush()
1945
 
        except BzrError, e:
1946
 
            quiet = isinstance(e, (BzrCommandError))
1947
 
            _report_exception('error: ' + str(e), quiet=quiet)
1948
 
            if len(e.args) > 1:
1949
 
                for h in e.args[1]:
1950
 
                    # some explanation or hints
1951
 
                    log_error('  ' + h)
1952
 
            return 1
1953
 
        except AssertionError, e:
1954
 
            msg = 'assertion failed'
1955
 
            if str(e):
1956
 
                msg += ': ' + str(e)
1957
 
            _report_exception(msg)
1958
 
            return 2
1959
 
        except KeyboardInterrupt, e:
1960
 
            _report_exception('interrupted', quiet=True)
1961
 
            return 2
1962
 
        except Exception, e:
1963
 
            import errno
1964
 
            quiet = False
1965
 
            if (isinstance(e, IOError) 
1966
 
                and hasattr(e, 'errno')
1967
 
                and e.errno == errno.EPIPE):
1968
 
                quiet = True
1969
 
                msg = 'broken pipe'
1970
 
            else:
1971
 
                msg = str(e).rstrip('\n')
1972
 
            _report_exception(msg, quiet)
1973
 
            return 2
1974
 
    finally:
1975
 
        bzrlib.trace.close_trace()
 
1944
            return run_bzr(argv[1:])
 
1945
        finally:
 
1946
            # do this here inside the exception wrappers to catch EPIPE
 
1947
            sys.stdout.flush()
 
1948
    except BzrCommandError, e:
 
1949
        # command line syntax error, etc
 
1950
        log_error(str(e))
 
1951
        return 1
 
1952
    except BzrError, e:
 
1953
        bzrlib.trace.log_exception()
 
1954
        return 1
 
1955
    except AssertionError, e:
 
1956
        bzrlib.trace.log_exception('assertion failed: ' + str(e))
 
1957
        return 3
 
1958
    except KeyboardInterrupt, e:
 
1959
        bzrlib.trace.note('interrupted')
 
1960
        return 2
 
1961
    except Exception, e:
 
1962
        import errno
 
1963
        if (isinstance(e, IOError) 
 
1964
            and hasattr(e, 'errno')
 
1965
            and e.errno == errno.EPIPE):
 
1966
            bzrlib.trace.note('broken pipe')
 
1967
            return 2
 
1968
        else:
 
1969
            bzrlib.trace.log_exception('terminated by exception')
 
1970
            return 2
1976
1971
 
1977
1972
 
1978
1973
if __name__ == '__main__':