49 lines
2.1 KiB
Python
49 lines
2.1 KiB
Python
"""Build the scoped Exchange listing preview overlay."""
|
|
import argparse
|
|
from hashlib import sha256
|
|
from pathlib import Path
|
|
import subprocess
|
|
from tempfile import TemporaryDirectory
|
|
from zipfile import ZipFile
|
|
|
|
CLASS = "com/dunerealms/gui/ExchangeMenus.class"
|
|
BASELINES = {
|
|
"8bdd90dbb5e0fb0d0da0d15008a82cdfaefebecc0864f4ee443e6cd9442fd4db",
|
|
"c252f79f2735e92b1be3660a6c5d9d09f7aa8e57e81f05582fb9bca1c8bc04eb",
|
|
}
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("input", type=Path)
|
|
parser.add_argument("output", type=Path)
|
|
parser.add_argument("--baseline", type=Path)
|
|
parser.add_argument("--classpath")
|
|
args = parser.parse_args()
|
|
with ZipFile(args.input) as donor:
|
|
if not args.baseline:
|
|
with ZipFile(args.output, "x") as capsule:
|
|
capsule.writestr(CLASS, donor.read(CLASS))
|
|
return
|
|
if donor.namelist() != [CLASS] or not args.classpath:
|
|
raise ValueError("Expected the single-class donor and ASM classpath")
|
|
if sha256(args.baseline.read_bytes()).hexdigest() not in BASELINES:
|
|
raise ValueError("Unexpected retained GUI")
|
|
with TemporaryDirectory() as temp, ZipFile(args.baseline) as retained:
|
|
work = Path(temp)
|
|
before, new, result = (work / name for name in ("before.class", "donor.class", "patched.class"))
|
|
before.write_bytes(retained.read(CLASS))
|
|
new.write_bytes(donor.read(CLASS))
|
|
subprocess.run(
|
|
["java", "--class-path", args.classpath, str(Path(__file__).with_name("ExchangeListingMerge.java")), str(before), str(new), str(result)],
|
|
check=True,
|
|
)
|
|
if len(set(retained.namelist())) != len(retained.namelist()):
|
|
raise ValueError("Duplicate baseline entries")
|
|
with ZipFile(args.output, "x") as output:
|
|
for entry in retained.infolist():
|
|
output.writestr(entry, result.read_bytes() if entry.filename == CLASS else retained.read(entry))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|

Staff