]> arthur.barton.de Git - bup.git/blob - cmd/join-cmd.py
Adjust split-cmd join-cmd margin-cmd for python 3; test-split-join
[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
8 from __future__ import absolute_import
9 import sys
10
11 from bup import git, options
12 from bup.compat import argv_bytes
13 from bup.helpers import linereader, log
14 from bup.io import byte_stream
15 from bup.repo import LocalRepo, RemoteRepo
16
17
18 optspec = """
19 bup join [-r host:path] [refs or hashes...]
20 --
21 r,remote=  remote repository path
22 o=         output filename
23 """
24 o = options.Options(optspec)
25 (opt, flags, extra) = o.parse(sys.argv[1:])
26 if opt.remote:
27     opt.remote = argv_bytes(opt.remote)
28
29 git.check_repo_or_die()
30
31 stdin = byte_stream(sys.stdin)
32
33 if not extra:
34     extra = linereader(stdin)
35
36 ret = 0
37 repo = RemoteRepo(opt.remote) if opt.remote else LocalRepo()
38
39 if opt.o:
40     outfile = open(opt.o, 'wb')
41 else:
42     sys.stdout.flush()
43     outfile = byte_stream(sys.stdout)
44
45 for ref in [argv_bytes(x) for x in extra]:
46     try:
47         for blob in repo.join(ref):
48             outfile.write(blob)
49     except KeyError as e:
50         outfile.flush()
51         log('error: %s\n' % e)
52         ret = 1
53
54 sys.exit(ret)