Files
Diabolo/DoOtboy/tools/package.py
T

53 lines
2.7 KiB
Python
Raw Normal View History

"""Package only distributable files; exclude editor caches and player saves."""
from pathlib import Path
import hashlib
import zipfile
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--windows-dir", default="Windows")
parser.add_argument("--version", default="0.2.3")
args = parser.parse_args()
root = Path(__file__).resolve().parents[1]
builds = root / "builds"
windows = builds / args.windows_dir
assert windows.resolve().is_relative_to(builds.resolve())
assert all(c in "0123456789." for c in args.version)
windows_zip = builds / f"DoOtboy_v{args.version}_Windows.zip"
source_zip = builds / f"DoOtboy_v{args.version}_Source.zip"
with zipfile.ZipFile(windows_zip, "w", zipfile.ZIP_DEFLATED, compresslevel=6) as archive:
for name in ("DoOtboy.exe", "README_RU.md", "SCENARIO_RU.md", "AUDIO_CREDITS.md", "GODOT_LICENSE.txt"):
archive.write(windows / name, "DoOtboy/" + name)
with zipfile.ZipFile(source_zip, "w", zipfile.ZIP_DEFLATED, compresslevel=6) as archive:
for name in ("README_RU.md", "SCENARIO_RU.md", "AUDIO_CREDITS.md", "GODOT_LICENSE.txt", "build.ps1", ".gitignore"):
archive.write(root / name, "DoOtboy/" + name)
for name in ("make_audio.py", "make_phone_effects.py", "prepare_soundscape.py", "install_conversation_fill.py", "install_stairwell_voices.py", "write_phone_story.py", "write_voice_direction.py", "make_draft_voices.ps1", "split_voice_batch.py", "install_jessica_voice.py", "install_directed_voices.py", "package.py"):
archive.write(root / "tools" / name, "DoOtboy/tools/" + name)
for path in (root / "voiceover").rglob("*"):
if path.is_file() and path.suffix in (".md", ".json"):
archive.write(path, "DoOtboy/" + path.relative_to(root).as_posix())
for path in (root / "do-otboy").rglob("*"):
if not path.is_file() or ".godot" in path.parts or path.suffix == ".import":
continue
archive_name = "DoOtboy/" + path.relative_to(root).as_posix()
if path.name == "export_presets.cfg":
portable = path.read_text(encoding="utf-8").replace(
'custom_template/release="../tools/templates/windows_release_x86_64.exe"',
'custom_template/release=""',
)
archive.writestr(archive_name, portable)
else:
archive.write(path, archive_name)
for path in (windows_zip, source_zip):
digest = hashlib.sha256(path.read_bytes()).hexdigest()
print(f"{path.name}: {path.stat().st_size:,} bytes; SHA256 {digest}")
with zipfile.ZipFile(windows_zip) as archive:
assert archive.testzip() is None
with zipfile.ZipFile(source_zip) as archive:
assert archive.testzip() is None
print("Both ZIP archives verified")