3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
8 from __future__ import absolute_import
9 import sys, os, struct, getopt, subprocess, signal
11 from subprocess import PIPE
12 from bup import options, ssh, path
13 from bup.helpers import DemuxConn, log
17 bup on <hostname> index ...
18 bup on <hostname> save ...
19 bup on <hostname> split ...
20 bup on <hostname> get ...
22 o = options.Options(optspec, optfunc=getopt.getopt)
23 (opt, flags, extra) = o.parse(sys.argv[1:])
25 o.fatal('arguments expected')
27 class SigException(Exception):
28 def __init__(self, signum):
30 Exception.__init__(self, 'signal %d received' % signum)
31 def handler(signum, frame):
32 raise SigException(signum)
34 signal.signal(signal.SIGTERM, handler)
35 signal.signal(signal.SIGINT, handler)
42 hp = extra[0].split(':')
44 (hostname, port) = (hp[0], None)
48 p = ssh.connect(hostname, port, 'on--server', stderr=PIPE)
51 argvs = '\0'.join(['bup'] + argv)
52 p.stdin.write(struct.pack('!I', len(argvs)) + argvs)
54 sp = subprocess.Popen([path.exe(), 'server'],
55 stdin=p.stdout, stdout=p.stdin)
58 # Demultiplex remote client's stderr (back to stdout/stderr).
59 dmc = DemuxConn(p.stderr.fileno(), open(os.devnull, "w"))
60 for line in iter(dmc.readline, ""):
61 sys.stdout.write(line)
64 # if we get a signal while waiting, we have to keep waiting, just
65 # in case our child doesn't die.
71 except SigException as e:
72 log('\nbup on: %s\n' % e)
73 os.kill(p.pid, e.signum)
75 except SigException as e:
78 log('\nbup on: %s\n' % e)