Use the brief for identify the parameter instead of the constant name...
[bertos.git] / wizard / bertos_utils.py
index 700a665382e37d0b1226829b0653643e30ffd0dd..cfaf2a7fd631f4f0a18f3c0f4f5d662c4845fac9 100644 (file)
@@ -24,13 +24,13 @@ def isBertosDir(directory):
 def bertosVersion(directory):
    return open(directory + "/VERSION").readline().strip()
 
-def createBertosProject(projectInfos):
-    directory = projectInfos.info("PROJECT_PATH")
-    sourcesDir = projectInfos.info("SOURCES_PATH")
+def createBertosProject(projectInfo):
+    directory = projectInfo.info("PROJECT_PATH")
+    sourcesDir = projectInfo.info("SOURCES_PATH")
     if not os.path.isdir(directory):
         os.mkdir(directory)
     f = open(directory + "/project.bertos", "w")
-    f.write(repr(projectInfos))
+    f.write(repr(projectInfo))
     f.close()
     ## Destination source dir
     srcdir = directory + "/bertos"
@@ -41,7 +41,7 @@ def createBertosProject(projectInfos):
     if os.path.exists(makefile):
         os.remove(makefile)
     makefile = open("mktemplates/Makefile").read()
-    makefile = makefileGenerator(projectInfos, makefile)
+    makefile = makefileGenerator(projectInfo, makefile)
     open(directory + "/Makefile", "w").write(makefile)
     ## Destination project dir
     prjdir = directory + "/" + os.path.basename(directory)
@@ -51,7 +51,7 @@ def createBertosProject(projectInfos):
     cfgdir = prjdir + "/cfg"
     shutil.rmtree(cfgdir, True)
     os.mkdir(cfgdir)
-    for key, value in projectInfos.info("CONFIGURATIONS").items():
+    for key, value in projectInfo.info("CONFIGURATIONS").items():
         string = open(sourcesDir + "/" + key, "r").read()
         for parameter, infos in value.items():
             value = infos["value"]
@@ -65,32 +65,48 @@ def createBertosProject(projectInfos):
         f.close()
     ## Destinatio mk file
     makefile = open("mktemplates/template.mk", "r").read()
-    makefile = mkGenerator(projectInfos, makefile)
+    makefile = mkGenerator(projectInfo, makefile)
     open(prjdir + "/" + os.path.basename(prjdir) + ".mk", "w").write(makefile)
 
-def mkGenerator(projectInfos, makefile):
+def mkGenerator(projectInfo, makefile):
     """
     Generates the mk file for the current project.
     """
     mkData = {}
-    mkData["pname"] = os.path.basename(projectInfos.info("PROJECT_PATH"))
-    mkData["cpuname"] = projectInfos.info("CPU_INFOS")["CPU_NAME"]
-    mkData["cflags"] = " ".join(projectInfos.info("CPU_INFOS")["C_FLAGS"])
-    mkData["ldflags"] = " ".join(projectInfos.info("CPU_INFOS")["LD_FLAGS"])
+    mkData["$pname"] = os.path.basename(projectInfo.info("PROJECT_PATH"))
+    mkData["$cpuname"] = projectInfo.info("CPU_INFOS")["CPU_NAME"]
+    mkData["$cflags"] = " ".join(projectInfo.info("CPU_INFOS")["C_FLAGS"])
+    mkData["$ldflags"] = " ".join(projectInfo.info("CPU_INFOS")["LD_FLAGS"])
+    mkData["$csrc"] = csrcGenerator(projectInfo)
     for key in mkData:
         while makefile.find(key) != -1:
             makefile = makefile.replace(key, mkData[key])
     return makefile
 
-def makefileGenerator(projectInfos, makefile):
+def makefileGenerator(projectInfo, makefile):
     """
     Generate the Makefile for the current project.
     """
     # TODO: write a general function that works for both the mk file and the Makefile
     while makefile.find("project_name") != -1:
-        makefile = makefile.replace("project_name", os.path.basename(projectInfos.info("PROJECT_PATH")))
+        makefile = makefile.replace("project_name", os.path.basename(projectInfo.info("PROJECT_PATH")))
     return makefile
 
+def csrcGenerator(projectInfo):
+    modules = projectInfo.info("MODULES")
+    files = []
+    for module, information in modules.items():
+        if information["enabled"]:
+            for filename, path in findDefinitions(module + ".c", projectInfo):
+                files.append(path + "/" + filename)
+            for filename, path in findDefinitions(module + "_" + projectInfo.info("CPU_INFOS")["TOOLCHAIN"] + ".c", projectInfo):
+                files.append(path + "/" + filename)
+            for tag in projectInfo.info("CPU_INFOS")["CPU_TAGS"]:
+                for filename, path in findDefinitions(module + "_" + tag + ".c", projectInfo):
+                    files.append(path + "/" + filename)
+    csrc = " \\\n\t".join(files)
+    return csrc
+    
 def getSystemPath():
     path = os.environ["PATH"]
     if os.name == "nt":
@@ -220,19 +236,27 @@ def getDescriptionInformations(comment):
     Take the doxygen comment and strip the wizard informations, returning the tuple 
     (comment, wizard_information) 
     """
+    brief = ""
     description = ""
     information = {}
     for num, line in enumerate(comment):
         index = line.find("$WIZ$")
         if index != -1:
-            description += " " + line[:index]
+            if len(brief) == 0:
+                brief += line[:index].strip()
+            else:
+                description += " " + line[:index]
             try:
                 exec line[index + len("$WIZ$ "):] in {}, information
             except:
                 raise ParseError(num, line[index:])
         else:
-            description += " " + line
-    return description.strip(), information
+            if len(brief) == 0:
+                brief += line.strip()
+            else:
+                description += " " + line
+                description = description.strip()
+    return brief.strip(), description.strip(), information
 
 def getDefinitionBlocks(text):
     """
@@ -261,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:
@@ -276,13 +300,14 @@ 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))
+    for tag in project.info("CPU_INFOS")["CPU_TAGS"]:
+        for filename, path in findDefinitions("*_" + tag + ".h", project):
+            commentList = getCommentList(open(path + "/" + filename, "r").read())
+            listInfoDict.update(loadDefineLists(commentList))
     project.setInfo("MODULES", moduleInfoDict)
     project.setInfo("LISTS", listInfoDict)
     project.setInfo("CONFIGURATIONS", configurationInfoDict)
@@ -308,31 +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)
-            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
-        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):
     """