Clean up. Add set polarity prototype.
[bertos.git] / wizard / bertos_utils.py
index 3957b6746b7b28e57bf3ac9aee53770040c59502..4589de3bf8bd2ca767beff5b1bc9ae38474b778a 100644 (file)
@@ -110,15 +110,22 @@ def projectFileGenerator(project_info):
         if information["enabled"]:
             enabled_modules.append(module)
     project_data["ENABLED_MODULES"] = enabled_modules
-    # Use the local BeRTOS version instead of the original one
-    # project_data["SOURCES_PATH"] = project_info.info("SOURCES_PATH")
-    project_data["SOURCES_PATH"] = directory
+    if project_info.info("PRESET"):
+        # For presets save again the BERTOS_PATH into project file
+        project_data["PRESET"] = True
+        project_data["BERTOS_PATH"] = project_info.info("BERTOS_PATH")
+    else:
+        # Use the local BeRTOS version instead of the original one
+        # project_data["BERTOS_PATH"] = project_info.info("BERTOS_PATH")
+        project_data["BERTOS_PATH"] = directory
     project_data["PROJECT_NAME"] = project_info.info("PROJECT_NAME", os.path.basename(directory))
+    project_data["PROJECT_SRC_PATH"] = project_info.info("PROJECT_SRC_PATH")
     project_data["TOOLCHAIN"] = project_info.info("TOOLCHAIN")
     project_data["CPU_NAME"] = project_info.info("CPU_NAME")
     project_data["SELECTED_FREQ"] = project_info.info("SELECTED_FREQ")
     project_data["OUTPUT"] = project_info.info("OUTPUT")
     project_data["WIZARD_VERSION"] = WIZARD_VERSION
+    project_data["PRESET"] = project_info.info("PRESET")
     return pickle.dumps(project_data)
 
 def loadPlugin(plugin):
@@ -128,24 +135,27 @@ def loadPlugin(plugin):
     return getattr(__import__("plugins", {}, {}, [plugin]), plugin)
 
 def versionFileGenerator(project_info, version_file):
-    version = bertosVersion(project_info.info("SOURCES_PATH"))
+    version = bertosVersion(project_info.info("BERTOS_PATH"))
     return version_file.replace('$version', version)
 
-def userMkGenerator(project_info, makefile):
+def userMkGenerator(project_info, destination):
+    makefile = open(os.path.join(const.DATA_DIR, "mktemplates/template.mk"), "r").read()
+    # Deadly performances loss was here :(
     mk_data = {}
     mk_data["$pname"] = os.path.basename(project_info.info("PROJECT_PATH"))
     mk_data["$main"] = os.path.basename(project_info.info("PROJECT_PATH")) + "/main.c"
     for key in mk_data:
         while makefile.find(key) != -1:
             makefile = makefile.replace(key, mk_data[key])
-    return makefile
+    open(destination, "w").write(makefile)
 
-def mkGenerator(project_info, makefile):
+def mkGenerator(project_info, destination):
     """
     Generates the mk file for the current project.
     """
+    makefile = open(os.path.join(const.DATA_DIR, "mktemplates/template_wiz.mk"), "r").read()
     mk_data = {}
-    mk_data["$pname"] = os.path.basename(project_info.info("PROJECT_PATH"))
+    mk_data["$pname"] = project_info.info("PROJECT_NAME")
     mk_data["$cpuclockfreq"] = project_info.info("SELECTED_FREQ")
     cpu_mk_parameters = []
     for key, value in project_info.info("CPU_INFOS").items():
@@ -159,16 +169,17 @@ def mkGenerator(project_info, makefile):
     for key in mk_data:
         while makefile.find(key) != -1:
             makefile = makefile.replace(key, mk_data[key])
-    return makefile
+    open(destination, "w").write(makefile)
 
-def makefileGenerator(project_info, makefile):
+def makefileGenerator(project_info, destination):
     """
     Generate the Makefile for the current project.
     """
+    makefile = open(os.path.join(const.DATA_DIR, "mktemplates/Makefile"), "r").read()
     # TODO write a general function that works for both the mk file and the Makefile
     while makefile.find("$pname") != -1:
-        makefile = makefile.replace("$pname", os.path.basename(project_info.info("PROJECT_PATH")))
-    return makefile
+        makefile = makefile.replace("$pname", project_info.info("PROJECT_NAME"))
+    open(destination, "w").write(makefile)
 
 def csrcGenerator(project_info):
     modules = project_info.info("MODULES")
@@ -246,13 +257,13 @@ def findModuleFiles(module, project_info):
     sfiles = []
     # .c files related to the module and the cpu architecture
     for filename, path in project_info.searchFiles(module + ".c"):
-        path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
+        path = path.replace(project_info.info("BERTOS_PATH") + os.sep, "")
         path = replaceSeparators(path)
         cfiles.append(path + "/" + filename)
     # .s files related to the module and the cpu architecture
     for filename, path in project_info.searchFiles(module + ".s") + \
             project_info.searchFiles(module + ".S"):
-        path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
+        path = path.replace(project_info.info("BERTOS_PATH") + os.sep, "")
         path = replaceSeparators(path)
         sfiles.append(path + "/" + filename)
     # .c and .s files related to the module and the cpu tags
@@ -261,7 +272,7 @@ def findModuleFiles(module, project_info):
     # Awful, but secure check for version
     # TODO: split me in a method/function
     try:
-        version_string = bertosVersion(project_info.info("SOURCES_PATH"))
+        version_string = bertosVersion(project_info.info("BERTOS_PATH"))
         version_list = [int(i) for i in version_string.split()[-1].split('.')]
         if version_list < [2, 5]:
             # For older versions of BeRTOS add the toolchain to the tags
@@ -272,13 +283,13 @@ def findModuleFiles(module, project_info):
 
     for tag in tags:
         for filename, path in project_info.searchFiles(module + "_" + tag + ".c"):
-            path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
+            path = path.replace(project_info.info("BERTOS_PATH") + os.sep, "")
             if os.sep != "/":
                 path = replaceSeparators(path)
             cfiles.append(path + "/" + filename)
         for filename, path in project_info.searchFiles(module + "_" + tag + ".s") + \
                 project_info.searchFiles(module + "_" + tag + ".S"):
-            path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
+            path = path.replace(project_info.info("BERTOS_PATH") + os.sep, "")
             path = replaceSeparators(path)
             sfiles.append(path + "/" + filename)
     return cfiles, sfiles