"""Prepare local binary/source archives; performs no publishing or deployment.""" from pathlib import Path import hashlib import json import zipfile ROOT=Path(__file__).resolve().parents[1] out=ROOT/'dist' version=json.loads((ROOT/'mod.json').read_text())['version'] stem=f'phantombladezero_scriptcompat_{version}_experimental' binary=out/(stem+'.zip') source=out/(stem+'_source.zip') binary_files=[out/'README.md',out/'LICENSE',out/'NOTICE.md',out/'CONTRIBUTORS.md', out/'MINHOOK-LICENSE.txt',out/'UE4SS-SDK-LICENSE.txt'] binary_files+=list((out/'ue4ss').rglob('*')) with zipfile.ZipFile(binary,'w',zipfile.ZIP_DEFLATED) as z: for path in sorted(binary_files): if path.is_file():z.write(path,path.relative_to(out).as_posix()) files=[ROOT/name for name in ['README.md','LICENSE','NOTICE.md','CONTRIBUTING.md','CONTRIBUTORS.md','mod.json','.gitignore','.gitattributes']] for folder in ['src','tests','tools/vendor/minhook-1.3.4','tools/vendor/ue4ss-sdk']: files.extend(p for p in (ROOT/folder).rglob('*') if p.is_file()) files.append(ROOT/'tools/build.py') with zipfile.ZipFile(source,'w',zipfile.ZIP_DEFLATED) as z: for path in sorted(files):z.write(path,path.relative_to(ROOT).as_posix()) for archive in [binary,source]: with zipfile.ZipFile(archive) as z: assert z.testzip() is None assert all('\\' not in n and not n.startswith('/') and '..' not in Path(n).parts for n in z.namelist()) print(archive.name,archive.stat().st_size,hashlib.sha256(archive.read_bytes()).hexdigest()) (out/'SHA256SUMS.txt').write_text(''.join( f'{hashlib.sha256(a.read_bytes()).hexdigest()} {a.name}\n' for a in [binary,source]),encoding='ascii')