time output formats and right aligned numeric cols

This commit is contained in:
2026-08-07 15:22:45 +02:00
parent 7a6188978a
commit c4cf8fa1e0
+20 -3
View File
@@ -49,7 +49,7 @@ import sys
import signal
import tempfile
import time
from datetime import datetime
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
from collections import defaultdict
from dataclasses import dataclass, field, fields, asdict
@@ -237,6 +237,7 @@ ALIASES = {
}
NUMERIC_COLUMNS = {
"Nr.",
"CPUs",
"NTasks",
"Nodes",
@@ -251,6 +252,7 @@ NUMERIC_COLUMNS = {
"MaxRSS_max",
"Mem_Eff",
"Time_Eff",
"Walltime",
"Walltime_max",
"waste_CPU",
"waste_Mem",
@@ -633,6 +635,17 @@ def format_seconds(seconds: int | float | None) -> str:
return f"{days}-{hours:02d}:{minutes:02d}:{sec:02d}"
return f"{hours:02d}:{minutes:02d}:{sec:02d}"
def format_hours(hours: float | None) -> str:
"""Return string representation in format hours:seconds"""
if hours is None:
return "Unknown"
td = timedelta(hours)
sraw = int(td.total_seconds())
hr = sraw // 3600
mn = (sraw % 3600) // 60
sc = sraw % 60
return f"{hr}:{round(mn,0)}:{sc}"
def parse_size_to_bytes(value: str) -> int | None:
"""Parse Slurm memory size fields such as 1024K, 2000M, 8Gn, 4Gc, 1.5T."""
@@ -1348,7 +1361,7 @@ def format_value(value: Any, column: str | None = None) -> str:
return f"{value:.2f}G"
if column in ["ReqWalltime", "Walltime", "Walltime_max",
"Elig_Qtime", "Planned_Time"]:
return f"{value:.2f}h"
return format_hours(value)
if column in ["Start"]:
return datetime.fromtimestamp(value).strftime("%Y-%m-%dT%H:%M:%S")
@@ -1376,7 +1389,11 @@ def print_table(rows: list[OutputRow], columns: list[str], sdev: bool) -> None:
print(" ".join(col.ljust(widths[col]) for col in columns))
print(" ".join("-" * widths[col] for col in columns))
for d in dicts:
print(" ".join(format_value(d.get(col), col).ljust(widths[col]) for col in columns))
print(" ".join(
format_value(d.get(col), col).rjust(widths[col])
if col in NUMERIC_COLUMNS
else format_value(d.get(col), col).ljust(widths[col])
for col in columns))
def columns_from_fmtstr(fmt: str) -> list[str]: