diff options
author | Michał Górny <mgorny@gentoo.org> | 2020-07-17 06:34:00 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2020-07-17 06:39:07 +0200 |
commit | 55a6bfdd9d3e2b8d0a59f5579de962fb82dde8ca (patch) | |
tree | 6cddd32d478764b7736e62c6c455da956966ee67 /lib/portage | |
parent | Remove support code for Python < 3.2 (diff) | |
download | portage-55a6bfdd9d3e2b8d0a59f5579de962fb82dde8ca.tar.gz portage-55a6bfdd9d3e2b8d0a59f5579de962fb82dde8ca.tar.bz2 portage-55a6bfdd9d3e2b8d0a59f5579de962fb82dde8ca.zip |
Remove support code for Python < 3.3
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'lib/portage')
-rw-r--r-- | lib/portage/_emirrordist/FetchTask.py | 13 | ||||
-rw-r--r-- | lib/portage/dbapi/vartree.py | 25 | ||||
-rw-r--r-- | lib/portage/util/_compare_files.py | 22 | ||||
-rw-r--r-- | lib/portage/util/_dyn_libs/PreservedLibsRegistry.py | 7 | ||||
-rw-r--r-- | lib/portage/util/movefile.py | 60 | ||||
-rw-r--r-- | lib/portage/util/mtimedb.py | 7 |
6 files changed, 36 insertions, 98 deletions
diff --git a/lib/portage/_emirrordist/FetchTask.py b/lib/portage/_emirrordist/FetchTask.py index 322de79ba..a1ba58822 100644 --- a/lib/portage/_emirrordist/FetchTask.py +++ b/lib/portage/_emirrordist/FetchTask.py @@ -1,4 +1,4 @@ -# Copyright 2013-2019 Gentoo Authors +# Copyright 2013-2020 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 from __future__ import division @@ -385,14 +385,9 @@ class FetchTask(CompositeTask): # Apply the timestamp from the source file, but # just rely on umask for permissions. try: - if sys.hexversion >= 0x3030000: - os.utime(copier.dest_path, - ns=(self._current_stat.st_mtime_ns, - self._current_stat.st_mtime_ns)) - else: - os.utime(copier.dest_path, - (self._current_stat[stat.ST_MTIME], - self._current_stat[stat.ST_MTIME])) + os.utime(copier.dest_path, + ns=(self._current_stat.st_mtime_ns, + self._current_stat.st_mtime_ns)) except OSError as e: msg = "%s %s utime failed unexpectedly: %s" % \ (self.distfile, current_mirror.name, e) diff --git a/lib/portage/dbapi/vartree.py b/lib/portage/dbapi/vartree.py index abb0a9308..2e29b25e5 100644 --- a/lib/portage/dbapi/vartree.py +++ b/lib/portage/dbapi/vartree.py @@ -435,10 +435,7 @@ class vardbapi(dbapi): if mysplit[0] == '*': mysplit[0] = mysplit[0][1:] try: - if sys.hexversion >= 0x3030000: - mystat = os.stat(self.getpath(mysplit[0])).st_mtime_ns - else: - mystat = os.stat(self.getpath(mysplit[0])).st_mtime + mystat = os.stat(self.getpath(mysplit[0])).st_mtime_ns except OSError: mystat = 0 if use_cache and mycp in self.cpcache: @@ -586,10 +583,7 @@ class vardbapi(dbapi): return list(self._iter_match(mydep, self.cp_list(mydep.cp, use_cache=use_cache))) try: - if sys.hexversion >= 0x3030000: - curmtime = os.stat(os.path.join(self._eroot, VDB_PATH, mycat)).st_mtime_ns - else: - curmtime = os.stat(os.path.join(self._eroot, VDB_PATH, mycat)).st_mtime + curmtime = os.stat(os.path.join(self._eroot, VDB_PATH, mycat)).st_mtime_ns except (IOError, OSError): curmtime=0 @@ -4921,10 +4915,7 @@ class dblink(object): mymd5 = None myto = None - if sys.hexversion >= 0x3030000: - mymtime = mystat.st_mtime_ns - else: - mymtime = mystat[stat.ST_MTIME] + mymtime = mystat.st_mtime_ns if stat.S_ISREG(mymode): mymd5 = perform_md5(mysrc, calc_prelink=calc_prelink) @@ -5067,10 +5058,7 @@ class dblink(object): % (relative_path, myabsto)]) showMessage("%s %s -> %s\n" % (zing, mydest, myto)) - if sys.hexversion >= 0x3030000: - outfile.write("sym "+myrealdest+" -> "+myto+" "+str(mymtime // 1000000000)+"\n") - else: - outfile.write("sym "+myrealdest+" -> "+myto+" "+str(mymtime)+"\n") + outfile.write("sym "+myrealdest+" -> "+myto+" "+str(mymtime // 1000000000)+"\n") else: showMessage(_("!!! Failed to move file.\n"), level=logging.ERROR, noiselevel=-1) @@ -5219,10 +5207,7 @@ class dblink(object): pass if mymtime != None: - if sys.hexversion >= 0x3030000: - outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime // 1000000000)+"\n") - else: - outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime)+"\n") + outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime // 1000000000)+"\n") showMessage("%s %s\n" % (zing,mydest)) else: # we are merging a fifo or device node diff --git a/lib/portage/util/_compare_files.py b/lib/portage/util/_compare_files.py index bd993e501..c3223d956 100644 --- a/lib/portage/util/_compare_files.py +++ b/lib/portage/util/_compare_files.py @@ -1,4 +1,4 @@ -# Copyright 2019 Gentoo Authors +# Copyright 2019-2020 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 __all__ = ["compare_files"] @@ -49,20 +49,12 @@ def compare_files(file1, file2, skipped_types=()): if "xattr" not in skipped_types and sorted(xattr.get_all(file1, nofollow=True)) != sorted(xattr.get_all(file2, nofollow=True)): differences.append("xattr") - if sys.hexversion >= 0x3030000: - if "atime" not in skipped_types and file1_stat.st_atime_ns != file2_stat.st_atime_ns: - differences.append("atime") - if "mtime" not in skipped_types and file1_stat.st_mtime_ns != file2_stat.st_mtime_ns: - differences.append("mtime") - if "ctime" not in skipped_types and file1_stat.st_ctime_ns != file2_stat.st_ctime_ns: - differences.append("ctime") - else: - if "atime" not in skipped_types and file1_stat.st_atime != file2_stat.st_atime: - differences.append("atime") - if "mtime" not in skipped_types and file1_stat.st_mtime != file2_stat.st_mtime: - differences.append("mtime") - if "ctime" not in skipped_types and file1_stat.st_ctime != file2_stat.st_ctime: - differences.append("ctime") + if "atime" not in skipped_types and file1_stat.st_atime_ns != file2_stat.st_atime_ns: + differences.append("atime") + if "mtime" not in skipped_types and file1_stat.st_mtime_ns != file2_stat.st_mtime_ns: + differences.append("mtime") + if "ctime" not in skipped_types and file1_stat.st_ctime_ns != file2_stat.st_ctime_ns: + differences.append("ctime") if "type" in differences: pass diff --git a/lib/portage/util/_dyn_libs/PreservedLibsRegistry.py b/lib/portage/util/_dyn_libs/PreservedLibsRegistry.py index 7909f258c..b82b11cb5 100644 --- a/lib/portage/util/_dyn_libs/PreservedLibsRegistry.py +++ b/lib/portage/util/_dyn_libs/PreservedLibsRegistry.py @@ -34,12 +34,9 @@ class PreservedLibsRegistry(object): _json_write_opts = { "ensure_ascii": False, - "indent": "\t", - "sort_keys": True + "indent": 4, + "sort_keys": True, } - if sys.hexversion < 0x30200F0: - # indent only supports int number of spaces - _json_write_opts["indent"] = 4 def __init__(self, root, filename): """ diff --git a/lib/portage/util/movefile.py b/lib/portage/util/movefile.py index e6180e9f1..e7be8792c 100644 --- a/lib/portage/util/movefile.py +++ b/lib/portage/util/movefile.py @@ -1,4 +1,4 @@ -# Copyright 2010-2018 Gentoo Foundation +# Copyright 2010-2020 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 from __future__ import absolute_import @@ -188,18 +188,13 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, except OSError: pass - if sys.hexversion >= 0x3030000: - try: - os.utime(dest, ns=(sstat.st_mtime_ns, sstat.st_mtime_ns), follow_symlinks=False) - except NotImplementedError: - # utimensat() and lutimes() missing in libc. - return os.stat(dest, follow_symlinks=False).st_mtime_ns - else: - return sstat.st_mtime_ns + try: + os.utime(dest, ns=(sstat.st_mtime_ns, sstat.st_mtime_ns), follow_symlinks=False) + except NotImplementedError: + # utimensat() and lutimes() missing in libc. + return os.stat(dest, follow_symlinks=False).st_mtime_ns else: - # utime() in Python <3.3 only works on the target of a symlink, so it's not - # possible to preserve mtime on symlinks. - return os.lstat(dest)[stat.ST_MTIME] + return sstat.st_mtime_ns except SystemExit as e: raise except Exception as e: @@ -312,49 +307,26 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, # if the nanosecond part of the timestamp is 999999881 ns or greater. try: if hardlinked: - if sys.hexversion >= 0x3030000: - newmtime = os.stat(dest).st_mtime_ns - else: - newmtime = os.stat(dest)[stat.ST_MTIME] + newmtime = os.stat(dest).st_mtime_ns else: # Note: It is not possible to preserve nanosecond precision # (supported in POSIX.1-2008 via utimensat) with the IEEE 754 # double precision float which only has a 53 bit significand. if newmtime is not None: - if sys.hexversion >= 0x3030000: - os.utime(dest, ns=(newmtime, newmtime)) - else: - os.utime(dest, (newmtime, newmtime)) + os.utime(dest, ns=(newmtime, newmtime)) else: - if sys.hexversion >= 0x3030000: - newmtime = sstat.st_mtime_ns - else: - newmtime = sstat[stat.ST_MTIME] + newmtime = sstat.st_mtime_ns if renamefailed: - if sys.hexversion >= 0x3030000: - # If rename succeeded then timestamps are automatically - # preserved with complete precision because the source - # and destination inodes are the same. Otherwise, manually - # update timestamps with nanosecond precision. - os.utime(dest, ns=(newmtime, newmtime)) - else: - # If rename succeeded then timestamps are automatically - # preserved with complete precision because the source - # and destination inodes are the same. Otherwise, round - # down to the nearest whole second since python's float - # st_mtime cannot be used to preserve the st_mtim.tv_nsec - # field with complete precision. Note that we have to use - # stat_obj[stat.ST_MTIME] here because the float - # stat_obj.st_mtime rounds *up* sometimes. - os.utime(dest, (newmtime, newmtime)) + # If rename succeeded then timestamps are automatically + # preserved with complete precision because the source + # and destination inodes are the same. Otherwise, manually + # update timestamps with nanosecond precision. + os.utime(dest, ns=(newmtime, newmtime)) except OSError: # The utime can fail here with EPERM even though the move succeeded. # Instead of failing, use stat to return the mtime if possible. try: - if sys.hexversion >= 0x3030000: - newmtime = os.stat(dest).st_mtime_ns - else: - newmtime = os.stat(dest)[stat.ST_MTIME] + newmtime = os.stat(dest).st_mtime_ns except OSError as e: writemsg(_("!!! Failed to stat in movefile()\n"), noiselevel=-1) writemsg("!!! %s\n" % dest, noiselevel=-1) diff --git a/lib/portage/util/mtimedb.py b/lib/portage/util/mtimedb.py index 30922a901..e1605310e 100644 --- a/lib/portage/util/mtimedb.py +++ b/lib/portage/util/mtimedb.py @@ -1,4 +1,4 @@ -# Copyright 2010-2012 Gentoo Foundation +# Copyright 2010-2020 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 __all__ = ['MtimeDB'] @@ -29,12 +29,9 @@ class MtimeDB(dict): _json_write_opts = { "ensure_ascii": False, - "indent": "\t", + "indent": 4, "sort_keys": True } - if sys.hexversion < 0x30200F0: - # indent only supports int number of spaces - _json_write_opts["indent"] = 4 def __init__(self, filename): dict.__init__(self) |