]> arthur.barton.de Git - bup.git/blobdiff - cmd/on-cmd.py
Use BytesIO instead of StringIO
[bup.git] / cmd / on-cmd.py
index 60759b64a6d6d85332c489de8a81df04f6d57f94..f76ad3e1e06a71fd07de06db586f1827d92d1a97 100755 (executable)
@@ -1,5 +1,11 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""": # -*-python-*-
+bup_python="$(dirname "$0")/bup-python" || exit $?
+exec "$bup_python" "$0" ${1+"$@"}
+"""
+# end of bup preamble
 import sys, os, struct, getopt, subprocess, signal
+from subprocess import PIPE
 from bup import options, ssh, path
 from bup.helpers import *
 
@@ -33,9 +39,8 @@ try:
         (hostname, port) = (hp[0], None)
     else:
         (hostname, port) = hp
-
     argv = extra[1:]
-    p = ssh.connect(hostname, port, 'on--server')
+    p = ssh.connect(hostname, port, 'on--server', stderr=PIPE)
 
     try:
         argvs = '\0'.join(['bup'] + argv)
@@ -45,6 +50,10 @@ try:
                               stdin=p.stdout, stdout=p.stdin)
         p.stdin.close()
         p.stdout.close()
+        # Demultiplex remote client's stderr (back to stdout/stderr).
+        dmc = DemuxConn(p.stderr.fileno(), open(os.devnull, "w"))
+        for line in iter(dmc.readline, ""):
+            sys.stdout.write(line)
     finally:
         while 1:
             # if we get a signal while waiting, we have to keep waiting, just
@@ -54,11 +63,11 @@ try:
                 if sp:
                     sp.wait()
                 break
-            except SigException, e:
+            except SigException as e:
                 log('\nbup on: %s\n' % e)
                 os.kill(p.pid, e.signum)
                 ret = 84
-except SigException, e:
+except SigException as e:
     if ret == 0:
         ret = 99
     log('\nbup on: %s\n' % e)