-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfinal_command_merge.py
More file actions
174 lines (142 loc) · 6.07 KB
/
final_command_merge.py
File metadata and controls
174 lines (142 loc) · 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import json
import os
def final_command_merge():
"""Final comprehensive merge of ALL command files"""
# Load current database
db_path = "resources/dataref_database.json"
with open(db_path, "r", encoding="utf-8") as f:
data = json.load(f)
current_commands = sum(1 for v in data.values() if v.get("type") == "command")
print(f"Starting with {current_commands} commands in database")
# Process ALL command files comprehensively
command_files = [
"XP12 dataref list and commands/Commands.txt",
"XP12 dataref list and commands/commands (2).txt",
]
total_added = 0
for file_path in command_files:
if not os.path.exists(file_path):
print(f"Skipping {file_path} - file not found")
continue
print(f"Processing {file_path}...")
added = 0
duplicate_count = 0
try:
with open(file_path, "r", encoding="utf-8") as f:
for line_num, line in enumerate(f, 1):
line = line.strip()
# Skip empty lines, headers, lines with pipes, digit-only lines
if (
not line
or line.startswith("#")
or "|" in line
or line.isdigit()
or not line.strip()
):
continue
# Determine command name based on format
if line.startswith("1-sim/"):
cmd_line = line[2:].strip() # Remove '1-' prefix
elif line.startswith("sim/") or line.startswith("1-sim/"):
cmd_line = line.strip()
else:
continue # Skip malformed lines
# Find first space to separate name from description
if " " in cmd_line:
first_space = cmd_line.find(" ")
name = cmd_line[:first_space].strip()
description = cmd_line[first_space:].strip()
else:
name = cmd_line
description = "Command" if not description else description
# Add to database if not already present
if name not in data:
data[name] = {
"name": name,
"type": "command",
"description": description,
"units": "",
"writable": False,
}
added += 1
if added <= 10: # Show first 10 additions per file
print(f" Added: {name}")
else:
duplicate_count += 1
print(
f"Added {added} commands, {duplicate_count} duplicates from {file_path}"
)
total_added += added
except Exception as e:
print(f"Error parsing {file_path}: {e}")
# Save updated database
print(f"\\nTotal new commands added: {total_added}")
print("Saving updated database...")
with open(db_path, "w", encoding="utf-8") as f:
json.dump(data, f, indent=2, sort_keys=True)
print("Database updated successfully!")
# Final verification
with open(db_path, "r", encoding="utf-8") as f:
updated_data = json.load(f)
final_commands = sum(1 for v in updated_data.values() if v.get("type") == "command")
final_total = len(updated_data)
print(f"\\n=== FINAL COMPREHENSIVE VERIFICATION ===")
print(f"Total entries: {final_total}")
print(
f"Total commands: {final_commands} (was {current_commands}, +{final_commands - current_commands})"
)
# Check for specific commands you wanted
target_commands = [
"sim/comm/AP/CMD_C",
"sim/comm/AP/CMD_L",
"sim/comm/AP/CMD_R",
"1-sim/MH/DoubleClickFromXP",
"1-sim/MH/LeftClickFromXP",
"1-sim/MH/RightClickFromXP",
"1-sim/MH/WheelIncDown",
"1-sim/MH/WheelIncMinus",
"1-sim/MH/WheelIncPlus",
"1-sim/MH/WheelIncUp",
"1-sim/MH/glewMode",
"1-sim/MH/mainTrigger",
"1-sim/MH/trimmer",
]
print("\\n=== CHECKING ALL TARGET COMMANDS ===")
found_count = 0
missing_count = 0
for cmd in target_commands:
if cmd in updated_data:
found_count += 1
entry = updated_data[cmd]
print(f"✅ FOUND: {cmd} -> {entry.get('description', 'N/A')}")
else:
missing_count += 1
print(f"❌ MISSING: {cmd}")
print(
f"\\nTARGET STATUS: {found_count}/{len(target_commands)} found, {missing_count} missing"
)
if missing_count > 0:
print("\\n⚠️ SOME TARGET COMMANDS STILL MISSING!")
print("The final merge should have included all commands.")
print("Let me check the command file format...")
# Check specific file for the missing ones
missing_file = "XP12 dataref list and commands/commands (2).txt"
if os.path.exists(missing_file):
print(f"\\nChecking {missing_file} for missing commands...")
with open(missing_file, "r", encoding="utf-8") as f:
for line_num, line in enumerate(f, 1):
if missing_count <= 0:
break
line = line.strip()
if not line or not line.startswith("1-sim/"):
continue
cmd_line = line[2:].strip()
first_space = cmd_line.find(" ")
name = cmd_line[:first_space].strip()
if name in target_commands and name not in updated_data:
print(f"Line {line_num}: {name} (MISSING from database)")
print(f"\\n=== FINAL RESULT ===")
print(f"Database now contains {final_commands} commands ready for use!")
return final_commands >= current_commands
if __name__ == "__main__":
final_command_merge()