"""Prepare a real quit.blend through the original GUI Blender exit lifecycle.""" import argparse, hashlib, json, pathlib, sys import bpy assert not bpy.app.background and bpy.app.version == (5, 2, 0) parser = argparse.ArgumentParser() parser.add_argument('--input', required=True); parser.add_argument('--work-dir', required=True) args = parser.parse_args(sys.argv[sys.argv.index('--') + 1:]) work = pathlib.Path(args.work_dir).resolve(); work.mkdir(parents=True, exist_ok=False) input_path = pathlib.Path(args.input).resolve() input_sha256 = hashlib.sha256(input_path.read_bytes()).hexdigest() assert bpy.ops.wm.open_mainfile(filepath=str(input_path), load_ui=False, use_scripts=False) == {'FINISHED'} assert bpy.ops.file.pack_all() == {'FINISHED'} temporary = work / 'native-temp'; temporary.mkdir() bpy.context.preferences.filepaths.temporary_directory = str(temporary) working_blend = work / 'source-session.blend' assert bpy.ops.wm.save_as_mainfile(filepath=str(working_blend), relative_remap=True, check_existing=False) == {'FINISHED'} assert 'wbv2_last_session_unsaved' not in bpy.context.scene bpy.context.scene['wbv2_last_session_unsaved'] = input_sha256 snapshot = {'filepath': bpy.data.filepath, 'scene': bpy.context.scene.name, 'marker': bpy.context.scene['wbv2_last_session_unsaved'], 'objects': sorted(obj.name for obj in bpy.data.objects), 'images': {image.name: {'pixels': list(image.pixels[:4]), 'size': list(image.size), 'packed': bool(image.packed_file)} for image in bpy.data.images if image.source == 'FILE'}} assert snapshot['images'] and all(image['packed'] and image['pixels'] and min(image['size']) > 0 for image in snapshot['images'].values()) assert hashlib.sha256(input_path.read_bytes()).hexdigest() == input_sha256 (work / 'native-last-session-expected.json').write_text(json.dumps({'schemaVersion': 1, 'kind': 'source-derived-original-native-exit', 'phase': 'EXPECTED_STATE_WRITTEN_QUIT_PENDING', 'inputSha256': input_sha256, 'producerSha256': hashlib.sha256(pathlib.Path(__file__).read_bytes()).hexdigest(), 'version': list(bpy.app.version), 'platform': sys.platform, 'quitFile': str(temporary / 'quit.blend'), 'expectedMain': snapshot}, indent=2)) print('WBV2_NATIVE_QUIT_EXPECTED', str(work / 'native-last-session-expected.json'), flush=True) assert bpy.ops.wm.quit_blender('EXEC_DEFAULT') == {'FINISHED'}