refactor(clew): rename object dump to AST dump
This commit is contained in:
@@ -5,12 +5,12 @@ py_binary(
|
|||||||
srcs = ["clew.py"],
|
srcs = ["clew.py"],
|
||||||
main = "clew.py",
|
main = "clew.py",
|
||||||
deps = [
|
deps = [
|
||||||
":renpy_object_dump",
|
":dump_ast",
|
||||||
"//third_party/python:rpycdec",
|
"//third_party/python:rpycdec",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
py_library(
|
py_library(
|
||||||
name = "renpy_object_dump",
|
name = "dump_ast",
|
||||||
srcs = ["renpy_object_dump.py"],
|
srcs = ["dump_ast.py"],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from collections.abc import Callable
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from rpycdec.rpa import extract_rpa
|
from rpycdec.rpa import extract_rpa
|
||||||
from src.clew import renpy_object_dump
|
from src.clew import dump_ast as dump_ast_script
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -38,9 +38,9 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
|
|||||||
help="Replace Clew-managed output directories.",
|
help="Replace Clew-managed output directories.",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--no-renpy-object-dump",
|
"--no-ast-dump",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Skip dumping compiled Ren'Py scripts from output/extracted/ to output/ast-raw/.",
|
help="Skip dumping compiled scripts from output/extracted/ to output/ast-raw/.",
|
||||||
)
|
)
|
||||||
return parser.parse_args(argv)
|
return parser.parse_args(argv)
|
||||||
|
|
||||||
@@ -98,14 +98,14 @@ def find(root: Path, predicate: Callable[[Path], bool]) -> list[Path]:
|
|||||||
return sorted(matches)
|
return sorted(matches)
|
||||||
|
|
||||||
|
|
||||||
def object_dump_output_path(output_root: Path, extracted_root: Path, game_root: Path, script: Path) -> Path:
|
def ast_dump_output_path(output_root: Path, extracted_root: Path, game_root: Path, script: Path) -> Path:
|
||||||
namespace = game_root.relative_to(extracted_root)
|
namespace = game_root.relative_to(extracted_root)
|
||||||
relative_script = script.relative_to(game_root)
|
relative_script = script.relative_to(game_root)
|
||||||
return output_root / "ast-raw" / namespace / relative_script.with_suffix(relative_script.suffix + ".json")
|
return output_root / "ast-raw" / namespace / relative_script.with_suffix(relative_script.suffix + ".json")
|
||||||
|
|
||||||
|
|
||||||
def run_renpy_object_dump(game_root: Path, script: Path, output: Path) -> None:
|
def run_ast_dump(game_root: Path, script: Path, output: Path) -> None:
|
||||||
exporter = Path(renpy_object_dump.__file__).resolve()
|
exporter = Path(dump_ast_script.__file__).resolve()
|
||||||
bundled_python = game_root / "lib" / "linux-x86_64" / "python"
|
bundled_python = game_root / "lib" / "linux-x86_64" / "python"
|
||||||
output.parent.mkdir(parents=True, exist_ok=True)
|
output.parent.mkdir(parents=True, exist_ok=True)
|
||||||
command = [
|
command = [
|
||||||
@@ -122,7 +122,7 @@ def run_renpy_object_dump(game_root: Path, script: Path, output: Path) -> None:
|
|||||||
subprocess.run(command, check=True)
|
subprocess.run(command, check=True)
|
||||||
|
|
||||||
|
|
||||||
def dump_renpy_objects(output_root: Path, extracted_root: Path, overwrite: bool) -> None:
|
def dump_ast(output_root: Path, extracted_root: Path, overwrite: bool) -> None:
|
||||||
game_roots = find(
|
game_roots = find(
|
||||||
extracted_root,
|
extracted_root,
|
||||||
lambda path: (
|
lambda path: (
|
||||||
@@ -143,12 +143,12 @@ def dump_renpy_objects(output_root: Path, extracted_root: Path, overwrite: bool)
|
|||||||
LOG.info("found %d compiled Ren'Py scripts under %s", len(scripts), game_root)
|
LOG.info("found %d compiled Ren'Py scripts under %s", len(scripts), game_root)
|
||||||
total = len(scripts)
|
total = len(scripts)
|
||||||
for index, script in enumerate(scripts, start=1):
|
for index, script in enumerate(scripts, start=1):
|
||||||
output = object_dump_output_path(output_root, extracted_root, game_root, script)
|
output = ast_dump_output_path(output_root, extracted_root, game_root, script)
|
||||||
if output.exists() and not overwrite:
|
if output.exists() and not overwrite:
|
||||||
LOG.info("skipping existing Ren'Py object dump %d/%d: %s", index, total, output)
|
LOG.info("skipping existing AST dump %d/%d: %s", index, total, output)
|
||||||
continue
|
continue
|
||||||
LOG.info("dumping Ren'Py object graph %d/%d: %s", index, total, script)
|
LOG.info("dumping AST %d/%d: %s", index, total, script)
|
||||||
run_renpy_object_dump(game_root, script, output)
|
run_ast_dump(game_root, script, output)
|
||||||
|
|
||||||
|
|
||||||
def run(args: argparse.Namespace) -> None:
|
def run(args: argparse.Namespace) -> None:
|
||||||
@@ -162,8 +162,8 @@ def run(args: argparse.Namespace) -> None:
|
|||||||
extracted = get_output_directory(output_root, "extracted")
|
extracted = get_output_directory(output_root, "extracted")
|
||||||
extract_game_files(game_root, extracted)
|
extract_game_files(game_root, extracted)
|
||||||
|
|
||||||
if not args.no_renpy_object_dump:
|
if not args.no_ast_dump:
|
||||||
dump_renpy_objects(output_root, extracted, args.overwrite)
|
dump_ast(output_root, extracted, args.overwrite)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ except NameError:
|
|||||||
|
|
||||||
|
|
||||||
RPYC2_HEADER = b"RENPY RPC2"
|
RPYC2_HEADER = b"RENPY RPC2"
|
||||||
SCHEMA = "clew-renpy-object-dump-v1"
|
SCHEMA = "clew-ast-dump-v1"
|
||||||
|
|
||||||
|
|
||||||
def parse_args(argv):
|
def parse_args(argv):
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog="renpy-object-dump",
|
prog="dump-ast",
|
||||||
description="Dump Ren'Py compiled script objects as generic JSON.",
|
description="Dump compiled Ren'Py script ASTs as generic JSON.",
|
||||||
)
|
)
|
||||||
parser.add_argument("--game-root", required=True)
|
parser.add_argument("--game-root", required=True)
|
||||||
parser.add_argument("--input", required=True)
|
parser.add_argument("--input", required=True)
|
||||||
Reference in New Issue
Block a user