X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cmd%2Flist-idx-cmd.py;h=78bb0a00fb94dc9d26e4756d35833d239d5a7e26;hb=093752b42c5548028c6f84c67f7741b2321c512f;hp=227d8fe48afccb7195e7bff3b3d841f29fdd765a;hpb=c40b3dd5fd74e72024fbaad3daf5a958aefa1c54;p=bup.git diff --git a/cmd/list-idx-cmd.py b/cmd/list-idx-cmd.py index 227d8fe..78bb0a0 100755 --- a/cmd/list-idx-cmd.py +++ b/cmd/list-idx-cmd.py @@ -5,12 +5,14 @@ exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -from __future__ import absolute_import +from __future__ import absolute_import, print_function +from binascii import hexlify, unhexlify import sys, os from bup import git, options +from bup.compat import argv_bytes from bup.helpers import add_error, handle_ctrl_c, log, qprogress, saved_errors - +from bup.io import byte_stream optspec = """ bup list-idx [--find=] @@ -21,7 +23,8 @@ o = options.Options(optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) handle_ctrl_c() -opt.find = opt.find or '' + +opt.find = argv_bytes(opt.find) if opt.find else b'' if not extra: o.fatal('you must provide at least one filename') @@ -30,32 +33,34 @@ if len(opt.find) > 40: o.fatal('--find parameter must be <= 40 chars long') else: if len(opt.find) % 2: - s = opt.find + '0' + s = opt.find + b'0' else: s = opt.find try: - bin = s.decode('hex') + bin = unhexlify(s) except TypeError: o.fatal('--find parameter is not a valid hex string') +sys.stdout.flush() +out = byte_stream(sys.stdout) find = opt.find.lower() - count = 0 -for name in extra: +idxfiles = [argv_bytes(x) for x in extra] +for name in idxfiles: try: ix = git.open_idx(name) except git.GitError as e: - add_error('%s: %s' % (name, e)) + add_error('%r: %s' % (name, e)) continue if len(opt.find) == 40: if ix.exists(bin): - print name, find + out.write(b'%s %s\n' % (name, find)) else: # slow, exhaustive search for _i in ix: - i = str(_i).encode('hex') + i = hexlify(_i) if i.startswith(find): - print name, i + out.write(b'%s %s\n' % (name, i)) qprogress('Searching: %d\r' % count) count += 1