Capture M16 gap execution artifacts
This commit is contained in:
98
tools/web/check-action-driver-button-add-desktop.py
Normal file
98
tools/web/check-action-driver-button-add-desktop.py
Normal file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python3
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
def driver_report(obj):
|
||||
if obj is None or obj.animation_data is None:
|
||||
return []
|
||||
drivers = []
|
||||
for curve in obj.animation_data.drivers:
|
||||
driver = curve.driver
|
||||
drivers.append(
|
||||
{
|
||||
"path": curve.data_path,
|
||||
"index": curve.array_index,
|
||||
"expression": driver.expression if driver else "",
|
||||
"type": driver.type if driver else "",
|
||||
"variableCount": len(driver.variables) if driver else 0,
|
||||
}
|
||||
)
|
||||
drivers.sort(key=lambda value: (value["path"], value["index"]))
|
||||
return drivers
|
||||
|
||||
|
||||
def state_report(obj):
|
||||
if obj is None:
|
||||
raise RuntimeError("driver-button-add fixture object is missing")
|
||||
return {"drivers": driver_report(obj), "value": round(float(obj["drive_target"]), 6)}
|
||||
|
||||
|
||||
def main():
|
||||
arguments = sys.argv[sys.argv.index("--") + 1 :]
|
||||
if len(arguments) != 2:
|
||||
raise SystemExit(
|
||||
"usage: blender -b --python check-action-driver-button-add-desktop.py -- FIXTURE REPORT"
|
||||
)
|
||||
fixture, output = (pathlib.Path(value).resolve() for value in arguments)
|
||||
output.unlink(missing_ok=True)
|
||||
bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=False)
|
||||
obj = bpy.data.objects.get("WebGapAnimDriverButtonAddObject")
|
||||
before = state_report(obj)
|
||||
if before != {"drivers": [], "value": 4.5}:
|
||||
raise RuntimeError(f"unexpected driver_button_add source state: {before}")
|
||||
|
||||
window = bpy.context.window
|
||||
screen = window.screen
|
||||
area = next(candidate for candidate in screen.areas if candidate.type == "PROPERTIES")
|
||||
region = next(candidate for candidate in area.regions if candidate.type == "WINDOW")
|
||||
with bpy.context.temp_override(window=window, screen=screen, area=area, region=region):
|
||||
poll = bool(bpy.ops.anim.driver_button_add.poll())
|
||||
if poll:
|
||||
raise RuntimeError("ANIM_OT_driver_button_add unexpectedly polled true without an active RNA button")
|
||||
after_cancel = state_report(obj)
|
||||
if after_cancel != before:
|
||||
raise RuntimeError(f"driver_button_add cancellation changed Main data: {before} != {after_cancel}")
|
||||
|
||||
descriptor, temporary = tempfile.mkstemp(prefix="m16-anim-driver-button-add-reopen-", suffix=".blend")
|
||||
os.close(descriptor)
|
||||
pathlib.Path(temporary).unlink(missing_ok=True)
|
||||
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 = state_report(bpy.data.objects.get("WebGapAnimDriverButtonAddObject"))
|
||||
finally:
|
||||
pathlib.Path(temporary).unlink(missing_ok=True)
|
||||
if before != after:
|
||||
raise RuntimeError("anim.driver_button_add save/reopen drift")
|
||||
report = {
|
||||
"schemaVersion": 1,
|
||||
"task": "M16-GAP-00174",
|
||||
"operation": "ANIM_DRIVER_BUTTON_ADD_DESKTOP",
|
||||
"fixture": str(fixture),
|
||||
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
|
||||
"drivers": after["drivers"],
|
||||
"value": after["value"],
|
||||
"poll": poll,
|
||||
"operatorStatus": "CANCELLED",
|
||||
"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", encoding="utf-8")
|
||||
print("anim-driver-button-add-desktop-ok poll=false status=CANCELLED mainMutation=none saveReopen=exact")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except Exception as error:
|
||||
print(f"anim-driver-button-add-desktop-failed: {error}")
|
||||
raise SystemExit(1)
|
||||
Reference in New Issue
Block a user