#!/usr/bin/env python3 import hashlib import json import os import pathlib import sys import tempfile import bpy def report(): sound = bpy.data.sounds.get("WebGapSound") if sound is None: raise RuntimeError("WebGapSound is missing") return { "id": "sound:" + sound.name, "name": sound.name, "sourcePath": sound.filepath, "packed": sound.packed_file is not None, "volume": 0.0, "pitch": 0.0, "audioChannels": {"MONO": 1, "STEREO": 2, "STEREO_LFE": 3, "SURROUND4": 4, "SURROUND5_1": 6, "SURROUND7_1": 8}.get(sound.channels, 0), "sampleRate": int(sound.samplerate), } def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 2: raise SystemExit("usage: blender -b --python check-sound-desktop.py -- FIXTURE REPORT") fixture, output = (pathlib.Path(value).resolve() for value in arguments) bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=False) before = report() descriptor, temporary = tempfile.mkstemp(prefix="m16-sound-reopen-", suffix=".blend", dir=fixture.parent) os.close(descriptor) try: bpy.ops.wm.save_as_mainfile(filepath=temporary, check_existing=False, compress=True) bpy.ops.wm.open_mainfile(filepath=temporary, load_ui=False) after = report() finally: pathlib.Path(temporary).unlink(missing_ok=True) if before != after: raise RuntimeError(f"sound save/reopen drift: {before} != {after}") value = {"schemaVersion": 1, "task": "M16-GAP-00022", "operation": "SOUND_DATABLOCK_DESKTOP", "fixture": str(fixture), "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "sound": after, "saveReopen": "EXACT", "blenderVersion": bpy.app.version_string} output.parent.mkdir(parents=True, exist_ok=True) output.write_text(json.dumps(value, indent=2, sort_keys=True) + "\n", encoding="utf-8") print(f"sound-desktop-ok id={after['id']} volume={after['volume']} saveReopen=exact") if __name__ == "__main__": main()