From 180a8472eaa735646bfb87215ff001b905a5909c Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sun, 20 Mar 2011 02:57:31 -0700 Subject: [PATCH] Get rid of some python syntax not compatible with python 2.4. 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 --- lib/bup/metadata.py | 4 ++-- lib/bup/t/tmetadata.py | 20 ++++++++++++++------ lib/bup/vint.py | 9 +++++++-- lib/bup/xstat.py | 4 ++-- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/bup/metadata.py b/lib/bup/metadata.py index 4751133..5c4a690 100644 --- a/lib/bup/metadata.py +++ b/lib/bup/metadata.py @@ -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) diff --git a/lib/bup/t/tmetadata.py b/lib/bup/t/tmetadata.py index 8660ed9..786a97d 100644 --- a/lib/bup/t/tmetadata.py +++ b/lib/bup/t/tmetadata.py @@ -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) diff --git a/lib/bup/vint.py b/lib/bup/vint.py index 8f7f58a..bca93bd 100644 --- a/lib/bup/vint.py +++ b/lib/bup/vint.py @@ -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): diff --git a/lib/bup/xstat.py b/lib/bup/xstat.py index e2aa153..abc93fe 100644 --- a/lib/bup/xstat.py +++ b/lib/bup/xstat.py @@ -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() -- 2.39.2