41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
"""Build and apply the scoped workstation provenance class overlay."""
|
|
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
from plugin_wild_update import digest, read_archive, write_archive
|
|
|
|
ENTRY = "com/dunerealms/jarvis/ItemMetadataOverlay.class"
|
|
|
|
|
|
def extract(built, output):
|
|
compiled = read_archive(built.read_bytes())
|
|
output.write_bytes(write_archive({ENTRY: compiled[ENTRY]}))
|
|
|
|
|
|
def assemble(baseline, baseline_sha, patch, patch_sha, output):
|
|
baseline_bytes = baseline.read_bytes()
|
|
patch_bytes = patch.read_bytes()
|
|
if digest(baseline_bytes) != baseline_sha or digest(patch_bytes) != patch_sha:
|
|
raise ValueError("Unexpected baseline or overlay checksum")
|
|
retained = read_archive(baseline_bytes)
|
|
overlay = read_archive(patch_bytes)
|
|
if set(overlay) != {ENTRY} or ENTRY not in retained or retained[ENTRY] == overlay[ENTRY]:
|
|
raise ValueError("Expected one replacement class in an existing JarvisConnector JAR")
|
|
output.write_bytes(write_archive(retained | overlay))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
sub = parser.add_subparsers(dest="action", required=True)
|
|
pack = sub.add_parser("extract")
|
|
pack.add_argument("built", type=Path)
|
|
pack.add_argument("output", type=Path)
|
|
merge = sub.add_parser("assemble")
|
|
merge.add_argument("baseline", type=Path)
|
|
merge.add_argument("baseline_sha")
|
|
merge.add_argument("patch", type=Path)
|
|
merge.add_argument("patch_sha")
|
|
merge.add_argument("output", type=Path)
|
|
args = vars(parser.parse_args())
|
|
(extract if args.pop("action") == "extract" else assemble)(**args)
|

Staff