#!/usr/bin/env python3 import hashlib import json import os import pathlib import sys import tempfile import bpy def library_report(): libraries = list(bpy.data.libraries) if len(libraries) != 1: raise RuntimeError(f"expected one library, found {len(libraries)}") library = libraries[0] return { "id": "library:" + library.name, "name": library.name, "sourcePath": library.filepath, "packed": library.packed_file is not None, "readOnly": True, "dependencyIds": [], } def main() -> None: arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 2: raise SystemExit("usage: blender -b --python check-library-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 = library_report() descriptor, temporary = tempfile.mkstemp(prefix="m16-library-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 = library_report() finally: pathlib.Path(temporary).unlink(missing_ok=True) if before != after: raise RuntimeError(f"library save/reopen drift: {before} != {after}") report = { "schemaVersion": 1, "task": "M16-GAP-00011", "operation": "LIBRARY_DATABLOCK_DESKTOP", "fixture": str(fixture), "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "library": after, "saveReopen": "EXACT", "blenderVersion": bpy.app.version_string, } output.parent.mkdir(parents=True, exist_ok=True) output.write_text(json.dumps(report, indent=2, sort_keys=True) + "\n", encoding="utf-8") print(f"library-desktop-ok id={after['id']} sourcePath={after['sourcePath']} saveReopen=exact") if __name__ == "__main__": main()