refactor: move ten command helpers into packages

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 15:47:20 +01:00
1 parent 6d21a98342
commit 19681a3735
22 files changed
+218 -191

No files matched your search

+10
View File
@@ -577,3 +577,13 @@ def refresh_all(
forget_data_dir_index()
return results
def summarize(outcomes: dict[str, bool | None], dry_run: bool) -> str:
"""One closing line: how many entries changed, were current, failed."""
refreshed = sum(1 for o in outcomes.values() if o is True)
current = sum(1 for o in outcomes.values() if o is False)
failed = sum(1 for o in outcomes.values() if o is None)
verb = "would refresh" if dry_run else "refreshed"
line = f"{len(outcomes)} entries: {refreshed} {verb}, {current} up to date"
return f"{line}, {failed} failed" if failed else line
+9
View File
@@ -2,6 +2,7 @@
from __future__ import annotations
import argparse
import io
import re
import struct
@@ -304,3 +305,11 @@ def split_directory(directory: Path, limit: int = ASSET_LIMIT) -> list[Path]:
for path in sorted(Path(directory).glob(f"*{PACK_SUFFIX}")):
published.extend(split_pack(path, limit))
return published
def parse_size(text: str) -> int:
"""A byte count written with an optional K, M or G suffix."""
match = re.fullmatch(r"(\d+)([KMG]?)", text.strip().upper())
if not match:
raise argparse.ArgumentTypeError(f"not a size: {text}")
return int(match[1]) * 1024 ** " KMG".index(match[2] or " ")