Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostyX committed Dec 3, 2023
1 parent 9087619 commit f964c9b
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions rpmbuild/bin/copr-builder
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,27 @@ class CMDShow:
return pid
return None

@property
def uptime_seconds(self):
with open("/proc/uptime", "r") as f:
return float(f.readline().split()[0])

@property
def expiration(self):
# TODO We are implementing the same thing on backend, move it to common
try:
with open(EXPIRATION_PATH, "r") as fp:
timestamp = float(fp.read())
return datetime.fromtimestamp(timestamp)
except (OSError, ValueError):
boot = datetime.now() - timedelta(seconds=self.uptime_seconds)
return boot + timedelta(seconds=DEFAULT_EXPIRATION)
return None


@property
def remaining_time(self):
"""
Human friendly representation of remaining time for the VM
"""
# TODO We are implementing the same thing on backend, move it to common
if not self.expiration:
return "unknown"

delta = self.expiration - datetime.now()
if delta.total_seconds() < 0:
return "Expired"
return "expired"

days, hours, minutes, seconds = timedelta_to_dhms(delta)
return ("{0} days, {1} hours, {2} minutes, {3} seconds"
Expand Down

0 comments on commit f964c9b

Please sign in to comment.