Files
workinf_Blender_Wasm/tools/web/check-text-desktop.py
mes123456 10640aeb3c
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
Govern task context and advance execution pointer
2026-08-20 06:02:43 -04:00

56 lines
2.1 KiB
Python

#!/usr/bin/env python3
import hashlib
import json
import os
import pathlib
import sys
import tempfile
import bpy
def report():
text = bpy.data.texts.get("WebGapText")
if text is None:
raise RuntimeError("WebGapText is missing")
source = text.as_string()
return {
"id": "text:" + text.name,
"name": text.name,
"source": source,
"sourceSha256": hashlib.sha256(source.encode("utf-8")).hexdigest(),
"byteLength": len(source.encode("utf-8")),
"lineCount": len(source.splitlines()) + (1 if source.endswith("\n") else 0),
"sourcePath": text.filepath,
"internal": not bool(text.filepath),
"isDirty": text.is_dirty,
"useModule": text.use_module,
}
def main():
arguments = sys.argv[sys.argv.index("--") + 1 :]
if len(arguments) != 2:
raise SystemExit("usage: blender -b --python check-text-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 = report()
descriptor, temporary = tempfile.mkstemp(prefix="m16-text-reopen-", suffix=".blend", dir=fixture.parent)
os.close(descriptor)
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 = report()
finally:
pathlib.Path(temporary).unlink(missing_ok=True)
if before != after:
raise RuntimeError(f"text save/reopen drift: {before} != {after}")
value = {"schemaVersion": 1, "task": "M16-GAP-00024", "operation": "TEXT_DATABLOCK_DESKTOP", "fixture": str(fixture), "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "text": after, "saveReopen": "EXACT", "blenderVersion": bpy.app.version_string}
output.parent.mkdir(parents=True, exist_ok=True)
output.write_text(json.dumps(value, indent=2, sort_keys=True) + "\n", encoding="utf-8")
print(f"text-desktop-ok id={after['id']} bytes={after['byteLength']} saveReopen=exact")
if __name__ == "__main__":
main()