From d685c5f413bd6cbd5f00c35da830a9a93ff943f1 Mon Sep 17 00:00:00 2001 From: duplo Date: Thu, 19 Feb 2009 14:22:05 +0000 Subject: [PATCH] Rewrite the exception handling procedure for the new parser git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2361 38d2e660-2303-0410-9eaa-f027e97ec537 --- wizard/BModulePage.py | 8 ++--- wizard/DefineException.py | 17 ++++++----- wizard/bertos_utils.py | 61 +++++++++++++++++---------------------- 3 files changed, 39 insertions(+), 47 deletions(-) diff --git a/wizard/BModulePage.py b/wizard/BModulePage.py index 101aba69..74cd7cb2 100644 --- a/wizard/BModulePage.py +++ b/wizard/BModulePage.py @@ -41,11 +41,11 @@ class BModulePage(BWizardPage): try: bertos_utils.loadModuleData(self._project()) except ModuleDefineException, e: - self._exceptionOccurred(self.tr("Error parsing module information in file %1").arg(e.path)) + self._exceptionOccurred(self.tr("Error parsing line '%2' in file %1").arg(e.path).arg(e.line)) except EnumDefineException, e: - self._exceptionOccurred(self.tr("Error parsing enum informations in file %1").arg(e.path)) + self._exceptionOccurred(self.tr("Error parsing line '%2' in file %1").arg(e.path).arg(e.line)) except ConfigurationDefineException, e: - self._exceptionOccurred(self.tr("Error parsing configuration informations in file %1, reading parameter %2").arg(e.path).arg(e.name)) + self._exceptionOccurred(self.tr("Error parsing line '%2' in file %1").arg(e.path).arg(e.line)) def _fillModuleTable(self): modules = self._projectInfoRetrieve("MODULES") @@ -177,7 +177,7 @@ class BModulePage(BWizardPage): self._resetPropertyDescription() configurations = self._currentModuleConfigurations() if self._currentProperty() in configurations.keys(): - description = configurations[self._currentProperty()]["description"] + description = configurations[self._currentProperty()]["brief"] name = self._currentProperty() self._currentPropertyItem().setText(name + "\n" + description) diff --git a/wizard/DefineException.py b/wizard/DefineException.py index fabb4d90..2060a535 100644 --- a/wizard/DefineException.py +++ b/wizard/DefineException.py @@ -14,8 +14,10 @@ class DefineException(Exception): """ Exception raised when an error occurs parsing the module informations. """ - def __init__(self, path): + def __init__(self, path, line_number, line): self.path = path + self.line_number = line_number + self.line = line def __str__(self): return repr(self.path) @@ -24,20 +26,19 @@ class ModuleDefineException(DefineException): """ Exception raised when an error occurs parsing the module informations. """ - def __init__(self, path): - super(ModuleDefineException, self).__init__(path) + def __init__(self, path, line_number, line): + super(ModuleDefineException, self).__init__(path, line_number, line) class EnumDefineException(DefineException): """ Exception raised when an error occurs parsing the enum informations. """ - def __init__(self, path): - super(EnumDefineException, self).__init__(path) + def __init__(self, path, line_number, line): + super(EnumDefineException, self).__init__(path, line_number, line) class ConfigurationDefineException(DefineException): """ Exception raised when an error occurs parsing the configuration parameter informations. """ - def __init__(self, path, name): - super(ConfigurationDefineException, self).__init__(path) - self.name = name + def __init__(self, path, line_number, line): + super(ConfigurationDefineException, self).__init__(path, line_number, line) diff --git a/wizard/bertos_utils.py b/wizard/bertos_utils.py index 82b4ab7d..cfaf2a7f 100644 --- a/wizard/bertos_utils.py +++ b/wizard/bertos_utils.py @@ -285,14 +285,14 @@ def loadModuleData(project): try: toBeParsed, moduleDict = loadModuleDefinition(commentList[0]) except ParseError, err: - print "error in file %s. line: %d - statement %s" % (path + "/" + filename, err.line_number, err.line) - print err.args - print err.message - raise Exception + raise DefineException.ModuleDefineException(path, err.line_number, err.line) for module, information in moduleDict.items(): if "configuration" in information.keys() and len(information["configuration"]): configuration = moduleDict[module]["configuration"] - configurationInfo[configuration] = loadConfigurationInfos(project.info("SOURCES_PATH") + "/" + configuration) + try: + configurationInfo[configuration] = loadConfigurationInfos(project.info("SOURCES_PATH") + "/" + configuration) + except ParseError, err: + raise DefineException.ConfigurationDefineException(project.info("SOURCES_PATH") + "/" + configuration, err.line_number, err.line) moduleInfoDict.update(moduleDict) configurationInfoDict.update(configurationInfo) if toBeParsed: @@ -300,10 +300,7 @@ def loadModuleData(project): listDict = loadDefineLists(commentList[1:]) listInfoDict.update(listDict) except ParseError, err: - print "error in file %s. line: %d - statement %s" % (path + "/" + filename, err.line_number, err.line) - print err.args - print err.message - raise Exception + raise DefineException.EnumDefineException(path, err.line_number, err.line) for filename, path in findDefinitions("*_" + project.info("CPU_INFOS")["TOOLCHAIN"] + ".h", project): commentList = getCommentList(open(path + "/" + filename, "r").read()) listInfoDict.update(loadDefineLists(commentList)) @@ -336,32 +333,26 @@ def loadConfigurationInfos(path): "long": boolean indicating if the num is a long "value_list": the name of the enum for enum parameters """ - try: - configurationInfos = {} - for comment, define in getDefinitionBlocks(open(path, "r").read()): - name, value = formatParamNameValue(define) - brief, description, informations = getDescriptionInformations(comment) - configurationInfos[name] = {} - configurationInfos[name]["value"] = value - configurationInfos[name]["informations"] = informations - if ("type" in configurationInfos[name]["informations"].keys() and - configurationInfos[name]["informations"]["type"] == "int" and - configurationInfos[name]["value"].find("L") != -1): - configurationInfos[name]["informations"]["long"] = True - configurationInfos[name]["value"] = configurationInfos[name]["value"].replace("L", "") - if ("type" in configurationInfos[name]["informations"].keys() and - configurationInfos[name]["informations"]["type"] == "int" and - configurationInfos[name]["value"].find("U") != -1): - configurationInfos[name]["informations"]["unsigned"] = True - configurationInfos[name]["value"] = configurationInfos[name]["value"].replace("U", "") - configurationInfos[name]["description"] = description - configurationInfos[name]["brief"] = brief - return configurationInfos - except ParseError, err: - print "error in file %s. line: %d - statement %s" % (path, err.line_number, err.line) - print err.args - print err.message - raise Exception + configurationInfos = {} + for comment, define in getDefinitionBlocks(open(path, "r").read()): + name, value = formatParamNameValue(define) + brief, description, informations = getDescriptionInformations(comment) + configurationInfos[name] = {} + configurationInfos[name]["value"] = value + configurationInfos[name]["informations"] = informations + if ("type" in configurationInfos[name]["informations"].keys() and + configurationInfos[name]["informations"]["type"] == "int" and + configurationInfos[name]["value"].find("L") != -1): + configurationInfos[name]["informations"]["long"] = True + configurationInfos[name]["value"] = configurationInfos[name]["value"].replace("L", "") + if ("type" in configurationInfos[name]["informations"].keys() and + configurationInfos[name]["informations"]["type"] == "int" and + configurationInfos[name]["value"].find("U") != -1): + configurationInfos[name]["informations"]["unsigned"] = True + configurationInfos[name]["value"] = configurationInfos[name]["value"].replace("U", "") + configurationInfos[name]["description"] = description + configurationInfos[name]["brief"] = brief + return configurationInfos def sub(string, parameter, value): """ -- 2.25.1