]> arthur.barton.de Git - bup.git/commitdiff
Get rid of some python syntax not compatible with python 2.4.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 20 Mar 2011 09:57:31 +0000 (02:57 -0700)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 20 Mar 2011 10:56:08 +0000 (03:56 -0700)
Mostly this is 'x if b else y' crap, which I hate anyway.

This makes 'make test' *almost* pass on my MacOS 10.4 system (with upgrade
to python 2.4 from fink).

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
lib/bup/metadata.py
lib/bup/t/tmetadata.py
lib/bup/vint.py
lib/bup/xstat.py

index 4751133b2905483704054d887e6edf7e5fc072dd..5c4a6900d4fdf70510dca8410d3295f176611354 100644 (file)
@@ -536,7 +536,7 @@ class Metadata:
         self.posix1e_acl_default = None
 
     def write(self, port, include_path=True):
-        records = [(_rec_tag_path, self._encode_path())] if include_path else []
+        records = include_path and [(_rec_tag_path, self._encode_path())] or []
         records.extend([(_rec_tag_common, self._encode_common()),
                         (_rec_tag_symlink_target, self._encode_symlink_target()),
                         (_rec_tag_posix1e_acl, self._encode_posix1e_acl()),
@@ -604,7 +604,7 @@ class Metadata:
 def from_path(path, statinfo=None, archive_path=None, save_symlinks=True):
     result = Metadata()
     result.path = archive_path
-    st = statinfo if statinfo else lstat(path)
+    st = statinfo or lstat(path)
     result._add_common(path, st)
     if save_symlinks:
         result._add_symlink_target(path, st)
index 8660ed9512e8faf9fe55c6c32e970beb1fbea0a4..786a97dab8ee541f2989d71e40fbbb6e7fc585ed 100644 (file)
@@ -108,6 +108,12 @@ def test_clean_up_extract_path():
     WVPASSEQ(cleanup('///foo/bar'), 'foo/bar')
 
 
+def _first_err():
+    if helpers.saved_errors:
+        return str(helpers.saved_errors[0])
+    return ''
+
+
 @wvtest
 def test_from_path_error():
     if os.geteuid() == 0 or detect_fakeroot():
@@ -121,7 +127,7 @@ def test_from_path_error():
         os.chmod(path, 000)
         metadata.from_path(path, archive_path=path, save_symlinks=True)
         if metadata.get_linux_file_attr:
-            errmsg = helpers.saved_errors[0] if helpers.saved_errors else ''
+            errmsg = _first_err()
             WVPASS(errmsg.startswith('read Linux attr'))
             clear_errors()
     finally:
@@ -141,7 +147,7 @@ def test_apply_to_path_restricted_access():
         WVPASSEQ(m.path, path)
         os.chmod(tmpdir, 000)
         m.apply_to_path(path)
-        errmsg = str(helpers.saved_errors[0]) if helpers.saved_errors else ''
+        errmsg = _first_err()
         WVPASS(errmsg.startswith('utime: '))
         clear_errors()
     finally:
@@ -162,13 +168,13 @@ def test_restore_restricted_user_group():
         orig_uid = m.uid
         m.uid = 0;
         m.apply_to_path(path, restore_numeric_ids=True)
-        errmsg = str(helpers.saved_errors[0]) if helpers.saved_errors else ''
+        errmsg = _first_err()
         WVPASS(errmsg.startswith('lchown: '))
         clear_errors()
         m.uid = orig_uid
         m.gid = 0;
         m.apply_to_path(path, restore_numeric_ids=True)
-        errmsg = str(helpers.saved_errors[0]) if helpers.saved_errors else ''
+        errmsg = _first_err()
         WVPASS(errmsg.startswith('lchown: ') or os.stat(path).st_gid == m.gid)
         clear_errors()
     finally:
@@ -183,8 +189,10 @@ def test_restore_nonexistent_user_group():
         os.mkdir(path)
         m = metadata.from_path(path, archive_path=path, save_symlinks=True)
         WVPASSEQ(m.path, path)
-        m.owner = max([x.pw_name for x in pwd.getpwall()], key=len) + 'x'
-        m.group = max([x.gr_name for x in grp.getgrall()], key=len) + 'x'
+        junk,m.owner = max([(len(x.pw_name), x.pw_name + 'x')
+                           for x in pwd.getpwall()])
+        junk,m.group = max([(len(x.gr_name), x.gr_name + 'x')
+                            for x in grp.getgrall()])
         WVPASSEQ(m.apply_to_path(path, restore_numeric_ids=True), None)
         WVPASSEQ(os.stat(path).st_uid, m.uid)
         WVPASSEQ(os.stat(path).st_gid, m.gid)
index 8f7f58a6698ddc22a3d9a3959190c323d03e69dd..bca93bd0b5eb9f18c4db0a270e6154ef525481b1 100644 (file)
@@ -77,8 +77,10 @@ def read_vint(port):
         if b & 0x80:
             offset += 6
             c = port.read(1)
+        elif negative:
+            return -result
         else:
-            return -result if negative else result
+            return result
     while c:
         b = ord(c)
         if b & 0x80:
@@ -88,7 +90,10 @@ def read_vint(port):
         else:
             result |= (b << offset)
             break
-    return -result if negative else result
+    if negative:
+        return -result
+    else:
+        return result
 
 
 def write_bvec(port, x):
index e2aa1530da8c4af3d17278a24e94c41bff99353e..abc93fe3756cc7959692e4cbe0b78a69da0a9783 100644 (file)
@@ -9,7 +9,7 @@ except AttributeError, e:
     _have_utimensat = False
 
 
-class FSTime():
+class FSTime:
     # Class to represent filesystem timestamps.  Use integer
     # nanoseconds on platforms where we have the higher resolution
     # lstat.  Use the native python stat representation (floating
@@ -81,7 +81,7 @@ else:
         os.utime(path, (atime, mtime))
 
 
-class stat_result():
+class stat_result:
     @staticmethod
     def from_stat_rep(st):
         result = stat_result()