4 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
9 # Author: Lorenzo Berni <duplo@develer.com>
19 def isBertosDir(directory):
20 return os.path.exists(directory + "/VERSION")
22 def bertosVersion(directory):
23 return open(directory + "/VERSION").readline().strip()
25 def createBertosProject(directory):
26 if not os.path.isdir(directory):
28 open(directory + "/project.bertos", "w")
31 path = os.environ["PATH"]
33 path = path.split(";")
35 path = path.split(":")
38 def findToolchains(pathList):
40 for element in pathList:
41 for toolchain in glob.glob(element+ "/" + const.GCC_NAME):
42 if not os.path.islink(toolchain):
43 toolchains.append(toolchain)
44 return list(set(toolchains))
46 def getToolchainInfo(output):
48 expr = re.compile("Target: .*")
49 target = expr.findall(output)
51 info["target"] = target[0].split("Target: ")[1]
52 expr = re.compile("gcc version [0-9,.]*")
53 version = expr.findall(output)
55 info["version"] = version[0].split("gcc version ")[1]
56 expr = re.compile("gcc version [0-9,.]* \(.*\)")
57 build = expr.findall(output)
59 build = build[0].split("gcc version ")[1]
60 build = build[build.find("(") + 1 : build.find(")")]
62 expr = re.compile("Configured with: .*")
63 configured = expr.findall(output)
64 if len(configured) == 1:
65 info["configured"] = configured[0].split("Configured with: ")[1]
66 expr = re.compile("Thread model: .*")
67 thread = expr.findall(output)
69 info["thread"] = thread[0].split("Thread model: ")[1]
72 def findDefinitions(ftype, path):
75 for filename in element[2]:
76 if fnmatch.fnmatch(filename, ftype):
77 yield (filename, element[0])
79 def loadCpuInfos(path):
81 for definition in findDefinitions(const.CPU_DEFINITION, path):
82 cpuInfos.append(getInfos(definition))
85 def getInfos(definition):
87 D.update(const.CPU_DEF)
88 def include(filename, dict = D, directory=definition[1]):
89 execfile(directory + "/" + filename, {}, D)
90 D["include"] = include
91 include(definition[0], D)
92 D["CPU_NAME"] = definition[0].split(".")[0]
93 D["DEFINITION_PATH"] = definition[1] + "/" + definition[0]
97 def getDefinitionBlocks(text):
99 Take a text and return a list of tuple (description, name-value).
102 block_tmp = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE)
103 for comment, define in block_tmp:
104 block.append((" ".join(re.findall(r"^\s*\*?\s*(.*?)\s*?(?:/{2}.*?)?$", comment, re.MULTILINE)).strip(), define))
105 block += re.findall(r"/{3}\s*([^<].*?)\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE)
106 block += [(comment, define) for define, comment in re.findall(r"#define\s*(.*?)\s*/{3}<\s*(.+?)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE)]
109 def formatModuleNameValue(text):
111 Take the given string and return a tuple with the name of the parameter in the first position
112 and the value in the second.
114 block = re.findall("\s*([^\s]+)\s*(.+?)\s*$", text, re.MULTILINE)
117 def getDescriptionInformations(text):
119 Take the doxygen comment and strip the wizard informations, returning the tuple
120 (comment, wizard_informations)
122 index = text.find("$WIZARD")
124 exec(text[index + 1:])
125 informations = WIZARD
126 return text[:index].strip(), informations
128 return text.strip(), {}
130 def loadModuleInfos(path):
132 Return the module configurations found in the given path as a dict with the name as key
133 and a dict as value. The value dict has the parameter name as key and has "value" and "description"
137 for definition in findDefinitions(const.MODULE_CONFIGURATION, path):
138 moduleName = definition[0].replace("cfg_", "").replace(".h", "")
139 moduleInfos[moduleName] = {}
140 for comment, define in getDefinitionBlocks(open(definition[1] + "/" + definition[0], "r").read()):
141 name, value = formatModuleNameValue(define)
142 description, informations = getDescriptionInformations(comment)
143 moduleInfos[moduleName][name] = {}
144 moduleInfos[moduleName][name]["value"] = value
145 moduleInfos[moduleName][name]["informations"] = informations
146 moduleInfos[moduleName][name]["description"] = description