2 import sys, os, subprocess
6 exepath = os.path.split(exe)[0] or '.'
8 # fix the PYTHONPATH to include our lib dir
9 libpath = os.path.join(exepath, 'lib')
10 sys.path[:0] = [libpath]
11 os.environ['PYTHONPATH'] = libpath + ':' + os.environ.get('PYTHONPATH', '')
13 from bup.helpers import *
16 log('Usage: bup <subcmd> <options...>\n\n')
17 log('Available subcommands:\n')
18 for c in sorted(os.listdir(exepath)):
19 if c.startswith('bup-') and c.find('.') < 0:
23 if len(argv) < 2 or not argv[1] or argv[1][0] == '-':
31 return os.path.join(exepath, 'bup-%s' % s)
33 if not os.path.exists(subpath(subcmd)):
34 log('error: unknown command "%s"\n' % subcmd)
38 already_fixed = atoi(os.environ.get('BUP_FORCE_TTY'))
41 fix_stdout = not already_fixed and os.isatty(1)
42 fix_stderr = not already_fixed and os.isatty(2)
45 if fix_stdout or fix_stderr:
46 os.environ['BUP_FORCE_TTY'] = '1'
48 if fix_stdout or fix_stderr:
49 realf = fix_stderr and 2 or 1
50 n = subprocess.Popen([subpath('newliner')],
51 stdin=subprocess.PIPE, stdout=os.dup(realf),
52 close_fds=True, preexec_fn=force_tty)
53 outf = fix_stdout and n.stdin.fileno() or 1
54 errf = fix_stderr and n.stdin.fileno() or 2
63 p = subprocess.Popen([subpath(subcmd)] + argv[2:],
64 stdout=outf, stderr=errf, preexec_fn=force_tty)
67 log('%s: %s\n' % (subpath(subcmd), e))
69 except KeyboardInterrupt, e: