commit: eec935ed36a6b8c18576e78bac34942f9f63347a
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Nov 4 04:54:54 2024 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Nov 4 04:54:54 2024 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=eec935ed
Fix deprecated datetime.datetime.utcnow() usage
DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for
removal in a future version. Use timezone-aware objects to represent datetimes
in UTC: datetime.datetime.now(datetime.UTC).
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/repository/storage/hardlink_rcu.py | 8 ++++++--
lib/portage/sync/modules/rsync/rsync.py | 6 +++++-
lib/portage/tests/sync/test_sync_local.py | 2 +-
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/lib/portage/repository/storage/hardlink_rcu.py
b/lib/portage/repository/storage/hardlink_rcu.py
index 6f464c8d05..e40c190853 100644
--- a/lib/portage/repository/storage/hardlink_rcu.py
+++ b/lib/portage/repository/storage/hardlink_rcu.py
@@ -266,7 +266,11 @@ class HardlinkRcuRepoStorage(RepoStorageInterface):
st = os.stat(snap_path)
except OSError:
continue
- snap_timestamp = datetime.datetime.utcfromtimestamp(st.st_mtime)
- if (datetime.datetime.utcnow() - snap_timestamp) < snap_ttl:
+ snap_timestamp = datetime.datetime.fromtimestamp(
+ st.st_mtime, tz=datetime.timezone.utc
+ )
+ if (
+ datetime.datetime.now(datetime.timezone.utc) - snap_timestamp
+ ) < snap_ttl:
continue
await self._check_call(["rm", "-rf", snap_path])
diff --git a/lib/portage/sync/modules/rsync/rsync.py
b/lib/portage/sync/modules/rsync/rsync.py
index e89221ebc9..29fee0a71a 100644
--- a/lib/portage/sync/modules/rsync/rsync.py
+++ b/lib/portage/sync/modules/rsync/rsync.py
@@ -437,7 +437,11 @@ class RsyncSync(NewBase):
raise RuntimeError("Timestamp not found in
Manifest")
if (
self.max_age != 0
- and (datetime.datetime.utcnow() - ts.ts).days >
self.max_age
+ and (
+ datetime.datetime.now(datetime.timezone.utc)
+ - ts.ts.replace(tzinfo=datetime.timezone.utc)
+ ).days
+ > self.max_age
):
out.quiet = False
out.ewarn(
diff --git a/lib/portage/tests/sync/test_sync_local.py
b/lib/portage/tests/sync/test_sync_local.py
index 7e6158ee45..284c117777 100644
--- a/lib/portage/tests/sync/test_sync_local.py
+++ b/lib/portage/tests/sync/test_sync_local.py
@@ -141,7 +141,7 @@ class SyncLocalTestCase(TestCase):
)
)
- bump_timestamp.timestamp = datetime.datetime.utcnow()
+ bump_timestamp.timestamp = datetime.datetime.now(datetime.timezone.utc)
bump_timestamp_cmds = ((homedir, bump_timestamp),)