X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=wizard%2Fbertos_utils.py;h=925774ba387fefe0761b66364763fb40c9a8bc9d;hb=822c03fa0b9d667b6abf4b04d89b7debd8bc5afb;hp=428e11e6a3ad125f69c8ee71eb6364c482ef4554;hpb=1ebf147629d5ac01251a964ad5a2f498f487091c;p=bertos.git diff --git a/wizard/bertos_utils.py b/wizard/bertos_utils.py index 428e11e6..925774ba 100644 --- a/wizard/bertos_utils.py +++ b/wizard/bertos_utils.py @@ -13,8 +13,10 @@ import os import fnmatch import glob import re +import shutil import const +import DefineException def isBertosDir(directory): return os.path.exists(directory + "/VERSION") @@ -22,10 +24,72 @@ def isBertosDir(directory): def bertosVersion(directory): return open(directory + "/VERSION").readline().strip() -def createBertosProject(directory): +def createBertosProject(projectInfos): + directory = projectInfos.info("PROJECT_PATH") + sourcesDir = projectInfos.info("SOURCES_PATH") if not os.path.isdir(directory): os.mkdir(directory) - open(directory + "/project.bertos", "w") + f = open(directory + "/project.bertos", "w") + f.write(repr(projectInfos)) + f.close() + ## Destination source dir + srcdir = directory + "/bertos" + shutil.rmtree(srcdir, True) + shutil.copytree(sourcesDir + "/bertos", srcdir) + ## Destination makefile + makefile = directory + "/Makefile" + if os.path.exists(makefile): + os.remove(makefile) + makefile = open("mktemplates/Makefile").read() + makefile = makefileGenerator(projectInfos, makefile) + open(directory + "/Makefile", "w").write(makefile) + ## Destination project dir + prjdir = directory + "/" + os.path.basename(directory) + shutil.rmtree(prjdir, True) + os.mkdir(prjdir) + ## Destination configurations files + cfgdir = prjdir + "/cfg" + shutil.rmtree(cfgdir, True) + os.mkdir(cfgdir) + for key, value in projectInfos.info("CONFIGURATIONS").items(): + string = open(sourcesDir + "/" + key, "r").read() + for parameter, infos in value.items(): + value = infos["value"] + if "unsigned" in infos["informations"].keys() and infos["informations"]["unsigned"]: + value += "U" + if "long" in infos["informations"].keys() and infos["informations"]["long"]: + value += "L" + string = sub(string, parameter, value) + f = open(cfgdir + "/" + os.path.basename(key), "w") + f.write(string) + f.close() + ## Destinatio mk file + makefile = open("mktemplates/template.mk", "r").read() + makefile = mkGenerator(projectInfos, makefile) + open(prjdir + "/" + os.path.basename(prjdir) + ".mk", "w").write(makefile) + +def mkGenerator(projectInfos, 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"]) + for key in mkData: + while makefile.find(key) != -1: + makefile = makefile.replace(key, mkData[key]) + return makefile + +def makefileGenerator(projectInfos, 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"))) + return makefile def getSystemPath(): path = os.environ["PATH"] @@ -95,9 +159,182 @@ def getInfos(definition): return D def getDefinitionBlocks(text): + """ + Take a text and return a list of tuple (description, name-value). + """ block = [] - block_tmp = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/\s*#define\s+(.*?)\s*?$", text, re.MULTILINE) + block_tmp = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE) for comment, define in block_tmp: - block.append((" ".join(re.findall(r"^\s*\*?\s*(.*?)\s*?$", comment, re.MULTILINE)), define)) - block += re.findall(r"/{3}#define\s+" + parameter + r"\s+)([^\s]+)", r"\g" + value, string) + +def isInt(informations): + """ + Return True if the value is a simple int. + """ + if ("long" not in informatios.keys() or not informations["long"]) and ("unsigned" not in informations.keys() or informations["unsigned"]): + return True + else: + return False + +def isLong(informations): + """ + Return True if the value is a long. + """ + if "long" in informations.keys() and informations["long"] and "unsigned" not in informations.keys(): + return True + else: + return False + +def isUnsigned(informations): + """ + Return True if the value is an unsigned. + """ + if "unsigned" in informations.keys() and informations["unsigned"] and "long" not in informations.keys(): + return True + else: + return False + +def isUnsignedLong(informations): + """ + Return True if the value is an unsigned long. + """ + if "unsigned" in informations.keys() and "long" in informations.keys() and informations["unsigned"] and informations["long"]: + return True + else: + return False \ No newline at end of file