Files
workinf_Blender_Wasm/tools/web/check-action-asset-library-reload-listing-desktop.py
mes123456 a081c68c87
Some checks are pending
M6 deployable RC / quick (push) Waiting to run
M6 deployable RC / chromium (push) Blocked by required conditions
M6 deployable RC / release (push) Blocked by required conditions
Reorganize Blender Web execution around capabilities
2026-08-24 18:37:46 -04:00

84 lines
3.1 KiB
Python

#!/usr/bin/env python3
import hashlib
import json
import pathlib
import sys
import tempfile
import bpy
def library_state():
libraries = list(bpy.data.libraries)
if len(libraries) != 1:
raise RuntimeError(f"expected one asset-library-reload-listing library, found {len(libraries)}")
library = libraries[0]
return {"name": library.name, "filepath": library.filepath, "packed": library.packed_file is not None}
def main():
arguments = sys.argv[sys.argv.index("--") + 1 :]
if len(arguments) != 2:
raise SystemExit(
"usage: blender -b --factory-startup --python "
"check-action-asset-library-reload-listing-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)
before = library_state()
try:
poll = bool(bpy.ops.asset.library_reload_listing.poll())
except RuntimeError as error:
if "context is incorrect" not in str(error) and "not a remote library" not in str(error):
raise
poll = False
if poll:
raise RuntimeError("asset.library_reload_listing unexpectedly polled true")
try:
bpy.ops.asset.library_reload_listing()
except RuntimeError as error:
if "context is incorrect" not in str(error) and "not a remote library" not in str(error):
raise
operator_status = "CANCELLED"
else:
raise RuntimeError("asset.library_reload_listing unexpectedly finished")
after_cancel = library_state()
if after_cancel != before:
raise RuntimeError(
f"asset.library_reload_listing cancellation changed Main data: {before} != {after_cancel}"
)
with tempfile.NamedTemporaryFile(
prefix="m16-asset-library-reload-listing-reopen-", suffix=".blend", dir=fixture.parent
) as temporary:
bpy.ops.wm.save_as_mainfile(filepath=temporary.name, check_existing=False, compress=True)
bpy.ops.wm.open_mainfile(filepath=temporary.name, load_ui=False)
after = library_state()
if after != before:
raise RuntimeError(f"asset.library_reload_listing save/reopen drift: {before} != {after}")
report = {
"schemaVersion": 1,
"task": "M16-GAP-00278",
"operation": "ASSET_LIBRARY_RELOAD_LISTING_DESKTOP",
"fixture": str(fixture),
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
"before": before,
"after": after,
"poll": poll,
"operatorStatus": operator_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", encoding="utf-8")
print("asset-library-reload-listing-desktop-ok poll=false status=CANCELLED mainMutation=none saveReopen=exact")
if __name__ == "__main__":
try:
main()
except Exception as error:
print(f"asset-library-reload-listing-desktop-failed: {error}")
raise SystemExit(1)