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