50 lines
2.2 KiB
Python
50 lines
2.2 KiB
Python
"""Permit a local return from a native dimension without replacing the home payment journal."""
|
|
import argparse
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
from tempfile import TemporaryDirectory
|
|
|
|
from plugin_wild_update import digest, read_archive, write_archive
|
|
|
|
TRAVEL = "com/example/duneess/PersonalHomeTravel.class"
|
|
ROUTES = "com/example/duneess/HomeDimensionRoutes.class"
|
|
TRAVEL_BASELINES = {
|
|
"7fde0b6b5aba9e6755292a88b8157780e212708aadc5fe62de084f599234587d",
|
|
"dee4b89e17c254e28254c5dfe88fbcf9f5c284a6a21332f0e7ab121d8c882afc",
|
|
}
|
|
|
|
|
|
def assemble(baseline, baseline_sha, donor, donor_sha, output, classpath):
|
|
existing = baseline.read_bytes()
|
|
compiled = donor.read_bytes()
|
|
if digest(existing) != baseline_sha or digest(compiled) != donor_sha:
|
|
raise ValueError("Unexpected baseline or donor checksum")
|
|
retained = read_archive(existing)
|
|
source = read_archive(compiled)
|
|
if set(source) != {ROUTES} or ROUTES in retained or digest(retained[TRAVEL]) not in TRAVEL_BASELINES:
|
|
raise ValueError("Unexpected home travel class scope")
|
|
java_home = os.environ.get("JAVA_HOME")
|
|
executable = "java.exe" if os.name == "nt" else "java"
|
|
java = str(Path(java_home) / "bin" / executable) if java_home else executable
|
|
helper = Path(__file__).with_name("HomeDimensionOverlay.java")
|
|
with TemporaryDirectory() as temporary:
|
|
root = Path(temporary)
|
|
old, merged = root / "retained.class", root / "merged.class"
|
|
old.write_bytes(retained[TRAVEL])
|
|
subprocess.run([java, "--class-path", classpath, str(helper), str(old), str(merged)], check=True)
|
|
retained[TRAVEL] = merged.read_bytes()
|
|
retained[ROUTES] = source[ROUTES]
|
|
with output.open("xb") as candidate:
|
|
candidate.write(write_archive(retained))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("baseline", type=Path)
|
|
parser.add_argument("baseline_sha")
|
|
parser.add_argument("donor", type=Path)
|
|
parser.add_argument("donor_sha")
|
|
parser.add_argument("output", type=Path)
|
|
parser.add_argument("classpath", help="ASM core and tree JARs")
|
|
assemble(**vars(parser.parse_args()))
|

Staff