Files
CyberGril/samples/companion/tools/pack_assets.py
T

42 lines
1.5 KiB
Python

"""Verify a whole versioned pack before building or rolling back.
Material versions and outfit labels are independent of the stable companion id.
This command never writes identity, bazi, memory or relationship state.
"""
import argparse
import hashlib
import json
from pathlib import Path
def verify(root):
root = root.resolve()
manifest = json.loads((root / "manifest.json").read_text())
assert manifest["version"] and manifest["persona_id"]
assert manifest["companion_id"] == "wanwan", "Companion identity cannot change with assets"
files = [manifest["identity_ref"]]
files += [c["file"] for c in manifest["daily_clips"] + manifest["talk_clips"]]
transition = manifest.get("transition", {})
if transition.get("available"):
files += [transition["enter"], transition["return"]]
for name in files:
assert name in manifest["sha256"], f"No checksum: {name}"
for name, checksum in manifest["sha256"].items():
path = (root / name).resolve()
assert path.is_relative_to(root), f"Unsafe asset path: {name}"
assert hashlib.sha256(path.read_bytes()).hexdigest() == checksum, name
return manifest
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--assets",
type=Path,
default=Path(__file__).resolve().parents[1] / "assets/personas/wanwan-v2-cream-night",
)
args = parser.parse_args()
manifest = verify(args.assets)
print("Verified asset pack:", manifest["version"], len(manifest["sha256"]), "files")