Download tasks/t39-rct-onetile/tests/reopen.py from refreshdotdev/Refresh-GUI-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.54 kB
-
https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t39-rct-onetile/tests/reopen.py
- Command line
-
hf download hf://datasets/refreshdotdev/Refresh-GUI-dataset/tasks/t39-rct-onetile/tests/reopen.py
-
curl -L -o reopen.py https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t39-rct-onetile/tests/reopen.py
2.54 kB
| """Read a saved park through the pinned engine in an isolated verifier profile.""" | |
| import argparse | |
| import json | |
| import os | |
| from pathlib import Path | |
| import selectors | |
| import shutil | |
| import subprocess | |
| import tempfile | |
| import time | |
| def reopen(park, engine="openrct2", rct2="/opt/rct2-assets"): | |
| with tempfile.TemporaryDirectory(prefix="t39-reopen-") as temp: | |
| profile=Path(temp) | |
| (profile/"plugin").mkdir() | |
| observer=Path(__file__).with_name("native-inspect.js") | |
| shutil.copy2(observer,profile/"plugin/observer.js") | |
| # The base plot is a converted copy; no RCT1 installation is needed. | |
| command=[engine,str(park.resolve()),"--headless","--rct2-data-path",rct2, | |
| "--user-data-path",temp] | |
| child=subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.STDOUT, | |
| bufsize=0) | |
| output=b"" | |
| try: | |
| selector=selectors.DefaultSelector() | |
| selector.register(child.stdout,selectors.EVENT_READ) | |
| deadline=time.monotonic()+90 | |
| while time.monotonic()<deadline: | |
| if not selector.select(timeout=1): | |
| if child.poll() is not None: | |
| break | |
| continue | |
| block=os.read(child.stdout.fileno(),65536) | |
| if not block: | |
| break | |
| output+=block | |
| for line in output.decode(errors="replace").splitlines(): | |
| if "T39JSON " in line: | |
| try: | |
| data,_=json.JSONDecoder().raw_decode(line.split("T39JSON ",1)[1]) | |
| if data.get("kind") == "load": | |
| return data | |
| except json.JSONDecodeError: | |
| pass | |
| raise RuntimeError("Native park inspection failed: "+output.decode(errors="replace")[-2000:]) | |
| finally: | |
| child.terminate() | |
| try: | |
| child.wait(timeout=5) | |
| except subprocess.TimeoutExpired: | |
| child.kill() | |
| child.wait() | |
| if __name__ == "__main__": | |
| parser=argparse.ArgumentParser() | |
| parser.add_argument("park",type=Path) | |
| parser.add_argument("output",type=Path) | |
| parser.add_argument("--engine",default="openrct2") | |
| parser.add_argument("--rct2",default="/opt/rct2-assets") | |
| args=parser.parse_args() | |
| args.output.write_text(json.dumps(reopen(args.park,args.engine,args.rct2),indent=2)+"\n") | |