]> arthur.barton.de Git - bup.git/blob - cmd/join-cmd.py
Use Python 3 compatible "except ... as e" syntax
[bup.git] / cmd / join-cmd.py
1 #!/bin/sh
2 """": # -*-python-*-
3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
5 """
6 # end of bup preamble
7 import sys
8 from bup import git, options, client
9 from bup.helpers import *
10
11
12 optspec = """
13 bup join [-r host:path] [refs or hashes...]
14 --
15 r,remote=  remote repository path
16 o=         output filename
17 """
18 o = options.Options(optspec)
19 (opt, flags, extra) = o.parse(sys.argv[1:])
20
21 git.check_repo_or_die()
22
23 if not extra:
24     extra = linereader(sys.stdin)
25
26 ret = 0
27
28 if opt.remote:
29     cli = client.Client(opt.remote)
30     cat = cli.cat
31 else:
32     cp = git.CatPipe()
33     cat = cp.join
34
35 if opt.o:
36     outfile = open(opt.o, 'wb')
37 else:
38     outfile = sys.stdout
39
40 for id in extra:
41     try:
42         for blob in cat(id):
43             outfile.write(blob)
44     except KeyError as e:
45         outfile.flush()
46         log('error: %s\n' % e)
47         ret = 1
48
49 sys.exit(ret)