1
- # Helper script for parsingt the header file of MEADE
2
- # Can be used to populate WIKI
1
+ """
2
+ Helper script for parsingt the header file of MEADE
3
+
4
+ USAGE:
5
+ - Ensure you have a Python interperter working for VSCode
6
+ - Execute this file by pressing the little green "Play" button in the top-right corner
7
+ - Output will be written to "./scripts/MeadeToWikiOutput.txt" directory
8
+ - Copy entire content of the file and paste it on the wiki page
9
+ """
3
10
4
11
import os
12
+ import re
5
13
6
14
MEADE_HPP = "..\\ src\\ MeadeCommandProcessor.cpp"
7
15
MODULE_PATH = os .path .dirname (os .path .realpath (__file__ ))
8
16
START_LINE = 0
9
17
END_LINE = 0
10
18
19
+
11
20
class Family :
12
21
def __init__ (self ):
13
22
self .name = None
@@ -16,15 +25,104 @@ def __init__(self):
16
25
17
26
class Command :
18
27
def __init__ (self ):
19
- self .command = None
20
- self .short = str ()
21
- self .long = str ()
22
- self .returns = str ()
28
+ self .__command = None
29
+ self .__description = str ()
30
+ self .__information = list ()
31
+ self .__returns = list ()
32
+ self .__parameters = list ()
33
+ self .__remarks = list ()
34
+ self .__example = list ()
35
+
36
+ def set_data (self , attribute , data ):
37
+ setattr (self , attribute , data )
38
+
39
+ @property
40
+ def command (self ):
41
+ return self .__command
42
+
43
+ @command .setter
44
+ def command (self , val ):
45
+ self .__command = val
46
+
47
+ @property
48
+ def description (self ):
49
+ return self .__description
50
+
51
+ @description .setter
52
+ def description (self , val ):
53
+ self .__description = val
54
+
55
+ @property
56
+ def information (self ):
57
+ return self .__information
58
+
59
+ @information .setter
60
+ def information (self , val ):
61
+ if val not in self .__information :
62
+ self .__information .append (val )
63
+
64
+ @property
65
+ def returns (self ):
66
+ return self .__returns
67
+
68
+ @returns .setter
69
+ def returns (self , val ):
70
+ if val not in self .__returns :
71
+ self .__returns .append (val )
72
+
73
+ @property
74
+ def parameters (self ):
75
+ return self .__parameters
76
+
77
+ @parameters .setter
78
+ def parameters (self , val ):
79
+ if val not in self .__parameters :
80
+ self .__parameters .append (val )
81
+
82
+ @property
83
+ def remarks (self ):
84
+ return self .__remarks
85
+
86
+ @remarks .setter
87
+ def remarks (self , val ):
88
+ if val not in self .__remarks :
89
+ self .__remarks .append (val )
90
+
91
+ @property
92
+ def example (self ):
93
+ return self .__example
94
+
95
+ @example .setter
96
+ def example (self , val ):
97
+ if val not in self .__example :
98
+ self .__example .append (val )
99
+
100
+
101
+ command_sepparators = ["Description::" ,
102
+ "Information:" ,
103
+ "Returns:" ,
104
+ "Parameters:" ,
105
+ "Remarks:" ,
106
+ "Remarks:" ,
107
+ "Example:" ,
108
+ "//" ]
109
+
110
+
111
+ def remove_line_prefix (line ):
112
+ striped_line = line .replace ("//" , "" ).lstrip ()
113
+ striped_line = striped_line .replace ("\" " , "`" )
114
+ return striped_line
23
115
24
- def removeLinePrefix (line ):
25
- return line .replace ("// " , "" ).strip ()
116
+ def check_command_sepparator (line ):
117
+ striped_line = line .replace ("//" , "" ).lstrip ()
118
+ if line in command_sepparators :
119
+ return True
120
+ elif line .startswith ("//" ) and striped_line in command_sepparators :
121
+ return True
122
+ else :
123
+ return False
26
124
27
- #Meade hpp File
125
+ # Meade hpp File
28
126
with open (os .path .join (MODULE_PATH , MEADE_HPP )) as f :
29
127
content = f .readlines ()
30
128
content = [x .strip () for x in content ]
@@ -40,75 +138,165 @@ def removeLinePrefix(line):
40
138
raise Exception ("Could not locate start and stop of comment block." )
41
139
42
140
START_LINE = startStop [0 ]
43
- END_LINE = startStop [1 ]
141
+ END_LINE = startStop [1 ]
44
142
45
143
print (("Start and end of block: {0}, {1} " .format (START_LINE , END_LINE )))
46
144
47
- familyDividers = []
145
+ family_dividers = []
48
146
for i in range (START_LINE , END_LINE ):
49
147
for div in ["//------------------------------------------------------------------" , "// --" ]:
50
148
if div in content [i ]:
51
- familyDividers .append (i )
149
+ family_dividers .append (i )
52
150
53
- print (("Found {0} family groups " .format (len (familyDividers ))))
151
+ print (("Found {0} family groups " .format (len (family_dividers ))))
54
152
55
- allCommands = []
56
- for i in range (len (familyDividers ) - 1 ):
57
- start = familyDividers [i ]
58
- end = familyDividers [i + 1 ]
153
+ all_commands = []
154
+ for i in range (len (family_dividers ) - 1 ):
155
+ #for i in range(0, 6):
156
+ start = family_dividers [i ] + 1
157
+ end = family_dividers [i + 1 ]
158
+
159
+ new_family = Family ()
160
+ new_family .name = remove_line_prefix (content [start ])
161
+
162
+ # Find command groups
163
+ sub_offsets = list ()
164
+ sub_offsets .append (start + 2 )
165
+ for j in range (start + 2 , end ):
166
+ if content [j ] == "//" :
167
+ sub_offsets .append (j )
59
168
60
- newFamily = Family ()
61
- if "//------------------------------------------------------------------" in content [start ]:
62
- newFamily .name = removeLinePrefix (content [start + 1 ])
63
- elif "// --" in content [start ]:
64
- nameCleanup = content [start ].replace ("// -- " , "" )
65
- nameCleanup = nameCleanup .replace (" --" , "" )
66
- newFamily .name = nameCleanup
67
-
68
- for y in range (start + 1 , end - 1 ):
69
- newCommand = Command ()
70
-
71
- # Command
72
- if content [y ].startswith ("// :" ):
73
- newCommand .command = removeLinePrefix (content [y ])
74
-
75
- # Short Description
76
- newCommand .short = removeLinePrefix (content [y + 1 ])
77
- y += 2
78
-
79
- k = y
80
- while not content [k ].startswith ("// Returns:" ):
81
- newCommand .long += removeLinePrefix (content [k ])
82
- k += 1
83
- y = k
169
+ for k in range (0 , len (sub_offsets )- 1 ):
170
+ command = Command ()
171
+ sub_start = sub_offsets [k ]
172
+ sub_end = sub_offsets [k + 1 ]
84
173
174
+ for l in range (sub_start , sub_end ):
175
+ if content [l ] == "//" :
176
+ continue
177
+
178
+ # Command
179
+ if content [l ].startswith ("// :" ):
180
+ command .command = remove_line_prefix (content [l ])
181
+
182
+ # Description
183
+ if content [l ].startswith ("//" ) and "Description:" in content [l ]:
184
+ command .description = remove_line_prefix (content [l + 1 ])
185
+
186
+ # Information
187
+ if content [l ].startswith ("//" ) and "Information:" in content [l ]:
188
+ m = l + 1
189
+ while not check_command_sepparator (content [m ]):
190
+ command .information = remove_line_prefix (content [m ])
191
+ m += 1
192
+ l = m
193
+
194
+ # Returns
195
+ if content [l ].startswith ("//" ) and "Returns:" in content [l ]:
196
+ m = l + 1
197
+ while not check_command_sepparator (content [m ]):
198
+ command .returns = remove_line_prefix (content [m ])
199
+ m += 1
200
+ l = m
201
+
202
+ # Remarks
203
+ if content [l ].startswith ("//" ) and "Remarks:" in content [l ]:
204
+ m = l + 1
205
+ while not check_command_sepparator (content [m ]):
206
+ command .remarks = remove_line_prefix (content [m ])
207
+ m += 1
208
+ l = m
209
+
210
+ # Parameters
211
+ if content [l ].startswith ("//" ) and "Parameters:" in content [l ]:
212
+ m = l + 1
213
+ while not check_command_sepparator (content [m ]):
214
+ command .parameters = remove_line_prefix (content [m ])
215
+ m += 1
216
+ l = m
217
+
218
+ # Example
219
+ if content [l ].startswith ("//" ) and "Example:" in content [l ]:
220
+ m = l + 1
221
+ while not check_command_sepparator (content [m ]):
222
+ command .example = remove_line_prefix (content [m ])
223
+ m += 1
224
+ l = m
85
225
86
- if content [y ].startswith ("// Returns:" ):
87
- newCommand .returns += content [y ].replace ("// Returns: " , "" )
88
- k = y + 1
89
- while content [k ] != "//" :
90
- newCommand .returns += content [k ].replace ("// " , " " ).strip ()
91
- k += 1
92
- y = k
93
-
94
- if newCommand .command :
95
- newFamily .commands .append (newCommand )
226
+ new_family .commands .append (command )
227
+ all_commands .append (new_family )
228
+
229
+ def output_wiki ():
230
+ """
231
+ Writes content to a MeadeToWikiOutput.txt file
232
+ """
96
233
97
- allCommands .append (newFamily )
234
+ f = open ("./scripts/MeadeToWikiOutput.txt" , "w" )
235
+
236
+ for fam in all_commands :
237
+ f .write (f"## { fam .name } \n " )
238
+ f .write ("<br>\n \n " )
239
+
240
+ for cmd in fam .commands :
241
+ f .write (f"### { cmd .description } \n " )
242
+
243
+ if cmd .information :
244
+ #f.write("**Information:**\n")
245
+ for line in cmd .information :
246
+ f .write (f"{ line } " )
247
+ f .write ("\n \n " )
248
+
249
+ f .write (f"**Command:**\n " )
250
+ f .write (f"`{ cmd .command } `\n " )
251
+ f .write ("\n " )
252
+
253
+ f .write ("**Returns:**\n " )
254
+ for line in cmd .returns :
255
+ f .write (f"- { line } \n " )
256
+ f .write ("\n " )
257
+
258
+ if cmd .parameters :
259
+ f .write ("**Parameters:**\n " )
260
+ for param in cmd .parameters :
261
+ f .write (f"- { param } \n " )
262
+ f .write ("\n " )
98
263
264
+ if cmd .remarks :
265
+ f .write ("**Remarks:**\n " )
266
+ for param in cmd .remarks :
267
+ f .write (f"{ param } \n " )
268
+ f .write ("\n " )
99
269
100
- # Example of printing output
101
- for fam in allCommands :
102
- print ("***** {0} *****" .format (fam .name ))
103
- print ("Command Count: {0}" .format (len (fam .commands )))
270
+ if cmd .example :
271
+ f .write ("**Example:**\n " )
272
+ for param in cmd .example :
273
+ f .write (f"- { param } \n " )
274
+ f .write ("\n " )
275
+
276
+ f .write ("<br>" )
277
+ f .write ("\n " )
278
+ f .write ("\n " )
279
+
280
+ f .write ("\n \n " )
281
+
282
+ f .close ()
283
+ print ("File written to: ./scripts/MeadeToWikiOutput.txt" )
284
+
285
+ if __name__ == "__main__" :
286
+ output_wiki ()
287
+
288
+ """
289
+ # Output Excample
290
+ for fam in all_commands:
291
+ print("-----")
292
+ print(fam.name)
104
293
for cmd in fam.commands:
105
- print ("\t Command: {0}" .format (cmd .command ))
106
- print ("\t Short: {0}" .format (cmd .short ))
107
- print ("\t Long Description: {0}" .format (cmd .long ))
108
- print ("\t Returns: {0}" .format (cmd .returns ))
109
- print ("\r " )
110
-
111
- print ("Family Count: {0}" .format (len (allCommands )))
112
- for fam in allCommands :
113
- print ("{0}" .format (fam .name ))
114
- print ("\t {0}" .format (len (fam .commands )))
294
+ print("############################")
295
+ print(f"Command: {cmd.command}")
296
+ print(f"Description: {cmd.description}")
297
+ print(f"Information: {cmd.information}")
298
+ print(f"Returns: {cmd.returns}")
299
+ print(f"Parameters: {cmd.parameters}")
300
+ print(f"Remarks: {cmd.remarks}")
301
+
302
+ """
0 commit comments