From 1fe604ce663530130833c05d65dbcf7fec9d2ebe Mon Sep 17 00:00:00 2001 From: duplo Date: Wed, 11 Feb 2009 09:56:29 +0000 Subject: [PATCH] Make smarter the selection of the header to parse git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2342 38d2e660-2303-0410-9eaa-f027e97ec537 --- wizard/BModulePage.py | 4 +-- wizard/bertos_utils.py | 53 ++++++++++++++++++++++++++--------- wizard/test/testModulePage.py | 3 ++ 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/wizard/BModulePage.py b/wizard/BModulePage.py index c592d1d3..101aba69 100644 --- a/wizard/BModulePage.py +++ b/wizard/BModulePage.py @@ -39,9 +39,7 @@ class BModulePage(BWizardPage): def _loadModuleData(self): try: - bertos_utils.loadModuleInfosDict(self._project()) - bertos_utils.loadDefineListsDict(self._project()) - bertos_utils.loadConfigurationInfosDict(self._project()) + bertos_utils.loadModuleData(self._project()) except ModuleDefineException, e: self._exceptionOccurred(self.tr("Error parsing module information in file %1").arg(e.path)) except EnumDefineException, e: diff --git a/wizard/bertos_utils.py b/wizard/bertos_utils.py index 700d72e7..7e16c1bf 100644 --- a/wizard/bertos_utils.py +++ b/wizard/bertos_utils.py @@ -164,6 +164,23 @@ def getInfos(definition): del D["include"] return D +def loadModuleData(project): + moduleInfosDict = {} + listInfosDict = {} + configurationsInfoDict = {} + for filename, path in findDefinitions("*.h", project): + moduleInfos, listInfos, configurationInfos= loadModuleInfos(path + "/" + filename) + moduleInfosDict.update(moduleInfos) + listInfosDict.update(listInfos) + for configuration in configurationInfos.keys(): + configurationsInfoDict[configuration] = loadConfigurationInfos(project.info("SOURCES_PATH") + "/" + configuration) + print "*_" + project.info("CPU_INFOS")["TOOLCHAIN"] + ".h" + for filename, path in findDefinitions("*_" + project.info("CPU_INFOS")["TOOLCHAIN"] + ".h", project): + listInfosDict.update(loadDefineLists(path + "/" + filename)) + project.setInfo("MODULES", moduleInfosDict) + project.setInfo("LISTS", listInfosDict) + project.setInfo("CONFIGURATIONS", configurationsInfoDict) + def getDefinitionBlocks(text): """ Take a text and return a list of tuple (description, name-value). @@ -258,24 +275,32 @@ def loadModuleInfos(path): """ try: moduleInfos = {} + listInfos = {} + configurationsInfos = {} string = open(path, "r").read() commentList = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/", string) commentList = [" ".join(re.findall(r"^\s*\*?\s*(.*?)\s*?(?:/{2}.*?)?$", comment, re.MULTILINE)).strip() for comment in commentList] - for comment in commentList: - index = comment.find("$WIZARD_MODULE") - if index != -1: - exec(comment[index + 1:]) - moduleInfos[WIZARD_MODULE["name"]] = {"depends": WIZARD_MODULE["depends"], - "configuration": WIZARD_MODULE["configuration"], - "description": "", - "enabled": False} - index = comment.find("\\brief") + if len(commentList) > 0: + comment = commentList[0] + if comment.find("$WIZARD_MODULE") != -1: + index = comment.find("$WIZARD_MODULE") if index != -1: - description = comment[index + 7:] - description = description[:description.find(" * ")] - moduleInfos[WIZARD_MODULE["name"]]["description"] = description - return moduleInfos - return {} + # 14 is the length of "$WIZARD_MODULE" + if len(comment[index + 14:].strip()) > 0: + exec(comment[index + 1:]) + moduleInfos[WIZARD_MODULE["name"]] = {"depends": WIZARD_MODULE["depends"], + "configuration": WIZARD_MODULE["configuration"], + "description": "", + "enabled": False} + index = comment.find("\\brief") + if index != -1: + description = comment[index + 7:] + description = description[:description.find(" * ")] + moduleInfos[WIZARD_MODULE["name"]]["description"] = description + if "configuration" in WIZARD_MODULE.keys() and len(WIZARD_MODULE["configuration"]) > 0: + configurationsInfos[WIZARD_MODULE["configuration"]] = {} + listInfos.update(loadDefineLists(path)) + return moduleInfos, listInfos, configurationsInfos except SyntaxError: raise DefineException.ModuleDefineException(path) diff --git a/wizard/test/testModulePage.py b/wizard/test/testModulePage.py index 026e9ae9..6c4f8dc7 100644 --- a/wizard/test/testModulePage.py +++ b/wizard/test/testModulePage.py @@ -19,6 +19,7 @@ sys.path.append("../") import BProject import BModulePage +import bertos_utils # Add a custom UI_LOCATION constant BModulePage.UI_LOCATION = "../ui" @@ -28,6 +29,8 @@ def main(): app.project = BProject.BProject() page = BModulePage.BModulePage() page._projectInfoStore("SOURCES_PATH", "../../") + page._projectInfoStore("CPU_INFOS", {"TOOLCHAIN": "avr"}) + bertos_utils.loadSourceTree(page._project()) page.reloadData() page.show() app.exec_() -- 2.25.1