4 # This file is part of BeRTOS.
6 # Bertos is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction. Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License. This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
33 # Author: Lorenzo Berni <duplo@develer.com>
41 # Use custom copytree function
47 import DefineException
50 def isBertosDir(directory):
51 return os.path.exists(directory + "/VERSION")
53 def bertosVersion(directory):
54 return open(directory + "/VERSION").readline().strip()
56 def loadBertosProject(project_file):
57 project_data = pickle.loads(open(project_file, "r").read())
58 project_info = BProject.BProject()
59 project_info.setInfo("PROJECT_PATH", os.path.dirname(project_file))
60 project_info.setInfo("SOURCES_PATH", project_data["SOURCES_PATH"])
61 project_info.setInfo("TOOLCHAIN", project_data["TOOLCHAIN"])
62 project_info.setInfo("SELECTED_FREQ", project_data["SELECTED_FREQ"])
63 project_info.setInfo("OUTPUT", project_data["OUTPUT"])
64 loadSourceTree(project_info)
65 cpu_name = project_data["CPU_NAME"]
66 project_info.setInfo("CPU_NAME", cpu_name)
67 cpu_info = loadCpuInfos(project_info)
69 if cpu["CPU_NAME"] == cpu_name:
70 project_info.setInfo("CPU_INFOS", cpu)
72 tag_list = getTagSet(cpu_info)
73 # Create, fill and store the dict with the tags
75 for element in tag_list:
76 tag_dict[element] = False
77 infos = project_info.info("CPU_INFOS")
79 if tag in infos["CPU_TAGS"] + [infos["CPU_NAME"], infos["TOOLCHAIN"]]:
83 project_info.setInfo("ALL_CPU_TAGS", tag_dict)
84 loadModuleData(project_info, True)
85 modules = project_info.info("MODULES")
86 for module, information in modules.items():
87 information["enabled"] = module in project_data["ENABLED_MODULES"]
88 project_info.setInfo("MODULES", modules)
91 def mergeSources(srcdir, new_sources, old_sources):
92 # TODO: implement the three way merge algorithm
95 def projectFileGenerator(project_info):
96 directory = project_info.info("PROJECT_PATH")
99 for module, information in project_info.info("MODULES").items():
100 if information["enabled"]:
101 enabled_modules.append(module)
102 project_data["ENABLED_MODULES"] = enabled_modules
103 project_data["SOURCES_PATH"] = project_info.info("SOURCES_PATH")
104 project_data["TOOLCHAIN"] = project_info.info("TOOLCHAIN")
105 project_data["CPU_NAME"] = project_info.info("CPU_NAME")
106 project_data["SELECTED_FREQ"] = project_info.info("SELECTED_FREQ")
107 project_data["OUTPUT"] = project_info.info("OUTPUT")
108 return pickle.dumps(project_data)
110 def createBertosProject(project_info, edit=False):
111 directory = project_info.info("PROJECT_PATH")
112 sources_dir = project_info.info("SOURCES_PATH")
114 if os.path.isdir(directory):
115 shutil.rmtree(directory, True)
116 os.makedirs(directory)
117 # Write the project file
118 f = open(directory + "/project.bertos", "w")
119 f.write(projectFileGenerator(project_info))
121 # Destination source dir
122 srcdir = directory + "/bertos"
124 # If not in editing mode it copies all the bertos sources in the /bertos subdirectory of the project
125 shutil.rmtree(srcdir, True)
126 copytree.copytree(sources_dir + "/bertos", srcdir, ignore_list=const.IGNORE_LIST)
128 # If in editing mode it merges the current bertos sources with the selected ones
129 # TODO: implement the three way merge algotihm
131 # mergeSources(srcdir, sources_dir, old_sources_dir)
134 # Destination makefile
135 makefile = directory + "/Makefile"
136 makefile = open("mktemplates/Makefile").read()
137 makefile = makefileGenerator(project_info, makefile)
138 open(directory + "/Makefile", "w").write(makefile)
139 # Destination project dir
140 prjdir = directory + "/" + os.path.basename(directory)
142 shutil.rmtree(prjdir, True)
144 # Destination hw files
145 hwdir = prjdir + "/hw"
147 shutil.rmtree(hwdir, True)
149 # Copy all the hw files
150 for module, information in project_info.info("MODULES").items():
151 for hwfile in information["hw"]:
152 string = open(sources_dir + "/" + hwfile, "r").read()
153 hwfile_path = hwdir + "/" + os.path.basename(hwfile)
154 if not edit or not os.path.exists(hwfile_path):
155 # If not in editing mode it copies all the hw files. If in
156 # editing mode it copies only the files that don't exist yet
157 open(hwdir + "/" + os.path.basename(hwfile), "w").write(string)
158 # Destination configurations files
159 cfgdir = prjdir + "/cfg"
161 shutil.rmtree(cfgdir, True)
163 # Set properly the autoenabled parameters
164 for module, information in project_info.info("MODULES").items():
165 if "configuration" in information and information["configuration"] != "":
166 configurations = project_info.info("CONFIGURATIONS")
167 configuration = configurations[information["configuration"]]
168 for start, parameter in configuration["paramlist"]:
169 if "type" in configuration[parameter]["informations"] and configuration[parameter]["informations"]["type"] == "autoenabled":
170 configuration[parameter]["value"] = "1" if information["enabled"] else "0"
171 project_info.setInfo("CONFIGURATIONS", configurations)
172 # Copy all the configuration files
173 for configuration, information in project_info.info("CONFIGURATIONS").items():
174 string = open(sources_dir + "/" + configuration, "r").read()
175 for start, parameter in information["paramlist"]:
176 infos = information[parameter]
177 value = infos["value"]
178 if "unsigned" in infos["informations"] and infos["informations"]["unsigned"]:
180 if "long" in infos["informations"] and infos["informations"]["long"]:
182 string = sub(string, parameter, value)
183 f = open(cfgdir + "/" + os.path.basename(configuration), "w")
187 # Destination user mk file (only on project creation)
188 makefile = open("mktemplates/template.mk", "r").read()
189 makefile = mkGenerator(project_info, makefile)
190 open(prjdir + "/" + os.path.basename(prjdir) + ".mk", "w").write(makefile)
191 # Destination wizard mk file
192 makefile = open("mktemplates/template_wiz.mk", "r").read()
193 makefile = mkGenerator(project_info, makefile)
194 open(prjdir + "/" + os.path.basename(prjdir) + "_wiz.mk", "w").write(makefile)
195 # Destination main.c file
197 main = open("srctemplates/main.c", "r").read()
198 open(prjdir + "/main.c", "w").write(main)
199 # Files for selected plugins
201 for plugin in project_info.info("OUTPUT"):
202 module = loadPlugin(plugin)
203 relevants_files[plugin] = module.createProject(project_info)
204 project_info.setInfo("RELEVANT_FILES", relevants_files)
206 def loadPlugin(plugin):
208 Returns the given plugin module.
210 return getattr(__import__("plugins", {}, {}, [plugin]), plugin)
212 def mkGenerator(project_info, makefile):
214 Generates the mk file for the current project.
217 mk_data["$pname"] = os.path.basename(project_info.info("PROJECT_PATH"))
218 mk_data["$cpuclockfreq"] = project_info.info("SELECTED_FREQ")
219 cpu_mk_parameters = []
220 for key, value in project_info.info("CPU_INFOS").items():
221 if key.startswith("MK_"):
222 cpu_mk_parameters.append("%s = %s" %(key.replace("MK", mk_data["$pname"]), value))
223 print project_info.info("CPU_INFOS")
224 mk_data["$cpuparameters"] = "\n".join(cpu_mk_parameters)
225 mk_data["$csrc"], mk_data["$pcsrc"], mk_data["$cppasrc"], mk_data["$cxxsrc"], mk_data["$asrc"], mk_data["$constants"] = csrcGenerator(project_info)
226 mk_data["$prefix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[0])
227 mk_data["$suffix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[1])
228 mk_data["$main"] = os.path.basename(project_info.info("PROJECT_PATH")) + "/main.c"
230 while makefile.find(key) != -1:
231 makefile = makefile.replace(key, mk_data[key])
234 def makefileGenerator(project_info, makefile):
236 Generate the Makefile for the current project.
238 # TODO write a general function that works for both the mk file and the Makefile
239 while makefile.find("$pname") != -1:
240 makefile = makefile.replace("$pname", os.path.basename(project_info.info("PROJECT_PATH")))
243 def csrcGenerator(project_info):
244 modules = project_info.info("MODULES")
245 files = project_info.info("FILES")
246 if "harvard" in project_info.info("CPU_INFOS")["CPU_TAGS"]:
250 # file to be included in CSRC variable
252 # file to be included in PCSRC variable
254 # files to be included in CPPASRC variable
256 # files to be included in CXXSRC variable
258 # files to be included in ASRC variable
260 # constants to be included at the beginning of the makefile
262 for module, information in modules.items():
263 module_files = set([])
264 dependency_files = set([])
267 hwdir = os.path.basename(project_info.info("PROJECT_PATH")) + "/hw"
268 if information["enabled"]:
269 if "constants" in information:
270 constants.update(information["constants"])
271 cfiles, sfiles = findModuleFiles(module, project_info)
272 module_files |= set(cfiles)
273 asm_files |= set(sfiles)
274 for file in information["hw"]:
275 if file.endswith(".c"):
276 module_files |= set([hwdir + "/" + os.path.basename(file)])
277 for file_dependency in information["depends"]:
278 if file_dependency in files:
279 dependencyCFiles, dependencySFiles = findModuleFiles(file_dependency, project_info)
280 dependency_files |= set(dependencyCFiles)
281 asm_files |= set(dependencySFiles)
282 for file in module_files:
283 if not harvard or information.get("harvard", "both") == "both":
285 if harvard and "harvard" in information:
287 for file in dependency_files:
289 for file in project_info.info("CPU_INFOS")["C_SRC"]:
291 for file in project_info.info("CPU_INFOS")["PC_SRC"]:
293 for file in asm_files:
295 for file in project_info.info("CPU_INFOS")["CPPA_SRC"]:
297 for file in project_info.info("CPU_INFOS")["CXX_SRC"]:
299 for file in project_info.info("CPU_INFOS")["ASRC"]:
301 csrc = " \\\n\t".join(csrc) + " \\"
302 pcsrc = " \\\n\t".join(pcsrc) + " \\"
303 cppasrc = " \\\n\t".join(cppasrc) + " \\"
304 cxxsrc = " \\\n\t".join(cxxsrc) + " \\"
305 asrc = " \\\n\t".join(asrc) + " \\"
306 constants = "\n".join([os.path.basename(project_info.info("PROJECT_PATH")) + "_" + key + " = " + unicode(value) for key, value in constants.items()])
307 return csrc, pcsrc, cppasrc, cxxsrc, asrc, constants
309 def findModuleFiles(module, project_info):
310 # Find the files related to the selected module
313 # .c files related to the module and the cpu architecture
314 for filename, path in findDefinitions(module + ".c", project_info) + \
315 findDefinitions(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".c", project_info):
316 path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
317 path = replaceSeparators(path)
318 cfiles.append(path + "/" + filename)
319 # .s files related to the module and the cpu architecture
320 for filename, path in findDefinitions(module + ".s", project_info) + \
321 findDefinitions(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".s", project_info) + \
322 findDefinitions(module + ".S", project_info) + \
323 findDefinitions(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".S", project_info):
324 path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
325 path = replaceSeparators(path)
326 sfiles.append(path + "/" + filename)
327 # .c and .s files related to the module and the cpu tags
328 for tag in project_info.info("CPU_INFOS")["CPU_TAGS"]:
329 for filename, path in findDefinitions(module + "_" + tag + ".c", project_info):
330 path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
332 path = replaceSeparators(path)
333 cfiles.append(path + "/" + filename)
334 for filename, path in findDefinitions(module + "_" + tag + ".s", project_info) + \
335 findDefinitions(module + "_" + tag + ".S", project_info):
336 path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
337 path = replaceSeparators(path)
338 sfiles.append(path + "/" + filename)
339 return cfiles, sfiles
341 def replaceSeparators(path):
343 Replace the separators in the given path with unix standard separator.
346 while path.find(os.sep) != -1:
347 path = path.replace(os.sep, "/")
351 path = os.environ["PATH"]
353 path = path.split(";")
355 path = path.split(":")
358 def findToolchains(path_list):
360 for element in path_list:
361 for toolchain in glob.glob(element+ "/" + const.GCC_NAME):
362 toolchains.append(toolchain)
363 return list(set(toolchains))
365 def getToolchainInfo(output):
367 expr = re.compile("Target: .*")
368 target = expr.findall(output)
370 info["target"] = target[0].split("Target: ")[1]
371 expr = re.compile("gcc version [0-9,.]*")
372 version = expr.findall(output)
373 if len(version) == 1:
374 info["version"] = version[0].split("gcc version ")[1]
375 expr = re.compile("gcc version [0-9,.]* \(.*\)")
376 build = expr.findall(output)
378 build = build[0].split("gcc version ")[1]
379 build = build[build.find("(") + 1 : build.find(")")]
380 info["build"] = build
381 expr = re.compile("Configured with: .*")
382 configured = expr.findall(output)
383 if len(configured) == 1:
384 info["configured"] = configured[0].split("Configured with: ")[1]
385 expr = re.compile("Thread model: .*")
386 thread = expr.findall(output)
388 info["thread"] = thread[0].split("Thread model: ")[1]
391 def getToolchainName(toolchain_info):
392 name = "GCC " + toolchain_info["version"] + " - " + toolchain_info["target"].strip()
395 def loadSourceTree(project):
396 fileList = [f for f in os.walk(project.info("SOURCES_PATH"))]
397 project.setInfo("FILE_LIST", fileList)
399 def findDefinitions(ftype, project):
400 L = project.info("FILE_LIST")
403 for filename in element[2]:
404 if fnmatch.fnmatch(filename, ftype):
405 definitions.append((filename, element[0]))
408 def loadCpuInfos(project):
410 for definition in findDefinitions(const.CPU_DEFINITION, project):
411 cpuInfos.append(getInfos(definition))
414 def getTagSet(cpu_info):
417 tag_set |= set([cpu["CPU_NAME"]])
418 tag_set |= set(cpu["CPU_TAGS"])
419 tag_set |= set([cpu["TOOLCHAIN"]])
423 def getInfos(definition):
425 D.update(const.CPU_DEF)
426 def include(filename, dict = D, directory=definition[1]):
427 execfile(directory + "/" + filename, {}, D)
428 D["include"] = include
429 include(definition[0], D)
430 D["CPU_NAME"] = definition[0].split(".")[0]
431 D["DEFINITION_PATH"] = definition[1] + "/" + definition[0]
435 def getCommentList(string):
436 comment_list = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/", string)
437 comment_list = [re.findall(r"^\s*\* *(.*?)$", comment, re.MULTILINE) for comment in comment_list]
440 def loadModuleDefinition(first_comment):
442 module_definition = {}
443 for num, line in enumerate(first_comment):
444 index = line.find("$WIZ$")
448 exec line[index + len("$WIZ$ "):] in {}, module_definition
450 raise ParseError(num, line[index:])
451 elif line.find("\\brief") != -1:
452 module_definition["module_description"] = line[line.find("\\brief") + len("\\brief "):]
454 if "module_name" in module_definition:
455 module_name = module_definition[const.MODULE_DEFINITION["module_name"]]
456 del module_definition[const.MODULE_DEFINITION["module_name"]]
457 module_dict[module_name] = {}
458 if const.MODULE_DEFINITION["module_depends"] in module_definition:
459 depends = module_definition[const.MODULE_DEFINITION["module_depends"]]
460 del module_definition[const.MODULE_DEFINITION["module_depends"]]
461 if type(depends) == str:
463 module_dict[module_name]["depends"] = depends
465 module_dict[module_name]["depends"] = ()
466 if const.MODULE_DEFINITION["module_configuration"] in module_definition:
467 module_dict[module_name]["configuration"] = module_definition[const.MODULE_DEFINITION["module_configuration"]]
468 del module_definition[const.MODULE_DEFINITION["module_configuration"]]
470 module_dict[module_name]["configuration"] = ""
471 if "module_description" in module_definition:
472 module_dict[module_name]["description"] = module_definition["module_description"]
473 del module_definition["module_description"]
474 if const.MODULE_DEFINITION["module_harvard"] in module_definition:
475 harvard = module_definition[const.MODULE_DEFINITION["module_harvard"]]
476 module_dict[module_name]["harvard"] = harvard
477 del module_definition[const.MODULE_DEFINITION["module_harvard"]]
478 if const.MODULE_DEFINITION["module_hw"] in module_definition:
479 hw = module_definition[const.MODULE_DEFINITION["module_hw"]]
480 del module_definition[const.MODULE_DEFINITION["module_hw"]]
483 module_dict[module_name]["hw"] = hw
485 module_dict[module_name]["hw"] = ()
486 if const.MODULE_DEFINITION["module_supports"] in module_definition:
487 supports = module_definition[const.MODULE_DEFINITION["module_supports"]]
488 del module_definition[const.MODULE_DEFINITION["module_supports"]]
489 module_dict[module_name]["supports"] = supports
490 module_dict[module_name]["constants"] = module_definition
491 module_dict[module_name]["enabled"] = False
492 return to_be_parsed, module_dict
494 def isSupported(project, module=None, property_id=None):
495 if not module and property_id:
496 item = project.info("CONFIGURATIONS")[property_id[0]][property_id[1]]["informations"]
498 item = project.info("MODULES")[module]
499 tag_dict = project.info("ALL_CPU_TAGS")
500 if "supports" in item:
501 support_string = item["supports"]
504 exec "supported = " + support_string in tag_dict, supported
506 raise SupportedException(support_string)
507 return supported["supported"]
511 def loadDefineLists(comment_list):
513 for comment in comment_list:
514 for num, line in enumerate(comment):
515 index = line.find("$WIZ$")
518 exec line[index + len("$WIZ$ "):] in {}, define_list
520 raise ParseError(num, line[index:])
521 for key, value in define_list.items():
522 if type(value) == str:
523 define_list[key] = (value,)
526 def getDescriptionInformations(comment):
528 Take the doxygen comment and strip the wizard informations, returning the tuple
529 (comment, wizard_information)
534 for num, line in enumerate(comment):
535 index = line.find("$WIZ$")
538 brief += line[:index].strip()
540 description += " " + line[:index]
542 exec line[index + len("$WIZ$ "):] in {}, information
544 raise ParseError(num, line[index:])
547 brief += line.strip()
549 description += " " + line
550 description = description.strip()
551 return brief.strip(), description.strip(), information
553 def getDefinitionBlocks(text):
555 Take a text and return a list of tuple (description, name-value).
558 block_tmp = re.finditer(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE)
559 for match in block_tmp:
560 # Only the first element is needed
561 comment = match.group(1)
562 define = match.group(2)
563 start = match.start()
564 block.append(([re.findall(r"^\s*\* *(.*?)$", line, re.MULTILINE)[0] for line in comment.splitlines()], define, start))
565 for match in re.finditer(r"/{3}\s*([^<].*?)\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
566 comment = match.group(1)
567 define = match.group(2)
568 start = match.start()
569 block.append(([comment], define, start))
570 for match in re.finditer(r"#define\s*(.*?)\s*/{3}<\s*(.+?)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
571 comment = match.group(2)
572 define = match.group(1)
573 start = match.start()
574 block.append(([comment], define, start))
577 def loadModuleData(project, edit=False):
578 module_info_dict = {}
580 configuration_info_dict = {}
582 for filename, path in findDefinitions("*.h", project) + findDefinitions("*.c", project) + findDefinitions("*.s", project) + findDefinitions("*.S", project):
583 comment_list = getCommentList(open(path + "/" + filename, "r").read())
584 if len(comment_list) > 0:
586 configuration_info = {}
588 to_be_parsed, module_dict = loadModuleDefinition(comment_list[0])
589 except ParseError, err:
590 raise DefineException.ModuleDefineException(path, err.line_number, err.line)
591 for module, information in module_dict.items():
592 if "depends" not in information:
593 information["depends"] = ()
594 information["depends"] += (filename.split(".")[0],)
595 information["category"] = os.path.basename(path)
596 if "configuration" in information and len(information["configuration"]):
597 configuration = module_dict[module]["configuration"]
599 configuration_info[configuration] = loadConfigurationInfos(project.info("SOURCES_PATH") + "/" + configuration)
600 except ParseError, err:
601 raise DefineException.ConfigurationDefineException(project.info("SOURCES_PATH") + "/" + configuration, err.line_number, err.line)
604 path = os.path.basename(project.info("PROJECT_PATH"))
605 directory = project.info("PROJECT_PATH")
606 user_configuration = loadConfigurationInfos(directory + "/" + configuration.replace("bertos", path))
607 configuration_info[configuration] = updateConfigurationValues(configuration_info[configuration], user_configuration)
608 except ParseError, err:
609 raise DefineException.ConfigurationDefineException(directory + "/" + configuration.replace("bertos", path))
610 module_info_dict.update(module_dict)
611 configuration_info_dict.update(configuration_info)
614 list_dict = loadDefineLists(comment_list[1:])
615 list_info_dict.update(list_dict)
616 except ParseError, err:
617 raise DefineException.EnumDefineException(path, err.line_number, err.line)
618 for filename, path in findDefinitions("*_" + project.info("CPU_INFOS")["TOOLCHAIN"] + ".h", project):
619 comment_list = getCommentList(open(path + "/" + filename, "r").read())
620 list_info_dict.update(loadDefineLists(comment_list))
621 for tag in project.info("CPU_INFOS")["CPU_TAGS"]:
622 for filename, path in findDefinitions("*_" + tag + ".h", project):
623 comment_list = getCommentList(open(path + "/" + filename, "r").read())
624 list_info_dict.update(loadDefineLists(comment_list))
625 project.setInfo("MODULES", module_info_dict)
626 project.setInfo("LISTS", list_info_dict)
627 project.setInfo("CONFIGURATIONS", configuration_info_dict)
628 project.setInfo("FILES", file_dict)
630 def formatParamNameValue(text):
632 Take the given string and return a tuple with the name of the parameter in the first position
633 and the value in the second.
635 block = re.findall("\s*([^\s]+)\s*(.+?)\s*$", text, re.MULTILINE)
638 def loadConfigurationInfos(path):
640 Return the module configurations found in the given file as a dict with the
641 parameter name as key and a dict containig the fields above as value:
642 "value": the value of the parameter
643 "description": the description of the parameter
644 "informations": a dict containig optional informations:
645 "type": "int" | "boolean" | "enum"
646 "min": the minimum value for integer parameters
647 "max": the maximum value for integer parameters
648 "long": boolean indicating if the num is a long
649 "unsigned": boolean indicating if the num is an unsigned
650 "value_list": the name of the enum for enum parameters
652 configuration_infos = {}
653 configuration_infos["paramlist"] = []
654 for comment, define, start in getDefinitionBlocks(open(path, "r").read()):
655 name, value = formatParamNameValue(define)
656 brief, description, informations = getDescriptionInformations(comment)
657 configuration_infos["paramlist"].append((start, name))
658 configuration_infos[name] = {}
659 configuration_infos[name]["value"] = value
660 configuration_infos[name]["informations"] = informations
661 if not "type" in configuration_infos[name]["informations"]:
662 configuration_infos[name]["informations"]["type"] = findParameterType(configuration_infos[name])
663 if ("type" in configuration_infos[name]["informations"] and
664 configuration_infos[name]["informations"]["type"] == "int" and
665 configuration_infos[name]["value"].find("L") != -1):
666 configuration_infos[name]["informations"]["long"] = True
667 configuration_infos[name]["value"] = configuration_infos[name]["value"].replace("L", "")
668 if ("type" in configuration_infos[name]["informations"] and
669 configuration_infos[name]["informations"]["type"] == "int" and
670 configuration_infos[name]["value"].find("U") != -1):
671 configuration_infos[name]["informations"]["unsigned"] = True
672 configuration_infos[name]["value"] = configuration_infos[name]["value"].replace("U", "")
673 configuration_infos[name]["description"] = description
674 configuration_infos[name]["brief"] = brief
675 return configuration_infos
677 def updateConfigurationValues(def_conf, user_conf):
678 for param in def_conf["paramlist"]:
679 def_conf[param[1]]["value"] = user_conf[param[1]]["value"]
682 def findParameterType(parameter):
683 if "value_list" in parameter["informations"]:
685 if "min" in parameter["informations"] or "max" in parameter["informations"] or re.match(r"^\d+U?L?$", parameter["value"]) != None:
688 def sub(string, parameter, value):
690 Substitute the given value at the given parameter define in the given string
692 return re.sub(r"(?P<define>#define\s+" + parameter + r"\s+)([^\s]+)", r"\g<define>" + value, string)
694 def isInt(informations):
696 Return True if the value is a simple int.
698 if ("long" not in informatios or not informations["long"]) and ("unsigned" not in informations or informations["unsigned"]):
703 def isLong(informations):
705 Return True if the value is a long.
707 if "long" in informations and informations["long"] and "unsigned" not in informations:
712 def isUnsigned(informations):
714 Return True if the value is an unsigned.
716 if "unsigned" in informations and informations["unsigned"] and "long" not in informations:
721 def isUnsignedLong(informations):
723 Return True if the value is an unsigned long.
725 if "unsigned" in informations and "long" in informations and informations["unsigned"] and informations["long"]:
730 class ParseError(Exception):
731 def __init__(self, line_number, line):
732 Exception.__init__(self)
733 self.line_number = line_number
736 class SupportedException(Exception):
737 def __init__(self, support_string):
738 Exception.__init__(self)
739 self.support_string = support_string