]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/helpers.py
path_components: adjust exception raise for py3
[bup.git] / lib / bup / helpers.py
index 9f404afdfc2da4da51b05cde91881cb120f7bd3e..0f3df669322fddbf24e4fddc5643be6cce9438e9 100644 (file)
@@ -11,6 +11,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,11 +28,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
@@ -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
 
 
@@ -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)