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 cmdpath = os.path.join(exepath, 'cmd')
11 sys.path[:0] = [libpath]
12 os.environ['PYTHONPATH'] = libpath + ':' + os.environ.get('PYTHONPATH', '')
14 from bup.helpers import *
17 log('Usage: bup <subcmd> <options...>\n\n')
18 log('Available subcommands:\n')
19 for c in sorted(os.listdir(cmdpath) + os.listdir(exepath)):
20 if c.startswith('bup-') and c.find('.') < 0:
24 if len(argv) < 2 or not argv[1] or argv[1][0] == '-':
32 sp = os.path.join(exepath, 'bup-%s' % s)
33 if not os.path.exists(sp):
34 sp = os.path.join(cmdpath, 'bup-%s' % s)
37 if not os.path.exists(subpath(subcmd)):
38 log('error: unknown command "%s"\n' % subcmd)
42 already_fixed = atoi(os.environ.get('BUP_FORCE_TTY'))
45 fix_stdout = not already_fixed and os.isatty(1)
46 fix_stderr = not already_fixed and os.isatty(2)
49 if fix_stdout or fix_stderr:
50 os.environ['BUP_FORCE_TTY'] = '1'
52 if fix_stdout or fix_stderr:
53 realf = fix_stderr and 2 or 1
54 n = subprocess.Popen([subpath('newliner')],
55 stdin=subprocess.PIPE, stdout=os.dup(realf),
56 close_fds=True, preexec_fn=force_tty)
57 outf = fix_stdout and n.stdin.fileno() or 1
58 errf = fix_stderr and n.stdin.fileno() or 2
67 p = subprocess.Popen([subpath(subcmd)] + argv[2:],
68 stdout=outf, stderr=errf, preexec_fn=force_tty)
71 log('%s: %s\n' % (subpath(subcmd), e))
73 except KeyboardInterrupt, e: