]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/helpers.py
Use absolute_import from the __future__ everywhere
[bup.git] / lib / bup / helpers.py
index 9f404afdfc2da4da51b05cde91881cb120f7bd3e..583c65b4bf07f040102c153638ff2d1c62b245a2 100644 (file)
@@ -1,5 +1,6 @@
 """Helper functions and classes for bup."""
 
+from __future__ import absolute_import
 from collections import namedtuple
 from contextlib import contextmanager
 from ctypes import sizeof, c_void_p
@@ -11,6 +12,10 @@ import hashlib, heapq, math, operator, time, grp, tempfile
 
 from bup import _helpers
 from bup import compat
+# This function should really be in helpers, not in bup.options.  But we
+# want options.py to be standalone so people can include it in other projects.
+from bup.options import _tty_width as tty_width
+
 
 class Nonlocal:
     """Helper to deal with Python scoping issues"""
@@ -24,12 +29,6 @@ sc_arg_max = os.sysconf('SC_ARG_MAX')
 if sc_arg_max == -1:  # "no definite limit" - let's choose 2M
     sc_arg_max = 2 * 1024 * 1024
 
-# This function should really be in helpers, not in bup.options.  But we
-# want options.py to be standalone so people can include it in other projects.
-from bup.options import _tty_width
-tty_width = _tty_width
-
-
 def last(iterable):
     result = None
     for result in iterable:
@@ -294,7 +293,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
 
@@ -848,7 +847,12 @@ if _mincore:
                     # Perhaps the file was a pipe, i.e. "... | bup split ..."
                     return None
                 raise ex
-            _mincore(m, msize, 0, result, ci * pages_per_chunk);
+            try:
+                _mincore(m, msize, 0, result, ci * pages_per_chunk)
+            except OSError as ex:
+                if ex.errno == errno.ENOSYS:
+                    return None
+                raise
         return result
 
 
@@ -956,14 +960,14 @@ def columnate(l, prefix):
         return ""
     l = l[:]
     clen = max(len(s) for s in l)
-    ncols = (tty_width() - len(prefix)) / (clen + 2)
+    ncols = (tty_width() - len(prefix)) // (clen + 2)
     if ncols <= 1:
         ncols = 1
         clen = 0
     cols = []
     while len(l) % ncols:
         l.append('')
-    rows = len(l)/ncols
+    rows = len(l) // ncols
     for s in range(0, len(l), rows):
         cols.append(l[s:s+rows])
     out = ''
@@ -1056,7 +1060,7 @@ def path_components(path):
     Example:
       '/home/foo' -> [('', '/'), ('home', '/home'), ('foo', '/home/foo')]"""
     if not path.startswith('/'):
-        raise Exception, 'path must start with "/": %s' % path
+        raise Exception('path must start with "/": %s' % path)
     # Since we assume path startswith('/'), we can skip the first element.
     result = [('', '/')]
     norm_path = os.path.abspath(path)