]> arthur.barton.de Git - bup.git/commitdiff
Add compat.items() and use it
authorRob Browning <rlb@defaultvalue.org>
Thu, 18 Jan 2018 02:00:00 +0000 (20:00 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sat, 27 Jan 2018 16:23:45 +0000 (10:23 -0600)
Python 3 made items behave like iteritems and dropped iteritems.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/compat.py
lib/bup/helpers.py
lib/bup/hlinkdb.py
lib/bup/rm.py
main.py
t/test-prune-older

index 183df9da33ab492631136eb7ae87db3615eef60b..51aabf8db38a4839ca8b5d47a9d31e83b113f84a 100644 (file)
@@ -21,6 +21,9 @@ if py3:
         """Do nothing (already handled by Python 3 infrastructure)."""
         return ex
 
+    def items(x):
+        return x.items()
+
 else:  # Python 2
 
     str_type = basestring
@@ -59,6 +62,10 @@ else:  # Python 2
             tb = getattr(ex, '__traceback__', None)
             print_exception(type(ex), ex, tb)
 
+    def items(x):
+        return x.iteritems()
+
+
 def wrap_main(main):
     """Run main() and raise a SystemExit with the return value if it
     returns, pass along any SystemExit it raises, convert
index 26e96c8e0d8934bf7841cd567b15efae1d0924e0..4ead99ad76085a6274668f20fcd6cf052aa3d5a2 100644 (file)
@@ -292,7 +292,7 @@ def _argmax_base(command):
     base_size = 2048
     for c in command:
         base_size += len(command) + 1
-    for k, v in environ.iteritems():
+    for k, v in compat.items(environ):
         base_size += len(k) + len(v) + 2 + sizeof(c_void_p)
     return base_size
 
index 70f3213f8b061805533fda066b196ce2f14b2b32..5c1ec0099621b46130217c4622937b7617473e7c 100644 (file)
@@ -1,5 +1,7 @@
 import cPickle, errno, os, tempfile
 
+from bup import compat
+
 class Error(Exception):
     pass
 
@@ -27,7 +29,7 @@ class HLinkDB:
                 f.close()
                 f = None
         # Set up the reverse hard link index.
-        for node, paths in self._node_paths.iteritems():
+        for node, paths in compat.items(self._node_paths):
             for path in paths:
                 self._path_node[path] = node
 
index 23423e951d271b499cdf699b42ece88099d76320..453de343cfb7baf3033eda4388697f96ddb0935c 100644 (file)
@@ -1,7 +1,7 @@
 
 import sys
 
-from bup import git, vfs
+from bup import compat, git, vfs
 from bup.client import ClientError
 from bup.git import get_commit_items
 from bup.helpers import add_error, die_if_errors, log, saved_errors
@@ -103,7 +103,7 @@ def bup_rm(repo, paths, compression=6, verbosity=None):
 
     updated_refs = {}  # ref_name -> (original_ref, tip_commit(bin))
 
-    for branchname, branchitem in dead_branches.iteritems():
+    for branchname, branchitem in compat.items(dead_branches):
         ref = 'refs/heads/' + branchname
         assert(not ref in updated_refs)
         updated_refs[ref] = (branchitem.oid, None)
@@ -111,7 +111,7 @@ def bup_rm(repo, paths, compression=6, verbosity=None):
     if dead_saves:
         writer = git.PackWriter(compression_level=compression)
         try:
-            for branch, saves in dead_saves.iteritems():
+            for branch, saves in compat.items(dead_saves):
                 assert(saves)
                 updated_refs['refs/heads/' + branch] = rm_saves(saves, writer)
         except:
@@ -126,7 +126,7 @@ def bup_rm(repo, paths, compression=6, verbosity=None):
     # Only update the refs here, at the very end, so that if something
     # goes wrong above, the old refs will be undisturbed.  Make an attempt
     # to update each ref.
-    for ref_name, info in updated_refs.iteritems():
+    for ref_name, info in compat.items(updated_refs):
         orig_ref, new_ref = info
         try:
             if not new_ref:
diff --git a/main.py b/main.py
index 119826564d7266815639d978c9d11400c5364ddc..dc1bec28690015fceaf127ec27af29ce56767748 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -215,7 +215,7 @@ def filter_output(src_out, src_err, dest_out, dest_err):
         pending_ex = chain_ex(add_ex_tb(ex), pending_ex)
     try:
         # Try to finish each of the streams
-        for fd, pending_items in pending.iteritems():
+        for fd, pending_items in compat.items(pending):
             dest = dest_out if fd == src_out else dest_err
             try:
                 print_clean_line(dest, pending_items, width)
index e0f5e332085fca784c84f8c031b57cecbae9b50d..2ec59474c170fe49b2475a9e8352d610739c6eb6 100755 (executable)
@@ -26,6 +26,7 @@ bup_cmd = top + '/bup'
 from buptest import exc, exo, test_tempdir
 from wvtest import wvfail, wvpass, wvpasseq, wvpassne, wvstart
 
+from bup import compat
 from bup.helpers import partition, period_as_secs, readpipe
 
 
@@ -69,7 +70,7 @@ def expected_retentions(utcs, utc_start, spec):
         return utcs
     utcs = sorted(utcs, reverse=True)
     period_start = dict(spec)
-    for kind, duration in period_start.iteritems():
+    for kind, duration in compat.items(period_start):
         period_start[kind] = utc_start - period_as_secs(duration)
     period_start = defaultdict(lambda: float('inf'), period_start)