3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
7 import sys, os, struct, getopt, subprocess, signal
8 from subprocess import PIPE
9 from bup import options, ssh, path
10 from bup.helpers import *
13 bup on <hostname> index ...
14 bup on <hostname> save ...
15 bup on <hostname> split ...
17 o = options.Options(optspec, optfunc=getopt.getopt)
18 (opt, flags, extra) = o.parse(sys.argv[1:])
20 o.fatal('arguments expected')
22 class SigException(Exception):
23 def __init__(self, signum):
25 Exception.__init__(self, 'signal %d received' % signum)
26 def handler(signum, frame):
27 raise SigException(signum)
29 signal.signal(signal.SIGTERM, handler)
30 signal.signal(signal.SIGINT, handler)
37 hp = extra[0].split(':')
39 (hostname, port) = (hp[0], None)
43 p = ssh.connect(hostname, port, 'on--server', stderr=PIPE)
46 argvs = '\0'.join(['bup'] + argv)
47 p.stdin.write(struct.pack('!I', len(argvs)) + argvs)
49 sp = subprocess.Popen([path.exe(), 'server'],
50 stdin=p.stdout, stdout=p.stdin)
53 # Demultiplex remote client's stderr (back to stdout/stderr).
54 dmc = DemuxConn(p.stderr.fileno(), open(os.devnull, "w"))
55 for line in iter(dmc.readline, ""):
56 sys.stdout.write(line)
59 # if we get a signal while waiting, we have to keep waiting, just
60 # in case our child doesn't die.
66 except SigException as e:
67 log('\nbup on: %s\n' % e)
68 os.kill(p.pid, e.signum)
70 except SigException as e:
73 log('\nbup on: %s\n' % e)