From 30e5431437786154491cbef7da4b9a3a6753d5d5 Mon Sep 17 00:00:00 2001 From: Rafael Date: Sun, 22 Nov 2026 03:53:27 -0300 Subject: [PATCH 1/2] ttpf_mips: scan searches any pool folder and rejects a path with no pool `scan` only looked for pools under /data/ttdb and /pack/*/data/ttdb, so pointing it at data/ttdb itself, one of its folders or pack/ found nothing, and a mistyped path did the same: it printed an all-zero summary and exited 0. A folder that holds no pool at those game-root places is now searched recursively for .ttpf, and a path that still yields no pool is an ERROR line naming it (no such file or folder / no .ttpf pool in it) with exit code 2. Real data (counts only), pools found on my 1.0.2.1 copy, main -> this change: game root 57 -> 57 (same list), pack/story000 3 -> 3 (same list), data/ttdb 0 -> 46, data/ttdb/peds 0 -> 9, pack 0 -> 11; a mistyped dat/ttdb now exits 2 instead of 0. Tests: test_scan_finds_pools_below_any_folder_and_rejects_paths_without_one (main: 0 pools for data/ttdb). Co-Authored-By: Claude Opus 5.5 --- tests/test_ttpf_mips.py | 24 ++++++++++++++++++++++++ tools/ttpf_mips.py | 13 +++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/tests/test_ttpf_mips.py b/tests/test_ttpf_mips.py index 70efde52c..8a5522b5a 100644 --- a/tests/test_ttpf_mips.py +++ b/tests/test_ttpf_mips.py @@ -749,6 +749,30 @@ class SyntheticPoolTest(unittest.TestCase): self.assertEqual((result["after_full"], result["after_partial"], result["after_skip"]), (1, 0, 0)) + def test_scan_finds_pools_below_any_folder_and_rejects_paths_without_one(self): + """A pool folder other than the game root (data/ttdb itself, one pack) is searched recursively; a + path with no pool is an error, not an all-zero scan with exit code 0.""" + import io + from contextlib import redirect_stderr, redirect_stdout + ttdb = os.path.join(self.tmp.name, "game", "data", "ttdb", "props") + os.makedirs(ttdb) + build_pool(os.path.join(ttdb, "a.ttpf")) + out = os.path.join(self.tmp.name, "scan.json") + for folder in (os.path.join(self.tmp.name, "game"), os.path.dirname(ttdb), ttdb): + with redirect_stdout(io.StringIO()): + self.assertEqual(ttpf.main(["scan", folder, "--json", out]), 0, folder) + with open(out, encoding="utf-8") as f: + self.assertEqual(json.load(f)["total"]["pools"], 1, folder) + empty = os.path.join(self.tmp.name, "empty") + os.mkdir(empty) + for bad, why in ((os.path.join(self.tmp.name, "missing"), "no such file or folder"), + (empty, "no .ttpf pool in it")): + err = io.StringIO() + with redirect_stdout(io.StringIO()), redirect_stderr(err): + self.assertEqual(ttpf.main(["scan", self.path, bad]), 2, bad) + self.assertIn(why, err.getvalue()) + self.assertIn(bad, err.getvalue()) + def test_scan_counts_an_unlisted_tuple_as_gated(self): path = os.path.join(self.tmp.name, "unlisted.ttpf") build_pool(path, meta=0x599) diff --git a/tools/ttpf_mips.py b/tools/ttpf_mips.py index 3c4bf79b6..22ad79413 100644 --- a/tools/ttpf_mips.py +++ b/tools/ttpf_mips.py @@ -30,7 +30,7 @@ slices/faces for arrays and cubemaps; BC1, BC3, BC4_UNORM and BC5_UNORM) or 3D Z-continuity vs 2D control for float16 volumes. `export` writes a DX10 DDS when every source mip uses a supported codec. - python -I tools/ttpf_mips.py scan [--json out] [--tuples] + python -I tools/ttpf_mips.py scan [--json out] [--tuples] python -I tools/ttpf_mips.py layout python -I tools/ttpf_mips.py check [--allow-provisional] [--history path] python -I tools/ttpf_mips.py export [--mips N] [--force] [--allow-provisional] [--history path] @@ -898,11 +898,15 @@ def same_output_path(first, second): def find_pools(arg): + """Pools under a game root (data/ttdb and pack/*/data/ttdb), or, for any other folder such as data/ttdb + itself or one pack, every .ttpf below it. A file is taken as a pool.""" if os.path.isfile(arg): return [arg] pools = sorted(glob.glob(os.path.join(arg, "data", "ttdb", "**", "*.ttpf"), recursive=True)) pools += sorted(glob.glob(os.path.join(arg, "pack", "*", "data", "ttdb", "**", "*.ttpf"), recursive=True)) + if not pools: + pools = sorted(glob.glob(os.path.join(arg, "**", "*.ttpf"), recursive=True)) return pools @@ -1550,7 +1554,12 @@ def main(argv=None): if a.cmd == "scan": pools = [] for p in a.paths: - pools += find_pools(p) + found = find_pools(p) + if not found: # a mistyped path would otherwise report an all-zero scan and exit 0 + why = "no such file or folder" if not os.path.exists(p) else "no .ttpf pool in it" + print(f"ERROR: {p}: {why}", file=sys.stderr) + return 2 + pools += found # The report is written after every pool is read: a pool given as --json used to be replaced by it. if a.json: if os.path.isdir(a.json): From d835fac9b49d76707528e96af37b6094e75b76c9 Mon Sep 17 00:00:00 2001 From: Rafael Date: Sun, 22 Nov 2026 09:01:10 -0300 Subject: [PATCH 2/2] ttpf_mips: find_pools escapes the folder before globbing A folder name with glob characters, like "Game [v1]", was used as a glob pattern, so no pool matched and the new "no .ttpf pool in it" error would name a folder that does hold pools. The folder is now passed through glob.escape; only the parts below it are patterns. Test: test_scan_finds_pools_below_any_folder_and_rejects_paths_without_one now builds its game folder as "game [v1]" (without the escape: 0 pools). Co-Authored-By: Claude Opus 5.5 --- tests/test_ttpf_mips.py | 4 ++-- tools/ttpf_mips.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_ttpf_mips.py b/tests/test_ttpf_mips.py index 8a5522b5a..53e60b3b2 100644 --- a/tests/test_ttpf_mips.py +++ b/tests/test_ttpf_mips.py @@ -754,11 +754,11 @@ class SyntheticPoolTest(unittest.TestCase): path with no pool is an error, not an all-zero scan with exit code 0.""" import io from contextlib import redirect_stderr, redirect_stdout - ttdb = os.path.join(self.tmp.name, "game", "data", "ttdb", "props") + ttdb = os.path.join(self.tmp.name, "game [v1]", "data", "ttdb", "props") # [..] is not a glob here os.makedirs(ttdb) build_pool(os.path.join(ttdb, "a.ttpf")) out = os.path.join(self.tmp.name, "scan.json") - for folder in (os.path.join(self.tmp.name, "game"), os.path.dirname(ttdb), ttdb): + for folder in (os.path.join(self.tmp.name, "game [v1]"), os.path.dirname(ttdb), ttdb): with redirect_stdout(io.StringIO()): self.assertEqual(ttpf.main(["scan", folder, "--json", out]), 0, folder) with open(out, encoding="utf-8") as f: diff --git a/tools/ttpf_mips.py b/tools/ttpf_mips.py index 22ad79413..21bcfc6d0 100644 --- a/tools/ttpf_mips.py +++ b/tools/ttpf_mips.py @@ -902,11 +902,12 @@ def find_pools(arg): itself or one pack, every .ttpf below it. A file is taken as a pool.""" if os.path.isfile(arg): return [arg] - pools = sorted(glob.glob(os.path.join(arg, "data", "ttdb", "**", "*.ttpf"), recursive=True)) - pools += sorted(glob.glob(os.path.join(arg, "pack", "*", "data", "ttdb", "**", "*.ttpf"), + root = glob.escape(arg) # a folder like "Game [v1]" is a path, not a glob pattern + pools = sorted(glob.glob(os.path.join(root, "data", "ttdb", "**", "*.ttpf"), recursive=True)) + pools += sorted(glob.glob(os.path.join(root, "pack", "*", "data", "ttdb", "**", "*.ttpf"), recursive=True)) if not pools: - pools = sorted(glob.glob(os.path.join(arg, "**", "*.ttpf"), recursive=True)) + pools = sorted(glob.glob(os.path.join(root, "**", "*.ttpf"), recursive=True)) return pools