monk/monkModule.py

327 lines
9.7 KiB
Python
Raw Normal View History

2013-12-22 18:55:48 +01:00
#!/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
2013-12-25 23:56:09 +01:00
import re
2013-12-22 18:55:48 +01:00
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.originFile=''
self.originFolder=''
# type of the module:
self.type='LIBRARY'
# Name of the module
self.name=moduleName
self.listDocFile = []
self.listTutorialFile = []
self.webSite = ""
2013-12-28 16:07:12 +01:00
self.webSource = ""
2013-12-22 18:55:48 +01:00
self.pathParsing = ""
self.pathGlobalDoc = ""
self.externalLink = []
self.title = moduleName + " Library"
self.styleHtml = ""
## end of basic INIT ...
if moduleType.upper() == 'APPLICATION':
self.type = 'application'
elif moduleType.upper() == 'LIBRARY':
self.type = "library"
2013-12-22 18:55:48 +01:00
else :
debug.error('for module "%s"' %moduleName)
debug.error(' ==> error : "%s" ' %moduleType)
raise 'Input value error'
self.structureLib = Node.MainNode(self.type, moduleName)
2013-12-22 18:55:48 +01:00
self.originFile = file;
self.originFolder = tools.get_current_path(self.originFile)
##
## @brief Set the module website (activate only when compile in release mode, else "../moduleName/)
## @param[in] url New Website url
##
def set_website(self, url):
self.webSite = url
2013-12-26 07:49:52 +01:00
def get_website(self):
return self.webSite
2013-12-28 16:07:12 +01:00
def set_website_sources(self, url):
self.webSource = url
def get_website_sources(self):
return self.webSource
2013-12-22 18:55:48 +01:00
##
## @brief set the parsing folder
## @param[in] path New path to parse
##
def set_path(self, path):
self.pathParsing = path
##
## @brief set the glabal documentation parsing folder
## @param[in] path New path to parse
##
def set_path_general_doc(self, path):
self.pathGlobalDoc = 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.externalLink = 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.styleHtml = cssFile
##
## @brief Create the module documentation:
##
def parse_code(self):
debug.info('Parse documantation code : ' + self.name)
if self.pathParsing != "":
for root, dirnames, filenames in os.walk(self.pathParsing):
tmpList = fnmatch.filter(filenames, "*.h")
# Import the module :
for filename in tmpList:
fileCompleteName = os.path.join(root, filename)
debug.debug(" Find a file : '" + fileCompleteName + "'")
self.add_file(fileCompleteName)
2013-12-26 07:49:52 +01:00
# all file is parset ==> now we create the namespacing of all elements:
2013-12-25 23:56:09 +01:00
self.structureLib.set_namespace()
2013-12-26 07:49:52 +01:00
self.structureLib.set_module_link(self)
#self.structureLib.complete_display()
2013-12-25 23:56:09 +01:00
2013-12-22 18:55:48 +01:00
# display the hierarchie of all the class and namespace ...
#self.structureLib.debug_display()
if self.pathGlobalDoc != "":
for root, dirnames, filenames in os.walk(self.pathGlobalDoc):
tmpList = fnmatch.filter(filenames, "*.bb")
# Import the module :
for filename in tmpList:
fileCompleteName = os.path.join(root, filename)
tutorialPath = os.path.join(self.pathGlobalDoc, "tutorial/")
debug.verbose(" Find a doc file : '" + fileCompleteName + "'")
pathBase = fileCompleteName[len(self.pathGlobalDoc):len(fileCompleteName)-3]
if fileCompleteName[:len(tutorialPath)] == tutorialPath:
self.add_tutorial_doc(fileCompleteName, pathBase)
2013-12-27 21:35:30 +01:00
else:
self.add_file_doc(fileCompleteName, pathBase)
2013-12-22 18:55:48 +01:00
##
## @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 + "'");
self.listDocFile.append([filename, outPath])
##
## @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):
debug.debug("adding file in documantation : '" + filename + "'");
self.listTutorialFile.append([filename, outPath])
##
## @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.structureLib = parsedFile.fusion(self.structureLib)
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)
destFolder = "out/doc/" + self.name + '/'
tools.remove_folder_and_sub_folder(destFolder);
2013-12-22 18:55:48 +01:00
if monkHtml.generate(self, destFolder) == False:
debug.warning("Generation Documentation ==> return an error for " + self.name)
def get_base_doc_node(self):
return self.structureLib
##
## @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.listClass.keys():
localClass = self.listClass[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.listClass:
localClass = self.listClass[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.structureLib.get_node_type() == "library":
return self.structureLib.get_whith_specific_parrent(name)
if appName != self.structureLib.get_name():
return []
return self.structureLib.get_whith_specific_parrent(name)
2013-12-22 18:55:48 +01:00
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()
2013-12-23 22:04:35 +01:00
try:
tmpdesc = theModule.get_desc()
except:
tmpdesc = ""
2013-12-22 18:55:48 +01:00
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
2013-12-23 22:04:35 +01:00
def get_link_type(type):
return ""
2013-12-22 18:55:48 +01:00
2013-12-25 23:56:09 +01:00
def get_element_with_name(type):
global moduleList
2013-12-26 07:49:52 +01:00
debug.verbose("try find : " + str(type) + " ")
2013-12-25 23:56:09 +01:00
ret = re.sub(r'::', ':', type)
ret = ret.split(":")
for mod in moduleList:
element = mod['node'].get_base_doc_node().find(ret)
if element != None:
2013-12-26 07:49:52 +01:00
debug.debug("we find : " + type + " = " + str(ret) + " " + str(element))
2013-12-25 23:56:09 +01:00
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