Skip to content

Commit

Permalink
cmd/join: add a new -o (output filename) option.
Browse files Browse the repository at this point in the history
This is a helpful way to have it open and write to the given output file.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
  • Loading branch information
apenwarr committed Feb 13, 2011
1 parent 11635a2 commit cf86321
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions cmd/join-cmd.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
bup join [-r host:path] [refs or hashes...] bup join [-r host:path] [refs or hashes...]
-- --
r,remote= remote repository path r,remote= remote repository path
o= output filename
""" """
o = options.Options(optspec) o = options.Options(optspec)
(opt, flags, extra) = o.parse(sys.argv[1:]) (opt, flags, extra) = o.parse(sys.argv[1:])
Expand All @@ -26,12 +27,17 @@
cp = git.CatPipe() cp = git.CatPipe()
cat = cp.join cat = cp.join


if opt.o:
outfile = open(opt.o, 'wb')
else:
outfile = sys.stdout

for id in extra: for id in extra:
try: try:
for blob in cat(id): for blob in cat(id):
sys.stdout.write(blob) outfile.write(blob)
except KeyError, e: except KeyError, e:
sys.stdout.flush() outfile.flush()
log('error: %s\n' % e) log('error: %s\n' % e)
ret = 1 ret = 1


Expand Down
2 changes: 1 addition & 1 deletion t/test.sh
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ WVPASS bup memtest -c1 -n100 --existing
WVSTART "join" WVSTART "join"
WVPASS bup join $(cat tags1.tmp) >out1.tmp WVPASS bup join $(cat tags1.tmp) >out1.tmp
WVPASS bup join <tags2.tmp >out2.tmp WVPASS bup join <tags2.tmp >out2.tmp
WVPASS bup join <tags2t.tmp >out2t.tmp WVPASS bup join <tags2t.tmp -o out2t.tmp
WVPASS bup join -r "$BUP_DIR" <tags2c.tmp >out2c.tmp WVPASS bup join -r "$BUP_DIR" <tags2c.tmp >out2c.tmp
WVPASS bup join -r ":$BUP_DIR" <tags2c.tmp >out2c.tmp WVPASS bup join -r ":$BUP_DIR" <tags2c.tmp >out2c.tmp
WVPASS diff -u t/testfile1 out1.tmp WVPASS diff -u t/testfile1 out1.tmp
Expand Down

0 comments on commit cf86321

Please sign in to comment.