Skip to content

Commit 88dcc37

Browse files
committed
improved logging
1 parent ab3f7d3 commit 88dcc37

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

scripts/hooks/update/50.workspace.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
from concurrent.futures import ThreadPoolExecutor, as_completed
1616
from pathlib import Path
1717
from typing import List
18-
18+
import time
19+
import shutil
1920
from tuda_workspace_scripts.print import *
2021
from tuda_workspace_scripts.workspace import get_workspace_root
2122

@@ -201,8 +202,25 @@ def update(**_) -> bool:
201202
# ----------------------- parallel phase ------------------------------- #
202203
total = len(repos)
203204

205+
_BAR_START = time.monotonic()
206+
204207
def _progress(idx: int):
205-
print(f"\rUpdating {total} repositories… {idx}/{total}", end="", flush=True)
208+
"""Draw a simple progress bar that lives on one terminal line."""
209+
cols = shutil.get_terminal_size((80, 20)).columns
210+
bar_len = max(10, min(50, cols - 30)) # leave space for counters & percent
211+
filled = int(bar_len * idx / total)
212+
bar = (
213+
("=" * filled + ">" + " " * (bar_len - filled - 1))
214+
if idx < total
215+
else "=" * bar_len
216+
)
217+
percent = (idx * 100) // total
218+
elapsed = time.monotonic() - _BAR_START
219+
print(
220+
f"\r[{bar}] {percent:3d}% {idx}/{total} | {elapsed:4.0f}s",
221+
end="",
222+
flush=True,
223+
)
206224

207225
results: List[RepoResult] = []
208226
done = 0

0 commit comments

Comments
 (0)