diff options
author | Zac Medico <zmedico@gentoo.org> | 2024-11-03 20:54:54 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2024-11-03 20:54:54 -0800 |
commit | eec935ed36a6b8c18576e78bac34942f9f63347a (patch) | |
tree | 03e6c3350b0d3d0ca84916d554f8b6584987c25a | |
parent | github: test python3.14 + spawn (diff) | |
download | portage-eec935ed36a6b8c18576e78bac34942f9f63347a.tar.gz portage-eec935ed36a6b8c18576e78bac34942f9f63347a.tar.bz2 portage-eec935ed36a6b8c18576e78bac34942f9f63347a.zip |
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@gentoo.org>
-rw-r--r-- | lib/portage/repository/storage/hardlink_rcu.py | 8 | ||||
-rw-r--r-- | lib/portage/sync/modules/rsync/rsync.py | 6 | ||||
-rw-r--r-- | 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 6f464c8d0..e40c19085 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 e89221ebc..29fee0a71 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 7e6158ee4..284c11777 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),) |