refactor
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"""Utility helpers extracted from the original script."""
|
||||
import time
|
||||
|
||||
|
||||
def shortname(name: str) -> str:
|
||||
return name.split(".")[0]
|
||||
|
||||
|
||||
def dur(sec: int) -> str:
|
||||
sec = int(sec)
|
||||
h = int(sec / 3600)
|
||||
m = int((sec - h * 3600) / 60)
|
||||
s = int((sec - h * 3600) % 60)
|
||||
if h > 0:
|
||||
return "%d:%02d:%02d" % (h, m, s)
|
||||
if m > 0:
|
||||
return "%d:%02d" % (m, s)
|
||||
return "0:%02d" % s
|
||||
|
||||
|
||||
def initlog(logfile: str):
|
||||
"""Open logfile for appending; fall back to creating it or returning stderr.
|
||||
|
||||
This mirrors the original behaviour from the monolithic script.
|
||||
"""
|
||||
try:
|
||||
return open(logfile, "a+")
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
return open(logfile, "w")
|
||||
except Exception as e:
|
||||
import sys
|
||||
|
||||
print(f"cannot open logfile {logfile}, using STDERR: {e}")
|
||||
return sys.stderr
|
||||
Reference in New Issue
Block a user