wizard: fix to get the correct BeRTOS version string.
[bertos.git] / wizard / bertos_utils.py
index 8d4b644917a0664c8905ac0beac9dbf1ceee3bc1..f10d7dc59fafc11de78f98398a20763a83fed4d6 100644 (file)
@@ -114,11 +114,14 @@ def projectFileGenerator(project_info):
     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")
+        project_data["BERTOS_PATH"] = relpath.relpath(project_info.info("BERTOS_PATH"), directory)
+    elif project_info.edit:
+        # If in editing mode the BERTOS_PATH is maintained
+        project_data["BERTOS_PATH"] = relpath.relpath(project_info.info("BERTOS_PATH"), directory)
     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["BERTOS_PATH"] = "."
     project_data["PROJECT_NAME"] = project_info.info("PROJECT_NAME", os.path.basename(directory))
     project_src_relpath = relpath.relpath(project_info.info("PROJECT_SRC_PATH"), directory)
     project_data["PROJECT_SRC_PATH"] = project_src_relpath
@@ -128,6 +131,7 @@ def projectFileGenerator(project_info):
     project_data["OUTPUT"] = project_info.info("OUTPUT")
     project_data["WIZARD_VERSION"] = WIZARD_VERSION
     project_data["PRESET"] = project_info.info("PRESET")
+    project_data["PROJECT_HW_PATH"] = relpath.relpath(project_info.info("PROJECT_HW_PATH"), directory)
     return pickle.dumps(project_data)
 
 def loadPlugin(plugin):
@@ -140,6 +144,18 @@ def versionFileGenerator(project_info, version_file):
     version = bertosVersion(project_info.info("BERTOS_PATH"))
     return version_file.replace('$version', version)
 
+def userMkGeneratorFromPreset(project_info):
+    project_name = project_info.info("PROJECT_NAME")
+    preset_path = project_info.info("PRESET_PATH")
+    preset_name = project_info.info("PRESET_NAME")
+    preset_src_dir = project_info.info("PRESET_SRC_PATH")
+    makefile = open(os.path.join(preset_path, preset_src_dir, "%s_user.mk" %preset_name), 'r').read()
+    destination = os.path.join(project_info.prjdir, "%s_user.mk" %project_info.info("PROJECT_NAME"))
+    # Temporary code.
+    # TODO: write it using regular expressions to secure this function
+    makefile = makefile.replace(preset_name + "_", project_name + "_")
+    open(destination, "w").write(makefile)
+
 def userMkGenerator(project_info):
     makefile = open(os.path.join(const.DATA_DIR, "mktemplates/template_user.mk"), "r").read()
     destination = os.path.join(project_info.prjdir, os.path.basename(project_info.prjdir) + "_user.mk")
@@ -149,8 +165,7 @@ def userMkGenerator(project_info):
     mk_data["$ppath"] = relpath.relpath(project_info.info("PROJECT_SRC_PATH"), project_info.info("PROJECT_PATH"))
     mk_data["$main"] = os.path.join("$(%s_SRC_PATH)" %project_info.info("PROJECT_NAME"), "main.c")
     for key in mk_data:
-        while makefile.find(key) != -1:
-            makefile = makefile.replace(key, mk_data[key])
+        makefile = makefile.replace(key, mk_data[key])
     open(destination, "w").write(makefile)
 
 def mkGenerator(project_info):
@@ -171,9 +186,9 @@ def mkGenerator(project_info):
     mk_data["$csrc"], mk_data["$pcsrc"], mk_data["$cppasrc"], mk_data["$cxxsrc"], mk_data["$asrc"], mk_data["$constants"] = csrcGenerator(project_info)
     mk_data["$prefix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[0])
     mk_data["$suffix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[1])
+    mk_data["$hwpath"] = relpath.relpath(project_info.info("PROJECT_HW_PATH"), project_info.info("PROJECT_PATH"))
     for key in mk_data:
-        while makefile.find(key) != -1:
-            makefile = makefile.replace(key, mk_data[key])
+        makefile = makefile.replace(key, mk_data[key])
     open(destination, "w").write(makefile)
 
 def makefileGenerator(project_info):
@@ -185,10 +200,9 @@ def makefileGenerator(project_info):
     # TODO write a general function that works for both the mk file and the Makefile
     mk_data = {}
     mk_data["$pname"] = project_info.info("PROJECT_NAME")
-    mk_data["$ppath"] = os.path.basename(project_info.info("PROJECT_SRC_PATH"))
+    mk_data["$ppath"] = relpath.relpath(project_info.info("PROJECT_SRC_PATH"), project_info.info("PROJECT_PATH"))
     for key in mk_data:
-        while makefile.find(key) != -1:
-            makefile = makefile.replace(key, mk_data[key])
+        makefile = makefile.replace(key, mk_data[key])
     open(destination, "w").write(makefile)
 
 def csrcGenerator(project_info):
@@ -283,7 +297,7 @@ def findModuleFiles(module, project_info):
     # TODO: split me in a method/function
     try:
         version_string = bertosVersion(project_info.info("BERTOS_PATH"))
-        version_list = [int(i) for i in version_string.split()[-1].split('.')]
+        version_list = [int(i) for i in version_string.split()[1].split('.')]
     except ValueError:
         # If the version file hasn't a valid version number assume it's an older
         # project.
@@ -310,8 +324,7 @@ def replaceSeparators(path):
     Replace the separators in the given path with unix standard separator.
     """
     if os.sep != "/":
-        while path.find(os.sep) != -1:
-            path = path.replace(os.sep, "/")
+        path = path.replace(os.sep, "/")
     return path
 
 def getSystemPath():