Files
workinf_Blender_Wasm/tools/web/check-action-armature-collection-move-desktop.py
mes123456 9f43244982
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
Continue Blender Web parity task handoff
2026-08-23 05:47:21 -04:00

125 lines
5.1 KiB
Python

#!/usr/bin/env python3
import hashlib
import json
import os
import pathlib
import shutil
import sys
import tempfile
import bpy
ARMATURE_NAME = "WebGapArmatureCollectionMoveArmature"
OBJECT_NAME = "WebGapArmatureCollectionMoveObject"
FIRST_COLLECTION = "WebGapArmatureCollectionMoveFirst"
ACTIVE_COLLECTION = "WebGapArmatureCollectionMoveActive"
LAST_COLLECTION = "WebGapArmatureCollectionMoveLast"
FIRST_BONE = "WebGapArmatureCollectionMoveFirstBone"
ACTIVE_BONE = "WebGapArmatureCollectionMoveActiveBone"
LAST_BONE = "WebGapArmatureCollectionMoveLastBone"
def state_report():
armature = bpy.data.armatures.get(ARMATURE_NAME)
obj = bpy.data.objects.get(OBJECT_NAME)
if armature is None or obj is None or obj.type != "ARMATURE" or obj.data != armature:
raise RuntimeError("armature.collection_move fixture is missing")
collections = []
for index, collection in enumerate(armature.collections):
collections.append({
"name": collection.name,
"index": index,
"bones": sorted(bone.name for bone in collection.bones),
})
return {
"object": OBJECT_NAME,
"armature": ARMATURE_NAME,
"activeIndex": armature.collections.active_index,
"collections": collections,
}
def run_operator(already_moved):
obj = bpy.data.objects[OBJECT_NAME]
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
armature = bpy.data.armatures[ARMATURE_NAME]
poll = bool(bpy.ops.armature.collection_move.poll())
if not poll:
raise RuntimeError("ARMATURE_OT_collection_move poll failed")
if not already_moved:
result = bpy.ops.armature.collection_move(direction="UP")
if result != {"FINISHED"}:
raise RuntimeError(f"ARMATURE_OT_collection_move returned {result}")
return poll, not already_moved
def main():
arguments = sys.argv[sys.argv.index("--") + 1 :]
if len(arguments) != 2:
raise SystemExit("usage: blender -b --factory-startup --python check-action-armature-collection-move-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 = state_report()
before_names = [collection["name"] for collection in before["collections"]]
if before_names == [ACTIVE_COLLECTION, FIRST_COLLECTION, LAST_COLLECTION] and before["activeIndex"] == 0:
already_moved = True
elif before_names == [FIRST_COLLECTION, ACTIVE_COLLECTION, LAST_COLLECTION] and before["activeIndex"] == 1:
already_moved = False
else:
raise RuntimeError(f"unexpected collection_move input: {before}")
poll, changed = run_operator(already_moved)
after = state_report()
after_names = [collection["name"] for collection in after["collections"]]
if after_names != [ACTIVE_COLLECTION, FIRST_COLLECTION, LAST_COLLECTION] or after["activeIndex"] != 0:
raise RuntimeError(f"collection_move produced unexpected order: {after}")
expected_members = {
FIRST_COLLECTION: [FIRST_BONE],
ACTIVE_COLLECTION: [ACTIVE_BONE],
LAST_COLLECTION: [LAST_BONE],
}
actual_members = {collection["name"]: collection["bones"] for collection in after["collections"]}
if actual_members != expected_members:
raise RuntimeError(f"collection_move changed collection membership: {after}")
descriptor, temporary = tempfile.mkstemp(prefix="m16-armature-collection-move-reopen-", suffix=".blend")
os.close(descriptor)
temporary_path = pathlib.Path(temporary)
try:
bpy.ops.wm.save_as_mainfile(filepath=str(temporary_path), check_existing=False, compress=True)
bpy.ops.wm.open_mainfile(filepath=str(temporary_path), load_ui=False)
reopened = state_report()
if reopened != after:
raise RuntimeError(f"armature.collection_move save/reopen drift: {after} != {reopened}")
shutil.copyfile(temporary_path, fixture)
report = {
"schemaVersion": 1,
"task": "M16-GAP-00225",
"operation": "ARMATURE_COLLECTION_MOVE_DESKTOP",
"fixture": str(fixture),
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
"before": before,
"after": reopened,
"direction": "UP",
"alreadyMoved": already_moved,
"poll": poll,
"operatorStatus": "FINISHED" if changed else "SKIPPED_ALREADY_APPLIED",
"mainMutation": "ACTIVE_COLLECTION_MOVED_UP" if changed else "ACTIVE_COLLECTION_ALREADY_MOVED_UP",
"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("armature-collection-move-desktop-ok poll=true direction=up activeIndex=0 saveReopen=exact")
finally:
temporary_path.unlink(missing_ok=True)
if __name__ == "__main__":
try:
main()
except Exception as error:
print(f"armature-collection-move-desktop-failed: {error}")
raise SystemExit(1)