diff --git a/rpmbuild/bin/copr-builder b/rpmbuild/bin/copr-builder index 4d0aa984f..31aa09fc5 100755 --- a/rpmbuild/bin/copr-builder +++ b/rpmbuild/bin/copr-builder @@ -5,7 +5,6 @@ Allow users to control their Copr builder instance https://github.com/fedora-copr/debate/tree/main/user-ssh-builders """ -import time import argparse from datetime import datetime, timedelta from contextlib import suppress @@ -72,11 +71,17 @@ class CMDShow: - The user for which the instance was spawned """ def run(self): + """ + Print the information + """ print("Remaining time for the machine: {0}".format(self.remaining_time)) print("Current copr-rpmbuild PID: {0}".format(self.copr_rpmbuild_pid)) @property def copr_rpmbuild_pid(self): + """ + PID of the current/last `copr-rpmbuild` process + """ with suppress(OSError), open(RPMBUILD_PID_PATH, "r") as fp: pid = fp.read() if pid.isdecimal(): @@ -85,6 +90,9 @@ class CMDShow: @property def expiration(self): + """ + The user preference of when the VM should expire + """ try: with open(EXPIRATION_PATH, "r") as fp: timestamp = float(fp.read()) @@ -92,7 +100,6 @@ class CMDShow: except (OSError, ValueError): return None - @property def remaining_time(self): """ @@ -105,6 +112,7 @@ class CMDShow: if delta.total_seconds() < 0: return "expired" + # TODO Print reasonable value when `copr-builder prolong --hours 666` days, hours, minutes, seconds = timedelta_to_dhms(delta) return ("{0} days, {1} hours, {2} minutes, {3} seconds" .format(days, hours, minutes, seconds)) @@ -114,6 +122,7 @@ def cmd_prolong(args): """ 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: fp.write(str(expiration.timestamp())) @@ -131,6 +140,9 @@ def cmd_release(): def get_parser(): + """ + Return argument parser + """ parser = argparse.ArgumentParser( "copr-builder", description="Control a Copr builder", @@ -180,6 +192,9 @@ def get_parser(): def main(): + """ + Main + """ parser = get_parser() args = parser.parse_args() @@ -190,7 +205,6 @@ def main(): cmd_help() elif args.command == "show": - # cmd_show() cmd = CMDShow() cmd.run()