""" Dump the complete folder tree structure of a working mapping to understand how input actions are stored. """ import grpc import sys import io import json sys.path.append(r'C:\DEV\COPILOT\geutebruck-api\src\api') if sys.platform == 'win32': sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8') from protos import configuration_pb2 from protos import configuration_pb2_grpc print("="*70) print("DUMPING WORKING MAPPING STRUCTURE") print("="*70) channel = grpc.insecure_channel('localhost:50051') stub = configuration_pb2_grpc.ConfigurationServiceStub(channel) # Export full configuration as JSON to examine structure print("\n1. Exporting configuration as JSON...") export_request = configuration_pb2.ExportJsonRequest() export_response = stub.ExportConfigurationJson(export_request) if not export_response.success: print(f" [ERROR] {export_response.error_message}") sys.exit(1) print(f" JSON size: {export_response.json_size} bytes") # Parse JSON config = json.loads(export_response.json_data) # Find MappingRules if "children" in config: for child in config["children"]: if child.get("name") == "MappingRules" and child.get("type") == "folder": print("\n2. Found MappingRules folder") mapping_rules = child # Look for a working mapping (one with "CrossSwitch" in the name) if "children" in mapping_rules: for rule in mapping_rules["children"]: if rule.get("type") == "folder": # Get the caption (@ field) caption = None if "children" in rule: for field in rule["children"]: if field.get("name") == "@" and field.get("type") == "string": caption = field.get("stringValue") break # If this looks like a working mapping (has "CrossSwitch" or "M") if caption and ("CrossSwitch" in caption or "C_" in caption): print(f"\n3. Found working mapping: '{caption}'") print(f" Rule ID: {rule.get('name')}") print(f"\n Complete structure:") print(json.dumps(rule, indent=2)) # Also print a simplified view print(f"\n Simplified field list:") if "children" in rule: for field in rule["children"]: field_type = field.get("type") field_name = field.get("name") if field_type == "folder": print(f" - {field_name}/ (folder with {len(field.get('children', []))} children)") elif field_type == "string": print(f" - {field_name} = \"{field.get('stringValue')}\"") elif field_type == "int32": print(f" - {field_name} = {field.get('intValue')}") else: print(f" - {field_name} ({field_type})") print("\n" + "="*70) print("DONE - Examine the structure above") print("="*70) sys.exit(0) print("\n[WARNING] No working mapping found with 'CrossSwitch' in name") print("Listing all mappings:") if "children" in mapping_rules: for rule in mapping_rules["children"]: if rule.get("type") == "folder": caption = None if "children" in rule: for field in rule["children"]: if field.get("name") == "@" and field.get("type") == "string": caption = field.get("stringValue") break print(f" - Rule {rule.get('name')}: {caption}") print("\n[ERROR] MappingRules folder not found")