MC/tools/build-dunemenus-release.py

36 lines
2.6 KiB
Python

"""Build the supplied menu artwork into the pinned shared pack; emit hashed release files."""
from pathlib import Path
import hashlib, io, json, shutil, subprocess, sys, urllib.request, zipfile
root=Path(__file__).resolve().parents[1]
out=Path(sys.argv[1]);out.mkdir(parents=True,exist_ok=True)
baseline=(root/'network/resource-pack/clean-base.zip').read_bytes()
assert hashlib.sha256(baseline).hexdigest()=='b52b89a6d437fccc56db756bf7d628839efa76c2a45ab9308db2afc6f8058e55','Clean base differs'
with zipfile.ZipFile(io.BytesIO(baseline)) as z:
entries={n:z.read(n) for n in z.namelist() if not n.endswith('/')}
art=root/'network/resource-pack/shared'
assets=[art/'assets/dunerealms/font/gui.json',*sorted((art/'assets/dunerealms/textures/gui/bg').glob('*.png'))]
assert len(assets)==13
font=json.loads(assets[0].read_text(encoding='utf-8'))
for p in assets:entries[p.relative_to(art).as_posix()]=p.read_bytes()
for name in ['items/spy_module.json','models/item/spy_module.json','textures/item/spy_module.png']:
p=art/'assets/dunerealms'/name
entries[p.relative_to(art).as_posix()]=p.read_bytes()
for provider in font['providers']:
if provider.get('type')=='bitmap':
namespace,path=provider['file'].split(':',1)
assert f'assets/{namespace}/textures/{path}' in entries
pack=out/'DuneRealms-Network-Artwork-v7.zip'
with zipfile.ZipFile(pack,'w',zipfile.ZIP_DEFLATED,compresslevel=9) as z:
for name,data in sorted(entries.items()):
zi=zipfile.ZipInfo(name,(2026,11,28,0,0,0));zi.compress_type=zipfile.ZIP_DEFLATED;z.writestr(zi,data)
for module,name in [('DuneMenus','DuneMenus.jar'),('DuneEss','DuneRealms-Essentials.jar'),('DuneLobby','DuneRealms-Lobby.jar'),('DuneRealms-minecraft-only','DuneRealms-Core.jar'),('DuneNPC','DuneRealms-NPC.jar'),('JarvisConnector','jarvistranslator.jar')]:
shutil.copy2(root/module/'build/libs'/name,out/name)
shutil.copy2(root/'tools/install-dunemenus-release.py',out/'install-dunemenus-release.py')
shutil.copy2(root/'network/resource-pack/dunemenus-v7.nginx.conf',out/'dunemenus-v7.nginx.conf')
shutil.copy2(root/'tools/publish-dunemenus-pack.py',out/'publish-dunemenus-pack.py')
manifest={'source':subprocess.check_output(['git','rev-parse','HEAD'],cwd=root,text=True).strip(),'input_zip_sha256':'6d3cde343ba09fb7088a3a07b0c54c96eeb629c82c527993a76000013c305b60','pack_url':'https://www.dunerealms.com/downloads/'+pack.name,'files':{}}
for p in sorted(out.iterdir()):
if p.is_file() and p.name!='release.json':
data=p.read_bytes();manifest['files'][p.name]={'sha1':hashlib.sha1(data).hexdigest(),'sha256':hashlib.sha256(data).hexdigest(),'bytes':len(data)}
(out/'release.json').write_text(json.dumps(manifest,indent=2)+'\n')
print(json.dumps(manifest,indent=2))