diff --git a/scripts/bundled_only.py b/scripts/bundled_only.py index fea5376f7..3dfe2f1a6 100644 --- a/scripts/bundled_only.py +++ b/scripts/bundled_only.py @@ -19,6 +19,7 @@ import json from pathlib import Path from core.hashing import compute_hashes +from core.sizes import size_text from resolve.directories import expand_directory_entries from model.registry import list_registered_platforms from model.database import load_database @@ -132,7 +133,7 @@ def main() -> int: print(f"{row['path']} ({', '.join(row['emulators'])})") total = sum(row["size"] for row in rows) print(f"{len(rows)} collected files only an emulator install provides, " - f"{total / 1024**2:.1f} MB") + f"{size_text(total)}") return 1 if args.strict and rows else 0 diff --git a/scripts/dedup.py b/scripts/dedup.py index c6570ed2d..bc8d13db7 100644 --- a/scripts/dedup.py +++ b/scripts/dedup.py @@ -29,6 +29,7 @@ from pathlib import Path sys.path.insert(0, os.path.dirname(__file__)) from core.hashing import compute_hashes +from core.sizes import size_text from core.cli import add_repo_inputs, require_directory from core.artifacts import write_text_atomic from model.nodedup import in_nodedup_dir @@ -298,7 +299,7 @@ def deduplicate(bios_dir: str, dry_run: bool = False) -> dict: prefix = "Would remove" if dry_run else "Removed" print(f"\n{prefix}: {total_removed} files") print( - f"Space {'to save' if dry_run else 'saved'}: {total_saved / 1024 / 1024:.1f} MB" + f"Space {'to save' if dry_run else 'saved'}: {size_text(total_saved)}" ) if not dry_run and empty_cleaned: print(f"Cleaned {empty_cleaned} empty directories") diff --git a/scripts/download.py b/scripts/download.py index e12df9e17..5961a77ec 100644 --- a/scripts/download.py +++ b/scripts/download.py @@ -33,6 +33,7 @@ from pathlib import Path sys.path.insert(0, os.path.dirname(__file__)) from core.hashing import compute_hashes, parse_sha256sums from core.paths import REPO_ROOT +from core.sizes import size_text from core.upstream import forge_headers from core.ziptools import safe_extract_zip from packs.parts import part_of @@ -239,7 +240,7 @@ def _progress_line(label: str, done: int, total: int, columns: int) -> str: copy of itself on every redraw, since \\r goes back one row only. The bar shrinks first, then goes.""" pct = done * 100 // total - figures = f" {pct}% ({done / 1e6:,.0f}/{total / 1e6:,.0f} MB)" + figures = f" {pct}% ({size_text(done)}/{size_text(total)})" room = min(50, columns - 1 - len(f" {label}[]") - len(figures)) if room < 10: return f" {label}{figures.strip()}"[: columns - 1] @@ -333,7 +334,7 @@ def show_info(platform: str, release: dict) -> None: print(f" Platform: {pack.platform}") print(f" File: {pack.name}") print(f" Parts: {len(pack.parts)} part{'s' if len(pack.parts) > 1 else ''}") - print(f" Size: {pack.size:,} bytes ({pack.size / (1024 * 1024):.1f} MB)") + print(f" Size: {pack.size:,} bytes ({size_text(pack.size)})") for part in pack.parts: print(f" {part['name']} ({part.get('size', 0):,} bytes)") diff --git a/scripts/release/assets.py b/scripts/release/assets.py index 03342322d..258894e77 100644 --- a/scripts/release/assets.py +++ b/scripts/release/assets.py @@ -218,7 +218,7 @@ def render_notes( out += ["| File | Description | Size | SHA1 |", "|------|-------------|-----:|------|"] out += [line for _, line in sorted(rows[section])] total = sum(assets.values()) - out += ["", f"{len(assets)} files, {total / 1073741824:.1f} GB total. Verify a download with `sha1sum `.", ""] + out += ["", f"{len(assets)} files, {size_text(total)} total. Verify a download with `sha1sum `.", ""] return "\n".join(out) diff --git a/tests/test_download.py b/tests/test_download.py index 7db14c3b9..7844ab98e 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -288,6 +288,14 @@ class TestProgressLineWidth(unittest.TestCase): self.assertLess(len(line), columns) self.assertIn("%", line) + def test_the_figures_read_like_the_site(self): + """The bar counted decimal megabytes (8,127 MB) where --info and the + site gave the same pack as 7.6 GB.""" + from download import _progress_line + + line = _progress_line("", 1024**3, 8_127_352_876, 200) + self.assertTrue(line.endswith(" 13% (1.0 GB/7.6 GB)"), line) + class TestStagingIsolation(unittest.TestCase): """Two downloads into one BIOS folder must not share a staging directory."""