2 import sys, os, struct, getopt, subprocess, signal
3 from bup import options, ssh
4 from bup.helpers import *
7 bup on <hostname> index ...
8 bup on <hostname> save ...
9 bup on <hostname> split ...
11 o = options.Options('bup on', optspec, optfunc=getopt.getopt)
12 (opt, flags, extra) = o.parse(sys.argv[1:])
14 o.fatal('arguments expected')
16 class SigException(Exception):
17 def __init__(self, signum):
19 Exception.__init__(self, 'signal %d received' % signum)
20 def handler(signum, frame):
21 raise SigException(signum)
23 signal.signal(signal.SIGTERM, handler)
24 signal.signal(signal.SIGINT, handler)
33 p = ssh.connect(hostname, 'on--server')
35 argvs = '\0'.join(['bup'] + argv)
36 p.stdin.write(struct.pack('!I', len(argvs)) + argvs)
39 main_exe = os.environ.get('BUP_MAIN_EXE') or sys.argv[0]
40 sp = subprocess.Popen([main_exe, 'server'], stdin=p.stdout, stdout=p.stdin)
47 # if we get a signal while waiting, we have to keep waiting, just
48 # in case our child doesn't die.
53 except SigException, e:
54 log('\nbup on: %s\n' % e)
55 os.kill(p.pid, e.signum)