1
Fork 0

Print total duration in human time

This commit is contained in:
Jakub Beránek 2023-02-01 17:50:38 +01:00
parent 4bce075149
commit 7bd8fbbd28
No known key found for this signature in database
GPG key ID: 909CD0D26483516B

View file

@ -241,7 +241,7 @@ class Timer:
len(label) for label in list(self.stages.keys()) + [total_duration_label[:-1]]
)) + 1 + 2
table_width = max_label_length + 24
table_width = max_label_length + 23
divider = "-" * table_width
with StringIO() as output:
@ -253,7 +253,7 @@ class Timer:
file=output)
print(file=output)
print(f"{total_duration_label:<{max_label_length}} {total_duration:>12.2f}s",
print(f"{total_duration_label:<{max_label_length}} {humantime(total_duration):>22}",
file=output)
print(divider, file=output, end="")
LOGGER.info(f"Timer results\n{output.getvalue()}")
@ -274,6 +274,21 @@ def change_cwd(dir: Path):
os.chdir(cwd)
def humantime(time_s: int) -> str:
hours = time_s // 3600
time_s = time_s % 3600
minutes = time_s // 60
seconds = time_s % 60
result = ""
if hours > 0:
result += f"{int(hours)}h "
if minutes > 0:
result += f"{int(minutes)}m "
result += f"{round(seconds)}s"
return result
def move_path(src: Path, dst: Path):
LOGGER.info(f"Moving `{src}` to `{dst}`")
shutil.move(src, dst)