""" Create a test mapping using the Python parser (working implementation) Then import it into GeViSet to verify it works """ import sys sys.path.append(r'C:\DEV\COPILOT_codex') from geviset_parser import load_set, save_set from pathlib import Path # Load the current configuration set_file = Path(r"C:\DEV\COPILOT_codex\TestMKS.set") tree = load_set(set_file) # Navigate to MappingRules mapping_rules = None for child in tree.get("children", []): if child.get("name") == "MappingRules" and child.get("type") == "folder": mapping_rules = child break if not mapping_rules: print("ERROR: MappingRules folder not found!") sys.exit(1) print(f"Found MappingRules with {len(mapping_rules.get('children', []))} existing rules") # Find the highest rule ID max_id = 0 for child in mapping_rules.get("children", []): if child.get("type") == "folder": try: rule_id = int(child.get("name", "0")) if rule_id > max_id: max_id = rule_id except: pass new_id = str(max_id + 1) print(f"Creating new rule with ID: {new_id}") # Create a new mapping rule with COMPLETE structure (matching working mappings) new_rule = { "type": "folder", "name": new_id, "children": [ # FILTERS (boolean fields starting with '.') {"type": "bool", "name": ".SwitchMode", "value": False}, {"type": "bool", "name": ".VideoInput", "value": True}, # Enable VideoInput {"type": "bool", "name": ".VideoOutput", "value": False}, # Caption and flags {"type": "string", "name": "@", "value": "PYTHON_TEST_MAPPING"}, {"type": "int32", "name": "@!", "value": 0}, {"type": "int32", "name": "@@", "value": 0}, # Rules folder (output actions) { "type": "folder", "name": "Rules", "children": [ # Output action 1 { "type": "folder", "name": "0", "children": [ {"type": "string", "name": "@", "value": "Test GCoreDataBase"}, {"type": "int32", "name": "@!", "value": 0}, {"type": "int32", "name": "@@", "value": 0}, {"type": "string", "name": "GCoreAction", "value": "GCoreDataBase"}, {"type": "string", "name": "GCoreServer", "value": ""} ] } ] }, # ACTUAL FIELD VALUES (after Rules) {"type": "int32", "name": "SwitchMode", "value": 0}, {"type": "int32", "name": "VideoInput", "value": 101027}, {"type": "int32", "name": "VideoOutput", "value": 0} ] } # Add to MappingRules mapping_rules["children"].append(new_rule) # Save to a new file output_file = Path(r"C:\DEV\COPILOT\TestMKS_with_python_test.set") save_set(tree, output_file) print(f"\nSUCCESS! Created new .set file with test mapping:") print(f" Output file: {output_file}") print(f" Rule ID: {new_id}") print(f" Caption: PYTHON_TEST_MAPPING") print(f" VideoInput: 101027") print(f"\nNow import this .set file into GeViSet and check if you can see 'PYTHON_TEST_MAPPING'")