]> arthur.barton.de Git - bup.git/commitdiff
Replace remaining print statements with print function
authorJulien Goodwin <jgoodwin@studio442.com.au>
Thu, 30 Aug 2018 08:25:25 +0000 (18:25 +1000)
committerRob Browning <rlb@defaultvalue.org>
Sat, 1 Sep 2018 17:19:03 +0000 (12:19 -0500)
Also add the appropriate __future__ import statement.

Signed-off-by: Julien Goodwin <jgoodwin@studio442.com.au>
[rlb@defaultvalue.org: memtest-cmd.py: remove a few preexisting
 trailing spaces that were carried over; adjust commit summary]
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
13 files changed:
cmd/drecurse-cmd.py
cmd/fsck-cmd.py
cmd/ftp-cmd.py
cmd/index-cmd.py
cmd/list-idx-cmd.py
cmd/margin-cmd.py
cmd/memtest-cmd.py
cmd/save-cmd.py
cmd/tag-cmd.py
cmd/xstat-cmd.py
lib/bup/metadata.py
lib/bup/t/tindex.py
lib/bup/t/tmetadata.py

index 21ee3a55b45592d9a640f81af3951575ef4b532c..a3a7d30aa4a368ce682bc55b83c55f0478bb84b2 100755 (executable)
@@ -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))
index df43b67080853511670b55ac83655278f0049a53..35b45f8b514a0c07a36d6455bbedc6c85877425c 100755 (executable)
@@ -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
 
 
index 8bd57b6d81accff181dde968af13f865f3979348..a18a93128034a4cc87820a5abcd429a869b80b80 100755 (executable)
@@ -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)
index 539e89ef5019839d67669096593e783d532366e0..51a43bb660f189f238e39c4f59b338809bba317a 100755 (executable)
@@ -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')
index 227d8fe48afccb7195e7bff3b3d841f29fdd765a..90753de4473fa61327d41f55909c147285dade17 100755 (executable)
@@ -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
 
index c042bf88bab8dd3795cb75d3e6f2bf2df44c3109..b01db3d1864e151fe7e74059b024f3eb08be1ebd 100755 (executable)
@@ -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
index 894bb64366a20543cc50d2bcce3874871ca3eec3..88ee06d92cd919700dacd31467a1e0257b0f7d64 100755 (executable)
@@ -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))
index 91d01ca84912dfa2f0e5ca5a1069f816fc06ede6..bf2877ba240a0ff90c79745c5104217c4c1849ea 100755 (executable)
@@ -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
index 00647b973ba3f1e3cbc8fb4595b905c951ff64f6..4e09870856adafb0894c1f7c2fd612e9eeb7c947 100755 (executable)
@@ -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.')
index aa43a53438a7a558b58701211108d08ad15ef190..06a881263bf4ea5b39c9e5a26ee252d336b9c2f4 100755 (executable)
@@ -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:
index e5337c96278563663a1d0c61303df8cbe8d5e162..58e3afa2beaab94926ec9b864b0508bd33e0bd2a 100644 (file)
@@ -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)
index 6364d9e8b25be55fe1cc177dba6cead67527dea9..c79330f8036b029e15d85b990abd257792b7af1f 100644 (file)
@@ -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())
index 91cb6df550c2e63e1631bfea4f3700ff0411c31b..6b0b1e48bc6355b11236abe4895bed6695ce46c0 100644 (file)
@@ -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: ')