Files

41 lines
1.7 KiB
Python

"""Package the current working sources, without Godot, Git history or local caches."""
from pathlib import Path
import hashlib
import json
import zipfile
import sys
root = Path(__file__).resolve().parent.parent
output = Path(sys.argv[1]).resolve()
output.mkdir(parents=True, exist_ok=True)
def entries(mac=False):
folders = ['assets', 'scenes', 'scripts'] + (['macos'] if mac else [])
for folder in folders:
for path in sorted((root / folder).rglob('*')):
if path.is_file() and path.suffix != '.import':
yield path, path.relative_to(root).as_posix()
for name in ['project.godot', 'README.md'] + (['Start-Game.command', 'Install-Mac.command'] if mac else ['Start-Game.exe', 'Start-Game.cmd', 'Start-Local.cmd']):
yield root / name, name
yield root / 'installer/README.md', 'INSTALLATION.md'
for path in (root / 'server/third-party').rglob('*'):
if path.is_file():
yield path, 'licenses/' + path.name
def write_zip(path, mac=False):
manifest = {}
with zipfile.ZipFile(path, 'w', zipfile.ZIP_DEFLATED) as archive:
for source, name in entries(mac):
data = source.read_bytes()
manifest[name] = hashlib.sha256(data).hexdigest()
info = zipfile.ZipInfo(('BLOCKLINE-Mac/' if mac else '') + name)
info.create_system = 3
info.external_attr = (0o100755 if name.endswith(('.sh', '.command')) else 0o100644) << 16
info.compress_type = zipfile.ZIP_DEFLATED
archive.writestr(info, data)
archive.writestr(('BLOCKLINE-Mac/' if mac else '') + 'BUILD-INFO.json', json.dumps(manifest, indent=2))
write_zip(output / 'payload.zip')
write_zip(output / 'BLOCKLINE-Mac.zip', True)
print(output)