Skip to content

Commit

Permalink
utcnow() is deprecated
Browse files Browse the repository at this point in the history
Addressing:
/usr/bin/copr-backend-analyze-results:153: 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).
  timestamp = datetime.utcnow().isoformat()
  • Loading branch information
xsuchy authored and praiskup committed Jun 5, 2024
1 parent b841d1c commit 24becb0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 23 deletions.
22 changes: 2 additions & 20 deletions backend/copr_backend/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@

import traceback

from datetime import datetime
import datetime
from threading import Thread

import subprocess

import pytz

import munch
from munch import Munch

Expand Down Expand Up @@ -452,21 +450,6 @@ def uses_devel_repo(front_url, username, projectname, project=None):
return bool(project.get("devel_mode", False))


# def log(lf, msg, quiet=None):
# if lf:
# now = datetime.datetime.utcnow().isoformat()
# try:
# with open(lf, "a") as lfh:
# fcntl.flock(lfh, fcntl.LOCK_EX)
# lfh.write(str(now) + ":" + msg + "\n")
# fcntl.flock(lfh, fcntl.LOCK_UN)
# except (IOError, OSError) as e:
# sys.stderr.write(
# "Could not write to logfile {0} - {1}\n".format(lf, str(e)))
# if not quiet:
# print(msg)
#

def register_build_result(opts=None, failed=False):
"""
Remember fails to redis.
Expand Down Expand Up @@ -581,8 +564,7 @@ def utc_now():
"""
:return datetime.datetime: Current utc datetime with specified timezone
"""
u = datetime.utcnow()
u = u.replace(tzinfo=pytz.utc)
u = datetime.datetime.now(datetime.UTC)
return u


Expand Down
4 changes: 2 additions & 2 deletions backend/run/copr-backend-analyze-results
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Analyze the Copr Backend resultdir storage usage.
"""

import argparse
from datetime import datetime
import datetime
import json
import os
import shlex
Expand Down Expand Up @@ -150,7 +150,7 @@ def _main(arguments):
except FileExistsError:
pass

timestamp = datetime.utcnow().isoformat()
timestamp = datetime.datetime.now(datetime.UTC).isoformat()

full_du_log = os.path.join(
datadir,
Expand Down
2 changes: 1 addition & 1 deletion backend/run/copr-repo
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def delete_builds(opts):
with open(prune_log, "a+") as fd:
fd.write("{} pruned on {}, by PID {}\n".format(
rpm,
datetime.datetime.utcnow(),
datetime.datetime.now(datetime.UTC),
os.getpid(),
))
except OSError:
Expand Down

0 comments on commit 24becb0

Please sign in to comment.