From aeafe13a9330e7deca3dc6b9c0496937d904663a Mon Sep 17 00:00:00 2001 From: Julien Goodwin Date: Thu, 30 Aug 2018 18:25:25 +1000 Subject: [PATCH] Replace remaining print statements with print function Also add the appropriate __future__ import statement. Signed-off-by: Julien Goodwin [rlb@defaultvalue.org: memtest-cmd.py: remove a few preexisting trailing spaces that were carried over; adjust commit summary] Reviewed-by: Rob Browning Tested-by: Rob Browning --- cmd/drecurse-cmd.py | 4 ++-- cmd/fsck-cmd.py | 4 ++-- cmd/ftp-cmd.py | 6 +++--- cmd/index-cmd.py | 4 ++-- cmd/list-idx-cmd.py | 6 +++--- cmd/margin-cmd.py | 6 +++--- cmd/memtest-cmd.py | 28 ++++++++++++++-------------- cmd/save-cmd.py | 6 +++--- cmd/tag-cmd.py | 4 ++-- cmd/xstat-cmd.py | 6 +++--- lib/bup/metadata.py | 31 +++++++++++++++---------------- lib/bup/t/tindex.py | 10 +++++----- lib/bup/t/tmetadata.py | 14 +++++++------- 13 files changed, 64 insertions(+), 65 deletions(-) diff --git a/cmd/drecurse-cmd.py b/cmd/drecurse-cmd.py index 21ee3a5..a3a7d30 100755 --- a/cmd/drecurse-cmd.py +++ b/cmd/drecurse-cmd.py @@ -5,7 +5,7 @@ exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -from __future__ import absolute_import +from __future__ import absolute_import, print_function from os.path import relpath import sys @@ -50,7 +50,7 @@ else: pass else: for (name,st) in it: - print name + print(name) if saved_errors: log('WARNING: %d errors encountered.\n' % len(saved_errors)) diff --git a/cmd/fsck-cmd.py b/cmd/fsck-cmd.py index df43b67..35b45f8 100755 --- a/cmd/fsck-cmd.py +++ b/cmd/fsck-cmd.py @@ -5,7 +5,7 @@ exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -from __future__ import absolute_import +from __future__ import absolute_import, print_function import sys, os, glob, subprocess from bup import options, git @@ -129,7 +129,7 @@ def do_pack(base, last, par2_exists): assert(opt.generate and (not par2_ok or par2_exists)) action_result = 'exists' if par2_exists else 'skipped' if opt.verbose: - print last, action_result + print(last, action_result) return code diff --git a/cmd/ftp-cmd.py b/cmd/ftp-cmd.py index 8bd57b6..a18a931 100755 --- a/cmd/ftp-cmd.py +++ b/cmd/ftp-cmd.py @@ -5,7 +5,7 @@ exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -from __future__ import absolute_import +from __future__ import absolute_import, print_function import sys, os, stat, fnmatch from bup import options, git, shquote, ls, vfs @@ -39,7 +39,7 @@ def inputiter(): try: yield raw_input('bup> ') except EOFError: - print '' # Clear the line for the terminal's next prompt + print() # Clear the line for the terminal's next prompt break else: for line in sys.stdin: @@ -190,7 +190,7 @@ for line in lines: elif cmd == 'pwd': if len(pwd) == 1: sys.stdout.write('/') - print '/'.join(name for name, item in pwd) + print('/'.join(name for name, item in pwd)) elif cmd == 'cat': for parm in words[1:]: res = vfs.resolve(repo, parm, parent=pwd) diff --git a/cmd/index-cmd.py b/cmd/index-cmd.py index 539e89e..51a43bb 100755 --- a/cmd/index-cmd.py +++ b/cmd/index-cmd.py @@ -5,7 +5,7 @@ exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -from __future__ import absolute_import +from __future__ import absolute_import, print_function import sys, stat, time, os, errno, re from bup import metadata, options, git, index, drecurse, hlinkdb @@ -291,7 +291,7 @@ if opt['print'] or opt.status or opt.modified: line += ent.sha.encode('hex') + ' ' if opt.long: line += "%7s %7s " % (oct(ent.mode), oct(ent.gitmode)) - print line + (name or './') + print(line + (name or './')) if opt.check and (opt['print'] or opt.status or opt.modified or opt.update): log('check: starting final check.\n') diff --git a/cmd/list-idx-cmd.py b/cmd/list-idx-cmd.py index 227d8fe..90753de 100755 --- a/cmd/list-idx-cmd.py +++ b/cmd/list-idx-cmd.py @@ -5,7 +5,7 @@ exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -from __future__ import absolute_import +from __future__ import absolute_import, print_function import sys, os from bup import git, options @@ -49,13 +49,13 @@ for name in extra: continue if len(opt.find) == 40: if ix.exists(bin): - print name, find + print(name, find) else: # slow, exhaustive search for _i in ix: i = str(_i).encode('hex') if i.startswith(find): - print name, i + print(name, i) qprogress('Searching: %d\r' % count) count += 1 diff --git a/cmd/margin-cmd.py b/cmd/margin-cmd.py index c042bf8..b01db3d 100755 --- a/cmd/margin-cmd.py +++ b/cmd/margin-cmd.py @@ -5,7 +5,7 @@ exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -from __future__ import absolute_import +from __future__ import absolute_import, print_function import sys, struct, math from bup import options, git, _helpers @@ -38,7 +38,7 @@ def do_predict(ix): expected = prefix * total / (1<<64) diff = count - expected maxdiff = max(maxdiff, abs(diff)) - print '%d of %d (%.3f%%) ' % (maxdiff, len(ix), maxdiff*100.0/len(ix)) + print('%d of %d (%.3f%%) ' % (maxdiff, len(ix), maxdiff*100.0/len(ix))) sys.stdout.flush() assert(count+1 == len(ix)) @@ -59,7 +59,7 @@ else: pm = _helpers.bitmatch(last, i) longmatch = max(longmatch, pm) last = i - print longmatch + print(longmatch) log('%d matching prefix bits\n' % longmatch) doublings = math.log(len(mi), 2) bpd = longmatch / doublings diff --git a/cmd/memtest-cmd.py b/cmd/memtest-cmd.py index 894bb64..88ee06d 100755 --- a/cmd/memtest-cmd.py +++ b/cmd/memtest-cmd.py @@ -5,7 +5,7 @@ exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -from __future__ import absolute_import +from __future__ import absolute_import, print_function import sys, re, struct, time, resource from bup import git, bloom, midx, options, _helpers @@ -55,12 +55,12 @@ def report(count): int((now - last) * 1000)] fmt = '%9s ' + ('%10s ' * len(fields)) if count >= 0: - print fmt % tuple([count] + fields) + print(fmt % tuple([count] + fields)) else: start = now - print fmt % tuple([''] + headers) + print(fmt % tuple([''] + headers)) sys.stdout.flush() - + # don't include time to run report() in usage counts ru = resource.getrusage(resource.RUSAGE_SELF) last_u = ru.ru_utime @@ -114,15 +114,15 @@ for c in xrange(opt.cycles): report((c+1)*opt.number) if bloom._total_searches: - print ('bloom: %d objects searched in %d steps: avg %.3f steps/object' - % (bloom._total_searches, bloom._total_steps, - bloom._total_steps*1.0/bloom._total_searches)) + print('bloom: %d objects searched in %d steps: avg %.3f steps/object' + % (bloom._total_searches, bloom._total_steps, + bloom._total_steps*1.0/bloom._total_searches)) if midx._total_searches: - print ('midx: %d objects searched in %d steps: avg %.3f steps/object' - % (midx._total_searches, midx._total_steps, - midx._total_steps*1.0/midx._total_searches)) + print('midx: %d objects searched in %d steps: avg %.3f steps/object' + % (midx._total_searches, midx._total_steps, + midx._total_steps*1.0/midx._total_searches)) if git._total_searches: - print ('idx: %d objects searched in %d steps: avg %.3f steps/object' - % (git._total_searches, git._total_steps, - git._total_steps*1.0/git._total_searches)) -print 'Total time: %.3fs' % (time.time() - start) + print('idx: %d objects searched in %d steps: avg %.3f steps/object' + % (git._total_searches, git._total_steps, + git._total_steps*1.0/git._total_searches)) +print('Total time: %.3fs' % (time.time() - start)) diff --git a/cmd/save-cmd.py b/cmd/save-cmd.py index 91d01ca..bf2877b 100755 --- a/cmd/save-cmd.py +++ b/cmd/save-cmd.py @@ -5,7 +5,7 @@ exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -from __future__ import absolute_import +from __future__ import absolute_import, print_function from errno import EACCES from io import BytesIO import os, sys, stat, time, math @@ -453,14 +453,14 @@ tree = _pop(force_tree = None, dir_metadata = metadata.Metadata() if root_collision else None) if opt.tree: - print tree.encode('hex') + print(tree.encode('hex')) if opt.commit or opt.name: msg = 'bup save\n\nGenerated by command:\n%r\n' % sys.argv userline = '%s <%s@%s>' % (userfullname(), username(), hostname()) commit = w.new_commit(tree, oldref, userline, date, None, userline, date, None, msg) if opt.commit: - print commit.encode('hex') + print(commit.encode('hex')) msr.close() w.close() # must close before we can update the ref diff --git a/cmd/tag-cmd.py b/cmd/tag-cmd.py index 00647b9..4e09870 100755 --- a/cmd/tag-cmd.py +++ b/cmd/tag-cmd.py @@ -5,7 +5,7 @@ exec "$bup_python" "$0" ${1+"$@"} """ # end of bup preamble -from __future__ import absolute_import +from __future__ import absolute_import, print_function import os, sys from bup import git, options @@ -45,7 +45,7 @@ if opt.delete: if not extra: for t in tags: - print t + print(t) sys.exit(0) elif len(extra) < 2: o.fatal('no commit ref or hash given.') diff --git a/cmd/xstat-cmd.py b/cmd/xstat-cmd.py index aa43a53..06a8812 100755 --- a/cmd/xstat-cmd.py +++ b/cmd/xstat-cmd.py @@ -10,7 +10,7 @@ exec "$bup_python" "$0" ${1+"$@"} # This code is covered under the terms of the GNU Library General # Public License as described in the bup LICENSE file. -from __future__ import absolute_import +from __future__ import absolute_import, print_function import sys, stat, errno from bup import metadata, options, xstat @@ -94,14 +94,14 @@ for path in remainder: raise if metadata.verbose >= 0: if not first_path: - print + print() if atime_resolution != 1: m.atime = (m.atime / atime_resolution) * atime_resolution if mtime_resolution != 1: m.mtime = (m.mtime / mtime_resolution) * mtime_resolution if ctime_resolution != 1: m.ctime = (m.ctime / ctime_resolution) * ctime_resolution - print metadata.detailed_str(m, active_fields) + print(metadata.detailed_str(m, active_fields)) first_path = False if saved_errors: diff --git a/lib/bup/metadata.py b/lib/bup/metadata.py index e5337c9..58e3afa 100644 --- a/lib/bup/metadata.py +++ b/lib/bup/metadata.py @@ -5,7 +5,7 @@ # This code is covered under the terms of the GNU Library General # Public License as described in the bup LICENSE file. -from __future__ import absolute_import +from __future__ import absolute_import, print_function from copy import deepcopy from errno import EACCES, EINVAL, ENOTTY, ENOSYS, EOPNOTSUPP from io import BytesIO @@ -925,7 +925,7 @@ def save_tree(output_file, paths, m = from_path(p, statinfo=st, archive_path=safe_path, save_symlinks=save_symlinks) if verbose: - print >> sys.stderr, m.path + print(m.path, file=sys.stderr) m.write(output_file, include_path=write_paths) else: start_dir = os.getcwd() @@ -937,7 +937,7 @@ def save_tree(output_file, paths, m = from_path(p, statinfo=st, archive_path=safe_path, save_symlinks=save_symlinks) if verbose: - print >> sys.stderr, m.path + print(m.path, file=sys.stderr) m.write(output_file, include_path=write_paths) os.chdir(dirlist_dir) finally: @@ -1107,20 +1107,19 @@ def display_archive(file): first_item = True for meta in _ArchiveIterator(file): if not first_item: - print - print detailed_str(meta) + print() + print(detailed_str(meta)) first_item = False elif verbose > 0: for meta in _ArchiveIterator(file): - print summary_str(meta) + print(summary_str(meta)) elif verbose == 0: for meta in _ArchiveIterator(file): if not meta.path: - print >> sys.stderr, \ - 'bup: no metadata path, but asked to only display path', \ - '(increase verbosity?)' + print('bup: no metadata path, but asked to only display path' + '(increase verbosity?)') sys.exit(1) - print meta.path + print(meta.path) def start_extract(file, create_symlinks=True): @@ -1128,7 +1127,7 @@ def start_extract(file, create_symlinks=True): if not meta: # Hit end record. break if verbose: - print >> sys.stderr, meta.path + print(meta.path, file=sys.stderr) xpath = _clean_up_extract_path(meta.path) if not xpath: add_error(Exception('skipping risky path "%s"' % meta.path)) @@ -1150,7 +1149,7 @@ def finish_extract(file, restore_numeric_ids=False): all_dirs.append(meta) else: if verbose: - print >> sys.stderr, meta.path + print(meta.path, file=sys.stderr) meta.apply_to_path(path=xpath, restore_numeric_ids=restore_numeric_ids) all_dirs.sort(key = lambda x : len(x.path), reverse=True) @@ -1158,7 +1157,7 @@ def finish_extract(file, restore_numeric_ids=False): # Don't need to check xpath -- won't be in all_dirs if not OK. xpath = _clean_up_extract_path(dir.path) if verbose: - print >> sys.stderr, dir.path + print(dir.path, file=sys.stderr) dir.apply_to_path(path=xpath, restore_numeric_ids=restore_numeric_ids) @@ -1175,20 +1174,20 @@ def extract(file, restore_numeric_ids=False, create_symlinks=True): else: meta.path = xpath if verbose: - print >> sys.stderr, '+', meta.path + print('+', meta.path, file=sys.stderr) _set_up_path(meta, create_symlinks=create_symlinks) if os.path.isdir(meta.path): all_dirs.append(meta) else: if verbose: - print >> sys.stderr, '=', meta.path + print('=', meta.path, file=sys.stderr) meta.apply_to_path(restore_numeric_ids=restore_numeric_ids) all_dirs.sort(key = lambda x : len(x.path), reverse=True) for dir in all_dirs: # Don't need to check xpath -- won't be in all_dirs if not OK. xpath = _clean_up_extract_path(dir.path) if verbose: - print >> sys.stderr, '=', xpath + print('=', xpath, file=sys.stderr) # Shouldn't have to check for risky paths here (omitted above). dir.apply_to_path(path=dir.path, restore_numeric_ids=restore_numeric_ids) diff --git a/lib/bup/t/tindex.py b/lib/bup/t/tindex.py index 6364d9e..c79330f 100644 --- a/lib/bup/t/tindex.py +++ b/lib/bup/t/tindex.py @@ -1,5 +1,5 @@ -from __future__ import absolute_import +from __future__ import absolute_import, print_function import os, time from wvtest import * @@ -51,9 +51,9 @@ def index_writer(): def dump(m): for e in list(m): - print '%s%s %s' % (e.is_valid() and ' ' or 'M', + print('%s%s %s' % (e.is_valid() and ' ' or 'M', e.is_fake() and 'F' or ' ', - e.name) + e.name)) def fake_validate(*l): for i in l: @@ -149,7 +149,7 @@ def index_dirty(): fake_validate(r1) dump(r1) - print [hex(e.flags) for e in r1] + print([hex(e.flags) for e in r1]) WVPASSEQ([e.name for e in r1 if e.is_valid()], r1all) WVPASSEQ([e.name for e in r1 if not e.is_valid()], []) WVPASSEQ([e.name for e in index.merge(r2, r1, r3) if not e.is_valid()], @@ -161,7 +161,7 @@ def index_dirty(): | set(['/a/b/n/2', '/a/c/n/3']) dump(index.merge(r2, r1, r3)) for e in index.merge(r2, r1, r3): - print e.name, hex(e.flags), e.ctime + print(e.name, hex(e.flags), e.ctime) eiv = e.name in expect_invalid er = e.name in expect_real WVPASSEQ(eiv, not e.is_valid()) diff --git a/lib/bup/t/tmetadata.py b/lib/bup/t/tmetadata.py index 91cb6df..6b0b1e4 100644 --- a/lib/bup/t/tmetadata.py +++ b/lib/bup/t/tmetadata.py @@ -1,5 +1,5 @@ -from __future__ import absolute_import +from __future__ import absolute_import, print_function import errno, glob, grp, pwd, stat, tempfile, subprocess from wvtest import * @@ -22,16 +22,16 @@ start_dir = os.getcwd() def ex(*cmd): try: cmd_str = ' '.join(cmd) - print >> sys.stderr, cmd_str + print(cmd_str, file=sys.stderr) rc = subprocess.call(cmd) if rc < 0: - print >> sys.stderr, 'terminated by signal', - rc + print('terminated by signal', - rc, file=sys.stderr) sys.exit(1) elif rc > 0: - print >> sys.stderr, 'returned exit status', rc + print('returned exit status', rc, file=sys.stderr) sys.exit(1) except OSError as e: - print >> sys.stderr, 'subprocess call failed:', e + print('subprocess call failed:', e, file=sys.stderr) sys.exit(1) @@ -185,7 +185,7 @@ def test_from_path_error(): os.chmod(path, 0o000) metadata.from_path(path, archive_path=path, save_symlinks=True) if metadata.get_linux_file_attr: - print >> sys.stderr, 'saved_errors:', helpers.saved_errors + print('saved_errors:', helpers.saved_errors, file=sys.stderr) WVPASS(len(helpers.saved_errors) == 1) errmsg = _first_err() WVPASS(errmsg.startswith('read Linux attr')) @@ -223,7 +223,7 @@ def test_apply_to_path_restricted_access(): WVPASSEQ(m.path, path) os.chmod(parent, 0o000) m.apply_to_path(path) - print >> sys.stderr, 'saved_errors:', helpers.saved_errors + print('saved_errors:', helpers.saved_errors, file=sys.stderr) expected_errors = ['utime: '] if m.linux_attr and _linux_attr_supported(tmpdir): expected_errors.append('Linux chattr: ') -- 2.39.2