]> arthur.barton.de Git - bup.git/blobdiff - cmd/join-cmd.py
web: remove unneeded __name__ == '__main__' guard
[bup.git] / cmd / join-cmd.py
index 0e1e1ffbc8108b3404d0dd3fdc3379b0d8dac72f..33935d2ad85d997cc8ded8f7faebc22458b88ff9 100755 (executable)
@@ -1,16 +1,23 @@
-#!/usr/bin/env python
-import sys, time, struct
-from bup import hashsplit, git, options, client
-from bup.helpers import *
-from subprocess import PIPE
+#!/bin/sh
+"""": # -*-python-*-
+bup_python="$(dirname "$0")/bup-python" || exit $?
+exec "$bup_python" "$0" ${1+"$@"}
+"""
+# end of bup preamble
+
+import sys
+
+from bup import git, options, client
+from bup.helpers import linereader, log
 
 
 optspec = """
 bup join [-r host:path] [refs or hashes...]
 --
 r,remote=  remote repository path
+o=         output filename
 """
-o = options.Options('bup join', optspec)
+o = options.Options(optspec)
 (opt, flags, extra) = o.parse(sys.argv[1:])
 
 git.check_repo_or_die()
@@ -27,12 +34,17 @@ else:
     cp = git.CatPipe()
     cat = cp.join
 
+if opt.o:
+    outfile = open(opt.o, 'wb')
+else:
+    outfile = sys.stdout
+
 for id in extra:
     try:
         for blob in cat(id):
-            sys.stdout.write(blob)
-    except KeyError, e:
-        sys.stdout.flush()
+            outfile.write(blob)
+    except KeyError as e:
+        outfile.flush()
         log('error: %s\n' % e)
         ret = 1