X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=wizard%2Fbertos_utils.py;h=493ffbe21c64bc8653994a1b1d8fc69dda68e620;hb=ab03b5b37726fb8b39a6f6c915f8668bddd779ee;hp=972438df4781643e7a69c757c38f8f134220aa08;hpb=3234ec653302eb271f87197429f1f6cbd8f0bdb7;p=bertos.git diff --git a/wizard/bertos_utils.py b/wizard/bertos_utils.py index 972438df..493ffbe2 100644 --- a/wizard/bertos_utils.py +++ b/wizard/bertos_utils.py @@ -111,13 +111,13 @@ def projectFileGenerator(project_info): enabled_modules.append(module) project_data["ENABLED_MODULES"] = enabled_modules if project_info.info("PRESET"): - # For presets save again the SOURCES_PATH into project file + # For presets save again the BERTOS_PATH into project file project_data["PRESET"] = True - project_data["SOURCES_PATH"] = project_info.info("SOURCES_PATH") + project_data["BERTOS_PATH"] = project_info.info("BERTOS_PATH") else: # Use the local BeRTOS version instead of the original one - # project_data["SOURCES_PATH"] = project_info.info("SOURCES_PATH") - project_data["SOURCES_PATH"] = directory + # 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") @@ -125,6 +125,7 @@ def projectFileGenerator(project_info): 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): @@ -134,24 +135,31 @@ 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): + 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") + # Deadly performances loss was here :( mk_data = {} mk_data["$pname"] = os.path.basename(project_info.info("PROJECT_PATH")) + mk_data["$ppath"] = os.path.basename(project_info.info("PROJECT_SRC_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): """ Generates the mk file for the current project. """ + makefile = open(os.path.join(const.DATA_DIR, "mktemplates/template.mk"), "r").read() + destination = os.path.join(project_info.prjdir, os.path.basename(project_info.prjdir) + ".mk") mk_data = {} mk_data["$pname"] = project_info.info("PROJECT_NAME") + mk_data["$ppath"] = os.path.basename(project_info.info("PROJECT_SRC_PATH")) mk_data["$cpuclockfreq"] = project_info.info("SELECTED_FREQ") cpu_mk_parameters = [] for key, value in project_info.info("CPU_INFOS").items(): @@ -165,16 +173,22 @@ 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): """ Generate the Makefile for the current project. """ + makefile = open(os.path.join(const.DATA_DIR, "mktemplates/Makefile"), "r").read() + destination = os.path.join(project_info.maindir, "Makefile") # TODO write a general function that works for both the mk file and the Makefile - while makefile.find("$pname") != -1: - makefile = makefile.replace("$pname", project_info.info("PROJECT_NAME")) - return makefile + mk_data = {} + mk_data["$pname"] = project_info.info("PROJECT_NAME") + mk_data["$ppath"] = os.path.basename(project_info.info("PROJECT_SRC_PATH")) + for key in mk_data: + while makefile.find(key) != -1: + makefile = makefile.replace(key, mk_data[key]) + open(destination, "w").write(makefile) def csrcGenerator(project_info): modules = project_info.info("MODULES") @@ -252,13 +266,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 @@ -267,24 +281,25 @@ 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 - tags.append(project_info.info("CPU_INFOS")["TOOLCHAIN"]) except ValueError: - # If the version file hasn't a valid version number do nothing - pass + # If the version file hasn't a valid version number assume it's an older + # project. + version_list = [0, 0] + if version_list < [2, 5]: + # For older versions of BeRTOS add the toolchain to the tags + tags.append(project_info.info("CPU_INFOS")["TOOLCHAIN"]) 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