-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonkModule.py
371 lines (329 loc) · 11.3 KB
/
monkModule.py
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#!/usr/bin/python
import sys
import os
import inspect
import fnmatch
import monkDebug as debug
import monkTools as tools
import monkNode as Node
import monkParse as Parse
import monkHtml
import re
import json
class Module:
##
## @brief Module class represent all system needed for a specific
## module like
## - type (bin/lib ...)
## - dependency
## - flags
## - files
## - ...
##
def __init__(self, file, moduleName, moduleType):
## Remove all variable to prevent error of multiple deffinition of the module ...
self.origin_file=''
self.origin_folder=''
# type of the module:
self.type='LIBRARY'
# Name of the module
self.name=moduleName
self.list_doc_file = []
self.list_tutorial_file = []
self.web_site = ""
self.web_source = ""
self.path_parsing = ""
self.path_global_doc = ""
self.external_link = []
self.title = moduleName + " Library"
self.style_html = ""
## end of basic INIT ...
if moduleType.upper() == 'APPLICATION':
self.type = 'application'
elif moduleType.upper() == 'LIBRARY':
self.type = "library"
else :
debug.error('for module "%s"' %moduleName)
debug.error(' ==> error : "%s" ' %moduleType)
raise 'Input value error'
self.structure_lib = Node.MainNode(self.type, moduleName)
self.origin_file = file;
self.origin_folder = tools.get_current_path(self.origin_file)
##
## @brief Set the module web_site (activate only when compile in release mode, else "../moduleName/)
## @param[in] url New web_site url
##
def set_website(self, url):
self.web_site = url
def get_website(self):
return self.web_site
def set_website_sources(self, url):
self.web_source = url
def get_website_sources(self):
return self.web_source
##
## @brief set the parsing folder
## @param[in] path New path to parse
##
def set_path(self, path):
self.path_parsing = path
##
## @brief set the glabal documentation parsing folder
## @param[in] path New path to parse
##
def set_path_general_doc(self, path):
self.path_global_doc = path
##
## @brief List of validate external library link (disable otherwise)
## @param[in] availlable List of all module link availlable
##
def set_external_link(self, availlable):
self.external_link = availlable
##
## @brief Set the library title
## @param[in] title New title to set.
##
def set_title(self, title):
self.title = title
##
## @brief new html basic css file
## @param[in] file File of the css style sheet
##
def set_html_css(self, cssFile):
self.style_html = cssFile
##
## @brief Create the module documentation:
##
def parse_code(self):
debug.info('Parse documantation code : ' + self.name)
if self.path_parsing != "":
for root, dirnames, filenames in os.walk(self.path_parsing):
tmpList = fnmatch.filter(filenames, "*.hpp")
# Import the module :
for filename in tmpList:
fileCompleteName = os.path.join(root, filename)
debug.debug(" Find a file : '" + fileCompleteName + "'")
self.add_file(fileCompleteName)
# all file is parset ==> now we create the namespacing of all elements:
self.structure_lib.set_namespace()
self.structure_lib.set_module_link(self)
#self.structure_lib.complete_display()
# display the hierarchie of all the class and namespace ...
#self.structure_lib.debug_display()
if self.path_global_doc != "":
for root, dirnames, filenames in os.walk(self.path_global_doc):
tmpList = fnmatch.filter(filenames, "*.md")
# Import the module :
for filename in tmpList:
fileCompleteName = os.path.join(root, filename)
tutorialPath = os.path.join(self.path_global_doc, "tutorial/")
pathBase = fileCompleteName[len(self.path_global_doc):len(fileCompleteName)-3]
while len(pathBase) > 0 \
and pathBase[0] == '/':
pathBase = pathBase[1:]
debug.verbose(" Find a doc file : fileCompleteName='" + fileCompleteName + "'")
if fileCompleteName[:len(tutorialPath)] == tutorialPath:
debug.warning("add_tutorial_doc : '" + fileCompleteName + "' ==> '" + pathBase + "'")
self.add_tutorial_doc(fileCompleteName, pathBase)
else:
debug.warning("add_file_doc : '" + fileCompleteName + "' ==> '" + pathBase + "'")
self.add_file_doc(fileCompleteName, pathBase)
##
## @brief Sort a list of n element containing a list of element (order with the first)
## @param[in] value List to order
## @return ordered list
##
def sort_list_first_elem(self, value):
# order the list:
order_elem = []
for elem in value:
order_elem.append(elem[0])
order_elem.sort()
out = []
for elem in order_elem:
for old_val in value:
if elem == old_val[0]:
out.append(old_val)
break;
return out
##
## @brief Add a documentation file at the parsing system
## @param[in] filename File To add at the parsing element system.
## @param[in] outPath output system file.
## @return True if no error occured, False otherwise
##
def add_file_doc(self, filename, outPath):
debug.debug("adding file in documantation : '" + filename + "'");
done = False
for iii in range(0,len(self.list_doc_file)):
if self.list_doc_file[iii][0] > filename:
self.list_doc_file.insert(iii, [filename, outPath])
done = True
break
if done == False:
self.list_doc_file.append([filename, outPath])
self.list_doc_file = self.sort_list_first_elem(self.list_doc_file)
##
## @brief Add a documentation file at the parsing system
## @param[in] filename File To add at the parsing element system.
## @param[in] outPath output system file.
## @return True if no error occured, False otherwise
##
def add_tutorial_doc(self, filename, outPath):
count = int(filename.split('/')[-1].split('_')[0])
debug.debug("adding file in documantation : '" + filename + "'");
done = False
for iii in range(0,len(self.list_tutorial_file)):
if self.list_tutorial_file[iii][0] > filename:
self.list_tutorial_file.insert(iii, [filename, outPath])
done = True
break
if done == False:
self.list_tutorial_file.append([filename, outPath])
self.list_tutorial_file = self.sort_list_first_elem(self.list_tutorial_file)
##
## @brief Add a file at the parsing system
## @param[in] filename File To add at the parsing element system.
## @return True if no error occured, False otherwise
##
def add_file(self, filename):
debug.debug("adding file in documantation : '" + filename + "'");
#parsedFile = Parse.parse_file("Widget.h")
#debug.error("plop")
parsedFile = Parse.parse_file(filename)
self.structure_lib = parsedFile.fusion(self.structure_lib)
return True
##
## @brief Generate Documentation at the folder ...
## @param[in] destFolder Destination folder.
## @param[in] mode (optinnal) generation output mode {html, markdown ...}
##
def generate(self):
debug.info('Generate documantation code : ' + self.name)
#json_data = json.dumps(self, sort_keys=True, indent=4)
#tools.file_write_data(os.path.join("out", "doc", self.name + ".json"), json_data)
destFolder = os.path.join("out", "doc", self.name)
tools.remove_folder_and_sub_folder(destFolder);
if monkHtml.generate(self, destFolder + '/') == False:
debug.warning("Generation Documentation ==> return an error for " + self.name)
def get_base_doc_node(self):
return self.structure_lib
##
## @brief Get the heritage list (parent) of one element.
## @param[in] element Element name.
## @return List of all element herited
##
def get_heritage_list(self, element):
list = []
# get element class :
if element in self.list_class.keys():
localClass = self.list_class[element]
if len(localClass['inherits']) != 0:
# TODO : Support multiple heritage ...
isFirst = True
for heritedClass in localClass['inherits']:
if isFirst == True:
list = self.get_heritage_list(heritedClass['class'])
break;
debug.verbose("find parent : " + element)
list.append(element);
return list
##
## @brief Get the heritage list (child) of this element.
## @param[in] curentClassName Element name.
## @return List of all childs
##
def get_down_heritage_list(self, curentClassName):
list = []
# get element class :
for element in self.list_class:
localClass = self.list_class[element]
if len(localClass['inherits']) != 0:
for heritedClass in localClass['inherits']:
if curentClassName == heritedClass['class']:
list.append(element)
break;
debug.verbose("find childs : " + str(list))
return list
def get_whith_specific_parrent(self, name, appName=None):
if self.structure_lib.get_node_type() == "library":
return self.structure_lib.get_whith_specific_parrent(name)
if appName != self.structure_lib.get_name():
return []
return self.structure_lib.get_whith_specific_parrent(name)
moduleList=[]
__startModuleName="monk_"
def import_path(path):
global moduleList
matches = []
debug.debug('Start find sub File : "%s"' %path)
for root, dirnames, filenames in os.walk(path):
tmpList = fnmatch.filter(filenames, __startModuleName + "*.py")
# Import the module :
for filename in tmpList:
debug.debug(' Find a file : "%s"' %os.path.join(root, filename))
#matches.append(os.path.join(root, filename))
sys.path.append(os.path.dirname(os.path.join(root, filename)) )
moduleName = filename.replace('.py', '')
moduleName = moduleName.replace(__startModuleName, '')
debug.debug("integrate module: '" + moduleName + "' from '" + os.path.join(root, filename) + "'")
theModule = __import__(__startModuleName + moduleName)
tmpElement = theModule.create()
try:
tmpdesc = theModule.get_desc()
except:
tmpdesc = ""
if (tmpElement == None) :
debug.warning("Request load module '" + name + "' not define for this platform")
moduleList.append({"name":moduleName, "path":os.path.join(root, filename), "node":tmpElement, "desc":tmpdesc})
def get_module(name):
global moduleList
for mod in moduleList:
if mod["name"] == name:
return mod["node"]
return None
def get_all_module():
global moduleList
AllList = []
for mod in moduleList:
AllList.append(mod["node"])
return AllList
def list_all_module_with_desc():
global moduleList
tmpList = []
for mod in moduleList:
tmpList.append([mod["name"], mod["desc"]])
return tmpList
def get_link_type(type):
return ""
def get_element_with_name(type):
global moduleList
debug.verbose("try find : " + str(type) + " ")
ret = re.sub(r'::', ':', type)
ret = ret.split(":")
for mod in moduleList:
element = mod['node'].get_base_doc_node().find(ret)
if element != None:
debug.debug("we find : " + type + " = " + str(ret) + " " + str(element))
return element
debug.debug("we not find : " + type + " = " + str(ret))
return None
def get_whith_specific_parrent(name, appName=None):
global moduleList
ret = []
for mod in moduleList:
tmpRet = mod['node'].get_whith_specific_parrent(name, appName)
if len(tmpRet) != 0:
for tmp in tmpRet:
ret.append(tmp)
return ret
def display_color(val):
# storage keyword :
val = re.sub(r'(inline|const|class|virtual|private|public|protected|friend|const|extern|auto|register|static|volatile|typedef|struct|union|enum)',
r'<span class="code-storage-keyword">\1</span>',
val)
# type :
val = re.sub(r'(bool|BOOL|char(16_t|32_t)?|double|float|u?int(8|16|32|64|128)?(_t)?|long|short|signed|size_t|unsigned|void|(I|U)(8|16|32|64|128))',
r'<span class="code-type">\1</span>',
val)
return val