28 lines
2.1 KiB
Python
28 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
import hashlib,json,pathlib,sys,tempfile,bpy
|
|
def state():
|
|
if len(bpy.data.libraries)!=1: raise RuntimeError("catalog-undo 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_undo.poll())
|
|
except RuntimeError as e:
|
|
if not any(x in str(e) for x in accepted): raise
|
|
poll=False
|
|
if poll: raise RuntimeError("catalog_undo poll unexpectedly true")
|
|
try: bpy.ops.asset.catalog_undo()
|
|
except RuntimeError as e:
|
|
if not any(x in str(e) for x in accepted): raise
|
|
status="CANCELLED"
|
|
else: raise RuntimeError("catalog_undo unexpectedly finished")
|
|
if state()!=before: raise RuntimeError("catalog_undo mutated Main")
|
|
with tempfile.NamedTemporaryFile(prefix="m16-catalog-undo-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_undo save/reopen drift")
|
|
report={"schemaVersion":1,"task":"M16-GAP-00272","operation":"ASSET_CATALOG_UNDO_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-undo-desktop-ok poll=false status=CANCELLED mainMutation=none saveReopen=exact")
|
|
if __name__=="__main__":
|
|
try: main()
|
|
except Exception as e: print(f"asset-catalog-undo-desktop-failed: {e}"); raise SystemExit(1)
|