34 lines
2.2 KiB
Python
34 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
import hashlib, json, pathlib, sys, tempfile, bpy
|
|
|
|
def state():
|
|
if len(bpy.data.libraries) != 1: raise RuntimeError("catalog-redo library missing")
|
|
lib = bpy.data.libraries[0]; return {"name": lib.name, "filepath": lib.filepath, "packed": lib.packed_file is not None}
|
|
|
|
def main():
|
|
args = sys.argv[sys.argv.index("--") + 1:]
|
|
if len(args) != 2: raise SystemExit("usage")
|
|
fixture, output = (pathlib.Path(v).resolve() for v in args); bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=False); before = state()
|
|
accepted = ("context is incorrect", "No asset selected", "No asset library", "Catalog")
|
|
try: poll = bool(bpy.ops.asset.catalog_redo.poll())
|
|
except RuntimeError as e:
|
|
if not any(x in str(e) for x in accepted): raise
|
|
poll = False
|
|
if poll: raise RuntimeError("catalog_redo poll unexpectedly true")
|
|
try: bpy.ops.asset.catalog_redo()
|
|
except RuntimeError as e:
|
|
if not any(x in str(e) for x in accepted): raise
|
|
status = "CANCELLED"
|
|
else: raise RuntimeError("catalog_redo unexpectedly finished")
|
|
if state() != before: raise RuntimeError("catalog_redo mutated Main")
|
|
with tempfile.NamedTemporaryFile(prefix="m16-catalog-redo-reopen-", suffix=".blend", dir=fixture.parent) as t:
|
|
bpy.ops.wm.save_as_mainfile(filepath=t.name, check_existing=False, compress=True); bpy.ops.wm.open_mainfile(filepath=t.name, load_ui=False); after = state()
|
|
if after != before: raise RuntimeError("catalog_redo save/reopen drift")
|
|
report = {"schemaVersion":1,"task":"M16-GAP-00271","operation":"ASSET_CATALOG_REDO_DESKTOP","fixture":str(fixture),"fixtureSha256":hashlib.sha256(fixture.read_bytes()).hexdigest(),"before":before,"after":after,"poll":poll,"operatorStatus":status,"mainMutation":"NONE","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")
|
|
print("asset-catalog-redo-desktop-ok poll=false status=CANCELLED mainMutation=none saveReopen=exact")
|
|
|
|
if __name__ == "__main__":
|
|
try: main()
|
|
except Exception as e: print(f"asset-catalog-redo-desktop-failed: {e}"); raise SystemExit(1)
|