]> arthur.barton.de Git - bup.git/commitdiff
list-idx-cmd: adjust for python 3 and enable test-list-idx
authorRob Browning <rlb@defaultvalue.org>
Wed, 1 Jan 2020 19:16:43 +0000 (13:16 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sun, 2 Feb 2020 19:30:12 +0000 (13:30 -0600)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
Makefile
cmd/list-idx-cmd.py

index 385fdddeb9233a16ecaa8ed6d3984529b96a592f..46a4d33e06e4888022d9107052f52b6ad2308a1b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -175,6 +175,7 @@ cmdline_tests := \
   t/test-drecurse.sh \
   t/test-fsck.sh \
   t/test-index-clear.sh \
+  t/test-list-idx.sh \
   t/test-ls \
   t/test-ls-remote \
   t/test-tz.sh
@@ -189,7 +190,6 @@ ifeq "2" "$(bup_python_majver)"
     t/test-rm.sh \
     t/test-gc.sh \
     t/test-main.sh \
-    t/test-list-idx.sh \
     t/test-index.sh \
     t/test-split-join.sh \
     t/test-fuse.sh \
index 90753de4473fa61327d41f55909c147285dade17..78bb0a00fb94dc9d26e4756d35833d239d5a7e26 100755 (executable)
@@ -6,11 +6,13 @@ exec "$bup_python" "$0" ${1+"$@"}
 # end of bup preamble
 
 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=<prefix>] <idxfilenames...>
@@ -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