Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Event media builders: an unknown --only is refused (Fixes #1465) (#1757)

Eyal Golan52f9292263f1
diff --git a/tools/encode_event_videos.py b/tools/encode_event_videos.py
index 332621741..729a4e5ee 100644
--- a/tools/encode_event_videos.py
+++ b/tools/encode_event_videos.py
@@ -138,9 +138,14 @@ def main(argv: list[str] | None = None) -> int:
if a.steadiest:
start, numbers = steadiest(a.steadiest, decimate=a.decimate)
print(json.dumps({"start_frame": start, "start_s": round(start / FPS, 3), "frames": int(round(3.5 * FPS)), **numbers})); return 0
+ all_rows = load_rows()
+ known = {Path(r["file"]).stem for r in all_rows}
+ unknown = [o for o in dict.fromkeys(a.only) if o not in known]
+ if unknown: # before ffmpeg or any source is looked at, so a typo cannot pass for "nothing to build"
+ print(f"UNKNOWN --only {', '.join(unknown)} (not a clip's file stem in {MAPPING.name})"); return 2
if shutil.which("ffmpeg") is None or shutil.which("ffprobe") is None:
print("ffmpeg and ffprobe are needed"); return 2
- rows = [r for r in load_rows() if not a.only or Path(r["file"]).stem in a.only]
+ rows = [r for r in all_rows if not a.only or Path(r["file"]).stem in a.only]
for r in rows: # check every source before writing anything
src = a.root / r["source"]
if not src.is_file():
diff --git a/tools/event_images.py b/tools/event_images.py
index f171e43d6..01d0f501f 100644
--- a/tools/event_images.py
+++ b/tools/event_images.py
@@ -114,7 +114,12 @@ def main(argv: list[str] | None = None) -> int:
a = ap.parse_args(argv)
if not isolated():
print("run with python -I: the originals are untrusted downloads (see the module docstring)"); return 2
- rows = [r for r in load_rows() if not a.only or r["event"] in a.only]
+ all_rows = load_rows()
+ known = {r["event"] for r in all_rows}
+ unknown = [o for o in dict.fromkeys(a.only) if o not in known]
+ if unknown: # before any original is looked at, so a typo cannot pass for "nothing to build"
+ print(f"UNKNOWN --only {', '.join(unknown)} (not an event in {MAPPING.name})"); return 2
+ rows = [r for r in all_rows if not a.only or r["event"] in a.only]
for r in rows: # check every download before reading or writing anything, so a bad row writes nothing
src = a.originals / f"{r['event']}.jpg"
if not src.is_file():
diff --git a/tools/tests/test_encode_event_videos.py b/tools/tests/test_encode_event_videos.py
index adf516f53..007664c6b 100644
--- a/tools/tests/test_encode_event_videos.py
+++ b/tools/tests/test_encode_event_videos.py
@@ -114,6 +114,24 @@ def test_only_selects_a_loop_or_an_outcome_by_its_file(monkeypatch, tmp_path, ca
assert "y.mp4" in capsys.readouterr().out, "only the outcome row is looked at"
[email protected]("only", [["typo"], ["e", "typo", "e-outcome", "other_typo"]])
+def test_an_unknown_only_is_refused_before_any_source_is_looked_at(monkeypatch, tmp_path, capsys, only):
+ # #1465: an --only that matches no row used to build nothing and exit 0. The checkout has no promo/ at all, so a
+ # refusal that names only the unknown values proves no source was looked at; ffmpeg is not needed either.
+ rows = [{"event": "e", "file": "e.mp4", "source": "promo/x.mp4", "source_sha256": "0" * 64},
+ {"event": "e", "option": "o", "file": "e-outcome.mp4", "source": "promo/y.mp4", "source_sha256": "0" * 64}]
+ monkeypatch.setattr(ev, "load_rows", lambda mapping=ev.MAPPING: rows)
+ monkeypatch.setattr(ev.shutil, "which", lambda name: None)
+ args = ["--root", str(tmp_path), "--out", str(tmp_path / "out")]
+ for o in only:
+ args += ["--only", o]
+ assert ev.main(args) == 2
+ unknown = [o for o in only if o not in ("e", "e-outcome")]
+ assert capsys.readouterr().out.splitlines() == [
+ f"UNKNOWN --only {', '.join(unknown)} (not a clip's file stem in {ev.MAPPING.name})"]
+ assert not (tmp_path / "out").exists()
+
+
def test_a_source_with_the_wrong_sha256_is_refused(tmp_path, capsys, monkeypatch):
row = dict(ev.load_rows()[0])
(tmp_path / "promo").mkdir()
diff --git a/tools/tests/test_event_images.py b/tools/tests/test_event_images.py
index ffd653656..c3d7b81a6 100644
--- a/tools/tests/test_event_images.py
+++ b/tools/tests/test_event_images.py
@@ -111,6 +111,23 @@ def test_every_row_has_a_shipped_file_and_a_crop():
[email protected]("only", [["typo"], ["altalena", "typo", "other_typo"]])
+def test_an_unknown_only_is_refused_before_any_original_is_looked_at(tmp_path, capsys, as_isolated, only):
+ # #1465: an --only that matches no row used to build nothing and exit 0. The originals folder does not even exist,
+ # so a refusal that names only the unknown values proves no source was looked at.
+ assert "altalena" in {r["event"] for r in ei.load_rows()}
+ out = tmp_path / "out"
+ out.mkdir()
+ args = ["--originals", str(tmp_path / "no-originals"), "--out", str(out)]
+ for o in only:
+ args += ["--only", o]
+ assert ei.main(args) == 2
+ printed = capsys.readouterr().out
+ unknown = [o for o in only if o != "altalena"]
+ assert printed.splitlines() == [f"UNKNOWN --only {', '.join(unknown)} (not an event in {ei.MAPPING.name})"]
+ assert list(out.iterdir()) == []
+
+
ISOLATED_IMPORT = ("import importlib.util, sys; s = importlib.util.spec_from_file_location('m', sys.argv[1]); "
"s.loader.exec_module(importlib.util.module_from_spec(s))")