Files
Diabolo/DoOtboy/tools/package.py
T

41 lines
1.9 KiB
Python
Raw Normal View History

"""Package only distributable files; exclude editor caches and player saves."""
from pathlib import Path
import hashlib
import zipfile
root = Path(__file__).resolve().parents[1]
builds = root / "builds"
windows = builds / "Windows"
with zipfile.ZipFile(builds / "DoOtboy_v0.1_Windows.zip", "w", zipfile.ZIP_DEFLATED, compresslevel=6) as archive:
for name in ("DoOtboy.exe", "README_RU.md", "GODOT_LICENSE.txt"):
archive.write(windows / name, "DoOtboy/" + name)
with zipfile.ZipFile(builds / "DoOtboy_v0.1_Source.zip", "w", zipfile.ZIP_DEFLATED, compresslevel=6) as archive:
for name in ("README_RU.md", "GODOT_LICENSE.txt", "build.ps1", ".gitignore"):
archive.write(root / name, "DoOtboy/" + name)
for name in ("make_audio.py", "package.py"):
archive.write(root / "tools" / name, "DoOtboy/tools/" + name)
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 name in ("DoOtboy_v0.1_Windows.zip", "DoOtboy_v0.1_Source.zip"):
path = builds / name
digest = hashlib.sha256(path.read_bytes()).hexdigest()
print(f"{name}: {path.stat().st_size:,} bytes; SHA256 {digest}")
with zipfile.ZipFile(builds / "DoOtboy_v0.1_Windows.zip") as archive:
assert archive.testzip() is None
with zipfile.ZipFile(builds / "DoOtboy_v0.1_Source.zip") as archive:
assert archive.testzip() is None
print("Both ZIP archives verified")