Rewrite the exception handling procedure for the new parser
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 19 Feb 2009 14:22:05 +0000 (14:22 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 19 Feb 2009 14:22:05 +0000 (14:22 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2361 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/BModulePage.py
wizard/DefineException.py
wizard/bertos_utils.py

index 101aba6913883f768f5f97d1775e42f2adaecb5f..74cd7cb266d7676213f6bd7e397948d8147eb244 100644 (file)
@@ -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)
     
index fabb4d90971052aaf0457f9ad85e8d53e870840a..2060a5353cd0dfcb433d700f0abccc386ba11b61 100644 (file)
@@ -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)
index 82b4ab7d607f854962973ddc53bd5eb706477720..cfaf2a7fd631f4f0a18f3c0f4f5d662c4845fac9 100644 (file)
@@ -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):
     """