refactor(clew): flatten Ren'Py AST extraction
This commit is contained in:
@@ -104,18 +104,22 @@ def ast_dump_output_path(output_root: Path, extracted_root: Path, game_root: Pat
|
||||
return output_root / "ast" / namespace / relative_script.with_suffix(relative_script.suffix + ".json")
|
||||
|
||||
|
||||
def run_extract_renpy_ast(game_root: Path, script: Path, output: Path) -> None:
|
||||
exporter = Path(dump_ast_script.__file__).resolve()
|
||||
bundled_python = game_root / "lib" / "linux-x86_64" / "python"
|
||||
def run_extract_renpy_ast(
|
||||
bundled_python: Path,
|
||||
extractor: Path,
|
||||
game_root: Path,
|
||||
compiled_script: Path,
|
||||
output: Path,
|
||||
) -> None:
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
command = [
|
||||
"steam-run",
|
||||
str(bundled_python),
|
||||
str(exporter),
|
||||
str(extractor),
|
||||
"--game-root",
|
||||
str(game_root),
|
||||
"--input",
|
||||
str(script),
|
||||
str(compiled_script),
|
||||
"--output",
|
||||
str(output),
|
||||
]
|
||||
@@ -123,6 +127,7 @@ def run_extract_renpy_ast(game_root: Path, script: Path, output: Path) -> None:
|
||||
|
||||
|
||||
def extract_game_ast(output_root: Path, extracted_root: Path, overwrite: bool) -> None:
|
||||
extractor = Path(dump_ast_script.__file__).resolve()
|
||||
game_roots = find(
|
||||
extracted_root,
|
||||
lambda path: (
|
||||
@@ -136,6 +141,7 @@ def extract_game_ast(output_root: Path, extracted_root: Path, overwrite: bool) -
|
||||
return
|
||||
|
||||
for game_root in game_roots:
|
||||
bundled_python = game_root / "lib" / "linux-x86_64" / "python"
|
||||
scripts = find(
|
||||
game_root / "game",
|
||||
lambda path: path.is_file() and path.suffix.lower() in {".rpyc", ".rpymc"},
|
||||
@@ -147,7 +153,7 @@ def extract_game_ast(output_root: Path, extracted_root: Path, overwrite: bool) -
|
||||
LOG.info("skipping existing AST dump: %s", output)
|
||||
continue
|
||||
LOG.info("dumping AST: %s", script)
|
||||
run_extract_renpy_ast(game_root, script, output)
|
||||
run_extract_renpy_ast(bundled_python, extractor, game_root, script, output)
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> None:
|
||||
|
||||
Reference in New Issue
Block a user