From: Rob Browning Date: Tue, 31 Dec 2019 23:44:39 +0000 (-0600) Subject: Adjust columnate for python 3; enable test-ls test-ls-remote X-Git-Tag: 0.31~154 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11ab0f39605bf9ec7920de507c5cb6c073ccfd93;hp=d1291f927f680ba0a146ba3bb1fd23dec6c61066;p=bup.git Adjust columnate for python 3; enable test-ls test-ls-remote Signed-off-by: Rob Browning Tested-by: Rob Browning --- diff --git a/Makefile b/Makefile index 4bfd833..74b41c1 100644 --- 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 \ diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py index 0e90780..8773cfc 100644 --- a/lib/bup/helpers.py +++ b/lib/bup/helpers.py @@ -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 diff --git a/t/test-ls b/t/test-ls index 2b919a2..fcff652 100755 --- 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" \