]> arthur.barton.de Git - bup.git/blob - lib/cmd/join-cmd.py
e17c3159bcd2ed487e5cbf7b73e1e0cd07247066
[bup.git] / lib / cmd / join-cmd.py
1 #!/bin/sh
2 """": # -*-python-*-
3 # https://sourceware.org/bugzilla/show_bug.cgi?id=26034
4 export "BUP_ARGV_0"="$0"
5 arg_i=1
6 for arg in "$@"; do
7     export "BUP_ARGV_${arg_i}"="$arg"
8     shift
9     arg_i=$((arg_i + 1))
10 done
11 # Here to end of preamble replaced during install
12 bup_python="$(dirname "$0")/bup-python" || exit $?
13 exec "$bup_python" "$0"
14 """
15 # end of bup preamble
16
17 from __future__ import absolute_import
18 import sys
19
20 from bup import compat, git, options
21 from bup.compat import argv_bytes
22 from bup.helpers import linereader, log
23 from bup.io import byte_stream
24 from bup.repo import LocalRepo, RemoteRepo
25
26
27 optspec = """
28 bup join [-r host:path] [refs or hashes...]
29 --
30 r,remote=  remote repository path
31 o=         output filename
32 """
33 o = options.Options(optspec)
34 opt, flags, extra = o.parse(compat.argv[1:])
35 if opt.remote:
36     opt.remote = argv_bytes(opt.remote)
37
38 git.check_repo_or_die()
39
40 stdin = byte_stream(sys.stdin)
41
42 if not extra:
43     extra = linereader(stdin)
44
45 ret = 0
46 repo = RemoteRepo(opt.remote) if opt.remote else LocalRepo()
47
48 if opt.o:
49     outfile = open(opt.o, 'wb')
50 else:
51     sys.stdout.flush()
52     outfile = byte_stream(sys.stdout)
53
54 for ref in [argv_bytes(x) for x in extra]:
55     try:
56         for blob in repo.join(ref):
57             outfile.write(blob)
58     except KeyError as e:
59         outfile.flush()
60         log('error: %s\n' % e)
61         ret = 1
62
63 sys.exit(ret)