plugins/tools/plugin_ria_copy.py

22 lines
1.2 KiB
Python

"""Install the scoped ATM reference actions onto an exact retained menu archive."""
import argparse
from pathlib import Path
from plugin_wild_update import digest, read_archive, write_archive
ATM='com/dunerealms/menus/AtmMenu.class'
COPY='com/dunerealms/menus/RiaClipboard.class'
ATM_PREIMAGE='3139e7085a1779098e8651f4fc79b32ae67de58fe61a59155843c6e9bd93eb62'
def assemble(baseline,baseline_sha,donor,donor_sha,output):
old=baseline.read_bytes();payload=donor.read_bytes()
if digest(old)!=baseline_sha or digest(payload)!=donor_sha:raise ValueError('Unexpected archive checksum')
retained=read_archive(old);compiled=read_archive(payload)
if digest(retained[ATM])!=ATM_PREIMAGE:raise ValueError('Unexpected retained ATM implementation')
if COPY in retained or set(compiled)!={ATM,COPY}:raise ValueError('Unexpected ATM overlay scope')
retained.update(compiled)
with output.open('xb') as stream:stream.write(write_archive(retained))
if __name__=='__main__':
p=argparse.ArgumentParser(description=__doc__)
p.add_argument('baseline',type=Path);p.add_argument('baseline_sha');p.add_argument('donor',type=Path);p.add_argument('donor_sha');p.add_argument('output',type=Path)
assemble(**vars(p.parse_args()))