diff --git a/tests/test_ttpf_mips.py b/tests/test_ttpf_mips.py index e5ed8dd5a..36dbbfa21 100644 --- a/tests/test_ttpf_mips.py +++ b/tests/test_ttpf_mips.py @@ -1112,6 +1112,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 [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 [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: + 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 a1959f9a5..bf7a9f35d 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, BC5_UNORM, BC6H and BC7) 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] @@ -1192,11 +1192,16 @@ 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"), + 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(root, "**", "*.ttpf"), recursive=True)) return pools @@ -1846,7 +1851,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):