Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostyX committed Dec 15, 2023
1 parent 4855868 commit 90188de
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions rpmbuild/bin/copr-builder
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ https://github.com/fedora-copr/debate/tree/main/user-ssh-builders
import argparse
from datetime import datetime, timedelta
from contextlib import suppress
from copr_rpmbuild.helpers import read_config
from copr_common.helpers import timedelta_to_dhms
from copr_rpmbuild.helpers import read_config


EXPIRATION_PATH = "/run/copr-builder-expiration"
Expand Down Expand Up @@ -86,7 +86,7 @@ class CMDShow:
PID of the current/last `copr-rpmbuild` process
"""
path = self.config.get("main", "pidfile")
with suppress(OSError), open(path, "r") as fp:
with suppress(OSError), open(path, "r", encoding="utf-8") as fp:
pid = fp.read()
if pid.isdecimal():
return pid
Expand All @@ -98,7 +98,7 @@ class CMDShow:
The user preference of when the VM should expire
"""
try:
with open(EXPIRATION_PATH, "r") as fp:
with open(EXPIRATION_PATH, "r", encoding="utf-8") as fp:
timestamp = float(fp.read())
return datetime.fromtimestamp(timestamp)
except (OSError, ValueError):
Expand All @@ -122,13 +122,13 @@ class CMDShow:
.format(days, hours, minutes, seconds))


def cmd_prolong(args):
def cmd_prolong(args, config):
"""
Prolong the VM expiration time
"""
# TODO Validate against `copr-builder prolong --hours 666`
expiration = CMDShow().expiration + timedelta(hours=args.hours)
with open(EXPIRATION_PATH, "w+") as fp:
expiration = CMDShow(config).expiration + timedelta(hours=args.hours)
with open(EXPIRATION_PATH, "w+", encoding="utf-8") as fp:
fp.write(str(expiration.timestamp()))
print("Prolonged to {0}".format(expiration))

Expand All @@ -138,7 +138,7 @@ def cmd_release():
Mark this VM as expired
"""
expiration = datetime.now() - timedelta(minutes=1)
with open(EXPIRATION_PATH, "w+") as fp:
with open(EXPIRATION_PATH, "w+", encoding="utf-8") as fp:
fp.write(str(expiration.timestamp()))
print("Releasing this VM, it will be shut-down soon")

Expand Down Expand Up @@ -214,7 +214,7 @@ def main():
cmd.run()

elif args.command == "prolong":
cmd_prolong(args)
cmd_prolong(args, config)

elif args.command == "release":
cmd_release()
Expand Down

0 comments on commit 90188de

Please sign in to comment.