refactor(clew): use predicate-based directory walking

This commit is contained in:
2026-09-07 18:15:39 -04:00
parent 3c68375a66
commit 246d7d5d0e

View File

@@ -92,22 +92,21 @@ def is_game_root(path: Path) -> bool:
)
def find_game_roots(extracted_root: Path) -> list[Path]:
game_roots = []
for root, directories, _files in os.walk(extracted_root):
path = Path(root)
if is_game_root(path):
game_roots.append(path)
directories[:] = []
return sorted(game_roots)
def walk_directory(root: Path, predicate) -> list[Path]:
matches = []
for current, _directories, files in os.walk(root):
current_path = Path(current)
if predicate(current_path):
matches.append(current_path)
for file_name in files:
file_path = current_path / file_name
if predicate(file_path):
matches.append(file_path)
return sorted(matches)
def find_compiled_scripts(game_root: Path) -> list[Path]:
scripts = []
game_directory = game_root / "game"
for suffix in ("*.rpyc", "*.rpymc"):
scripts.extend(game_directory.rglob(suffix))
return sorted(scripts)
def is_compiled_script(path: Path) -> bool:
return path.is_file() and path.suffix.lower() in {".rpyc", ".rpymc"}
def object_dump_output_path(output_root: Path, extracted_root: Path, game_root: Path, script: Path) -> Path:
@@ -135,13 +134,13 @@ def run_renpy_object_dump(game_root: Path, script: Path, output: Path) -> None:
def dump_renpy_objects(output_root: Path, extracted_root: Path, overwrite: bool) -> None:
game_roots = find_game_roots(extracted_root)
game_roots = walk_directory(extracted_root, is_game_root)
if not game_roots:
LOG.warning("no Ren'Py game roots found under %s", extracted_root)
return
for game_root in game_roots:
scripts = find_compiled_scripts(game_root)
scripts = walk_directory(game_root / "game", is_compiled_script)
LOG.info("found %d compiled Ren'Py scripts under %s", len(scripts), game_root)
total = len(scripts)
for index, script in enumerate(scripts, start=1):