Signed-off-by: Michał Górny <mgo...@gentoo.org>
---
 bin/chpathtool.py                             |  8 +--
 bin/doins.py                                  | 14 +----
 lib/portage/_emirrordist/FetchTask.py         | 13 ++--
 lib/portage/dbapi/vartree.py                  | 25 ++------
 lib/portage/util/_compare_files.py            | 22 +++----
 .../util/_dyn_libs/PreservedLibsRegistry.py   |  7 +--
 lib/portage/util/movefile.py                  | 60 +++++--------------
 lib/portage/util/mtimedb.py                   |  7 +--
 8 files changed, 39 insertions(+), 117 deletions(-)

diff --git a/bin/chpathtool.py b/bin/chpathtool.py
index fbd18b987..c036046ae 100755
--- a/bin/chpathtool.py
+++ b/bin/chpathtool.py
@@ -128,12 +128,8 @@ def chpath_inplace(filename, is_text_file, old, new):
 
        f.close()
        if modified:
-               if sys.hexversion >= 0x3030000:
-                       orig_mtime = orig_stat.st_mtime_ns
-                       os.utime(filename, ns=(orig_mtime, orig_mtime))
-               else:
-                       orig_mtime = orig_stat[stat.ST_MTIME]
-                       os.utime(filename, (orig_mtime, orig_mtime))
+               orig_mtime = orig_stat.st_mtime_ns
+               os.utime(filename, ns=(orig_mtime, orig_mtime))
        return modified
 
 def chpath_inplace_symlink(filename, st, old, new):
diff --git a/bin/doins.py b/bin/doins.py
index 98dc4f810..a08e3f8c9 100644
--- a/bin/doins.py
+++ b/bin/doins.py
@@ -110,10 +110,6 @@ def _parse_install_options(
        parser.add_argument('-p', '--preserve-timestamps', action='store_true')
        split_options = shlex.split(options)
        namespace, remaining = parser.parse_known_args(split_options)
-       if namespace.preserve_timestamps and sys.version_info < (3, 3):
-               # -p is not supported in this case, since timestamps cannot
-               # be preserved with full precision
-               remaining.append('-p')
        # Because parsing '--mode' option is partially supported. If unknown
        # arg for --mode is passed, namespace.mode is set to None.
        if remaining or namespace.mode is None:
@@ -151,15 +147,7 @@ def _set_timestamps(source_stat, dest):
                source_stat: stat result for the source file.
                dest: path to the dest file.
        """
-       os.utime(dest, (source_stat.st_atime, source_stat.st_mtime))
-
-
-if sys.version_info >= (3, 3):
-       def _set_timestamps_ns(source_stat, dest):
-               os.utime(dest, ns=(source_stat.st_atime_ns, 
source_stat.st_mtime_ns))
-
-       _set_timestamps_ns.__doc__ = _set_timestamps.__doc__
-       _set_timestamps = _set_timestamps_ns
+       os.utime(dest, ns=(source_stat.st_atime_ns, source_stat.st_mtime_ns))
 
 
 class _InsInProcessInstallRunner(object):
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)
-- 
2.27.0


Reply via email to