]> arthur.barton.de Git - bup.git/commitdiff
Adjust columnate for python 3; enable test-ls test-ls-remote
authorRob Browning <rlb@defaultvalue.org>
Tue, 31 Dec 2019 23:44:39 +0000 (17:44 -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
lib/bup/helpers.py
t/test-ls

index 4bfd833e15691955d3b53d6a7cf3a1b4553c03bd..74b41c1ef173876119de220509a6f7ab9d635233 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -171,6 +171,8 @@ cmdline_tests := \
   t/test-argv \
   t/test-compression.sh \
   t/test-index-clear.sh \
+  t/test-ls \
+  t/test-ls-remote \
   t/test-tz.sh
 
 ifeq "2" "$(bup_python_majver)"
@@ -191,8 +193,6 @@ ifeq "2" "$(bup_python_majver)"
     t/test-cat-file.sh \
     t/test-fsck.sh \
     t/test-index-check-device.sh \
-    t/test-ls \
-    t/test-ls-remote \
     t/test-meta.sh \
     t/test-on.sh \
     t/test-restore-map-owner.sh \
index 0e9078092200d92f3c489a45f89d0a5e3ca9b4e7..8773cfc0cf98e28f08e511642083881ab25c060f 100644 (file)
@@ -922,8 +922,11 @@ def columnate(l, prefix):
     The number of columns is determined automatically based on the string
     lengths.
     """
+    binary = isinstance(prefix, bytes)
+    nothing = b'' if binary else ''
+    nl = b'\n' if binary else '\n'
     if not l:
-        return ""
+        return nothing
     l = l[:]
     clen = max(len(s) for s in l)
     ncols = (tty_width() - len(prefix)) // (clen + 2)
@@ -932,13 +935,14 @@ def columnate(l, prefix):
         clen = 0
     cols = []
     while len(l) % ncols:
-        l.append('')
+        l.append(nothing)
     rows = len(l) // ncols
     for s in compat.range(0, len(l), rows):
         cols.append(l[s:s+rows])
-    out = ''
+    out = nothing
+    fmt = b'%-*s' if binary else '%-*s'
     for row in zip(*cols):
-        out += prefix + ''.join(('%-*s' % (clen+2, s)) for s in row) + '\n'
+        out += prefix + nothing.join((fmt % (clen+2, s)) for s in row) + nl
     return out
 
 
index 2b919a211958318f416ce8be1f830b8ae20e3e48..fcff652d4c2008b22891efd273e07f37a96c45de 100755 (executable)
--- a/t/test-ls
+++ b/t/test-ls
@@ -51,10 +51,10 @@ WVPASS bup save -n src -d 242312160 --strip src
 WVPASS bup tag some-tag src
 
 uid="$(WVPASS id -u)" || exit $?
-gid="$(WVPASS bup-python -c 'import os; print os.stat("src").st_gid')" || exit $?
+gid="$(WVPASS bup-python -c 'import os; print(os.stat("src").st_gid)')" || exit $?
 user="$(WVPASS id -un)" || exit $?
 group="$(WVPASS bup-python -c 'import grp, os;
-print grp.getgrgid(os.stat("src").st_gid)[0]')" || exit $?
+print(grp.getgrgid(os.stat("src").st_gid)[0])')" || exit $?
 src_commit_hash=$(git log --format=%H -n1 src)
 src_tree_hash=$(git log --format=%T -n1 src)
 
@@ -170,7 +170,7 @@ test "$bad_symlink_date" || exit 1
 
 if test "$(uname -s)" != NetBSD; then
     bad_symlink_size="$(WVPASS bup-python -c "import os
-print os.lstat('src/bad-symlink').st_size")" || exit $?
+print(os.lstat('src/bad-symlink').st_size)")" || exit $?
 else
     # NetBSD appears to return varying sizes, so for now, just ignore it.
     bad_symlink_size="$(WVPASS echo "$bad_symlink_bup_info" \
@@ -191,7 +191,7 @@ test "$symlink_date" || exit 1
 
 if test "$(uname -s)" != NetBSD; then
     symlink_size="$(WVPASS bup-python -c "import os
-print os.lstat('src/symlink').st_size")" || exit $?
+print(os.lstat('src/symlink').st_size)")" || exit $?
 else
     # NetBSD appears to return varying sizes, so for now, just ignore it.
     symlink_size="$(WVPASS echo "$symlink_bup_info" \