]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/options.py
Use absolute_import from the __future__ everywhere
[bup.git] / lib / bup / options.py
index d73aac2eb126484aa57c1a31887e32a96338e0d9..394b71daed2311e9417cd97353e9b12975b7b288 100644 (file)
@@ -60,8 +60,20 @@ Options can be put in different groups. Options in the same group must be on
 consecutive lines. Groups are formed by inserting a line that begins with a
 space. The text on that line will be output after an empty line.
 """
+
+from __future__ import absolute_import
 import sys, os, textwrap, getopt, re, struct
 
+try:
+    import fcntl
+except ImportError:
+    fcntl = None
+
+try:
+    import termios
+except ImportError:
+    termios = None
+
 
 def _invert(v, invert):
     if invert:
@@ -123,15 +135,18 @@ def _atoi(v):
         return 0
 
 
-def _tty_width():
-    s = struct.pack("HHHH", 0, 0, 0, 0)
-    try:
-        import fcntl, termios
-        s = fcntl.ioctl(sys.stderr.fileno(), termios.TIOCGWINSZ, s)
-    except (IOError, ImportError):
-        return _atoi(os.environ.get('WIDTH')) or 70
-    (ysize,xsize,ypix,xpix) = struct.unpack('HHHH', s)
-    return xsize or 70
+if not fcntl and termios:
+    def _tty_width():
+        return 70
+else:
+    def _tty_width():
+        s = struct.pack("HHHH", 0, 0, 0, 0)
+        try:
+            s = fcntl.ioctl(sys.stderr.fileno(), termios.TIOCGWINSZ, s)
+        except IOError:
+            return 70
+        ysize, xsize, ypix, xpix = struct.unpack('HHHH', s)
+        return xsize or 70
 
 
 class Options:
@@ -252,7 +267,7 @@ class Options:
 
         opt = OptDict(aliases=self._aliases)
 
-        for k,v in self._defaults.iteritems():
+        for k,v in self._defaults.items():
             opt[k] = v
 
         for (k,v) in flags: