Order the toolchains:
[bertos.git] / wizard / bertos_utils.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # This file is part of BeRTOS.
5 #
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.
10 #
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.
15 #
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
19 #
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.
28 #
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
30 #
31 #
32 # Author: Lorenzo Berni <duplo@develer.com>
33 #
34
35 import os
36 import fnmatch
37 import glob
38 import re
39 import shutil
40 # Use custom copytree function
41 import copytree
42 import relpath
43 import pickle
44
45 import const
46 import plugins
47 import DefineException
48
49 from _wizard_version import WIZARD_VERSION
50
51 from LoadException import VersionException, ToolchainException
52
53 def _cmp(x, y):
54     result = cmp(x["info"].get('ord', 0), y["info"].get('ord', 0))
55     if result == 0:
56         result = cmp(
57             x["info"].get("name", x["info"]["filename"]).lower(),
58             y["info"].get("name", y["info"]["filename"]).lower()
59         )
60     return result
61
62 def isBertosDir(directory):
63    return os.path.exists(directory + "/VERSION")
64
65 def bertosVersion(directory):
66    return open(directory + "/VERSION").readline().strip()
67
68 def enabledModules(project_info):
69     enabled_modules = []
70     for name, module in project_info.info("MODULES").items():
71         if module["enabled"]:
72             enabled_modules.append(name)
73     return enabled_modules
74
75 def presetList(directory):
76     """
77     Return the list of the preset found in the selected BeRTOS Version.
78     """
79     abspath = os.path.join(directory, const.PREDEFINED_BOARDS_DIR)
80     preset_list = dict([
81         (os.path.join(abspath, preset_dir), presetInfo(os.path.join(abspath, preset_dir)))
82         for preset_dir in os.listdir(os.path.join(directory, const.PREDEFINED_BOARDS_DIR))
83     ])
84     return preset_list
85
86 def presetInfo(preset_dir):
87     """
88     Return the preset-relevant info contined into the project_file.
89     """
90     preset_info = pickle.loads(open(os.path.join(preset_dir, "project.bertos"), "r").read())
91     try:
92         description = open(os.path.join(preset_dir, "description"), "r").read()
93     except IOError:
94         # No description file found.
95         description = ""
96     relevant_info = {
97         "CPU_NAME": preset_info.get("CPU_NAME"),
98         "SELECTED_FREQ": preset_info.get("SELECTED_FREQ"),
99         "WIZARD_VERSION": preset_info.get("WIZARD_VERSION", None),
100         "PRESET_NAME": preset_info.get("PROJECT_NAME"),
101         "PRESET_DESCRIPTION": description.decode("utf-8"),
102     }
103     return relevant_info
104
105 def mergeSources(srcdir, new_sources, old_sources):
106     # The current mergeSources function provide only a raw copy of the sources in the
107     # created project.
108     #
109     # TODO: implement the three way merge algorithm
110     #
111     shutil.rmtree(srcdir, True)
112     copytree.copytree(os.path.join(new_sources, "bertos"), srcdir, ignore_list=const.IGNORE_LIST)
113
114 def projectFileGenerator(project_info):
115     directory = project_info.info("PROJECT_PATH")
116     project_data = {}
117     enabled_modules = []
118     for module, information in project_info.info("MODULES").items():
119         if information["enabled"]:
120             enabled_modules.append(module)
121     project_data["ENABLED_MODULES"] = enabled_modules
122     if project_info.info("PRESET"):
123         # For presets save again the BERTOS_PATH into project file
124         project_data["PRESET"] = True
125         project_data["BERTOS_PATH"] = relpath.relpath(project_info.info("BERTOS_PATH"), directory)
126     elif project_info.edit:
127         # If in editing mode the BERTOS_PATH is maintained
128         project_data["BERTOS_PATH"] = relpath.relpath(project_info.info("BERTOS_PATH"), directory)
129     else:
130         # Use the local BeRTOS version instead of the original one
131         # project_data["BERTOS_PATH"] = project_info.info("BERTOS_PATH")
132         project_data["BERTOS_PATH"] = "."
133     project_data["PROJECT_NAME"] = project_info.info("PROJECT_NAME", os.path.basename(directory))
134     project_src_relpath = relpath.relpath(project_info.info("PROJECT_SRC_PATH"), directory)
135     project_data["PROJECT_SRC_PATH"] = project_src_relpath
136     project_data["TOOLCHAIN"] = project_info.info("TOOLCHAIN")
137     project_data["CPU_NAME"] = project_info.info("CPU_NAME")
138     project_data["SELECTED_FREQ"] = project_info.info("SELECTED_FREQ")
139     project_data["OUTPUT"] = project_info.info("OUTPUT")
140     project_data["WIZARD_VERSION"] = WIZARD_VERSION
141     project_data["PRESET"] = project_info.info("PRESET")
142     project_data["PROJECT_HW_PATH"] = relpath.relpath(project_info.info("PROJECT_HW_PATH"), directory)
143     return pickle.dumps(project_data)
144
145 def loadPlugin(plugin):
146     """
147     Returns the given plugin module.
148     """
149     return getattr(__import__("plugins", {}, {}, [plugin]), plugin)
150
151 def versionFileGenerator(project_info, version_file):
152     version = bertosVersion(project_info.info("BERTOS_PATH"))
153     return version_file.replace('$version', version)
154
155 def userMkGeneratorFromPreset(project_info):
156     project_name = project_info.info("PROJECT_NAME")
157     preset_path = project_info.info("PRESET_PATH")
158     preset_name = project_info.info("PRESET_NAME")
159     preset_src_dir = project_info.info("PRESET_SRC_PATH")
160     makefile = open(os.path.join(preset_path, preset_src_dir, "%s_user.mk" %preset_name), 'r').read()
161     destination = os.path.join(project_info.prjdir, "%s_user.mk" %project_info.info("PROJECT_NAME"))
162     # Temporary code.
163     # TODO: write it using regular expressions to secure this function
164     makefile = makefile.replace(preset_name + "_", project_name + "_")
165     open(destination, "w").write(makefile)
166
167 def userMkGenerator(project_info):
168     makefile = open(os.path.join(const.DATA_DIR, "mktemplates/template_user.mk"), "r").read()
169     destination = os.path.join(project_info.prjdir, os.path.basename(project_info.prjdir) + "_user.mk")
170     # Deadly performances loss was here :(
171     mk_data = {}
172     mk_data["$pname"] = os.path.basename(project_info.info("PROJECT_PATH"))
173     mk_data["$ppath"] = relpath.relpath(project_info.info("PROJECT_SRC_PATH"), project_info.info("PROJECT_PATH"))
174     mk_data["$main"] = "/".join(["$(%s_SRC_PATH)" %project_info.info("PROJECT_NAME"), "main.c"])
175     for key in mk_data:
176         makefile = makefile.replace(key, mk_data[key])
177     open(destination, "w").write(makefile)
178
179 def mkGenerator(project_info):
180     """
181     Generates the mk file for the current project.
182     """
183     makefile = open(os.path.join(const.DATA_DIR, "mktemplates/template.mk"), "r").read()
184     prjdir = os.path.abspath(project_info.prjdir)
185     destination = os.path.join(prjdir, os.path.basename(prjdir) + ".mk")
186     mk_data = {}
187     mk_data["$pname"] = project_info.info("PROJECT_NAME")
188     mk_data["$ppath"] = relpath.relpath(project_info.info("PROJECT_SRC_PATH"), project_info.info("PROJECT_PATH"))
189     mk_data["$cpuclockfreq"] = project_info.info("SELECTED_FREQ")
190     cpu_mk_parameters = []
191     for key, value in project_info.info("CPU_INFOS").items():
192         if key.startswith(const.MK_PARAM_ID):
193             cpu_mk_parameters.append("%s = %s" %(key.replace("MK", mk_data["$pname"]), value))
194     mk_data["$cpuparameters"] = "\n".join(cpu_mk_parameters)
195     mk_data["$csrc"], mk_data["$pcsrc"], mk_data["$cppasrc"], mk_data["$cxxsrc"], mk_data["$asrc"], mk_data["$constants"] = csrcGenerator(project_info)
196     mk_data["$prefix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].rsplit("gcc", 1)[0])
197     mk_data["$suffix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].rsplit("gcc", 1)[1])
198     mk_data["$hwpath"] = relpath.relpath(project_info.info("PROJECT_HW_PATH"), project_info.info("PROJECT_PATH"))
199     for key in mk_data:
200         makefile = makefile.replace(key, mk_data[key])
201     open(destination, "w").write(makefile)
202
203 def makefileGenerator(project_info):
204     """
205     Generate the Makefile for the current project.
206     """
207     makefile = open(os.path.join(const.DATA_DIR, "mktemplates/Makefile"), "r").read()
208     destination = os.path.join(project_info.maindir, "Makefile")
209     # TODO write a general function that works for both the mk file and the Makefile
210     mk_data = {}
211     mk_data["$pname"] = project_info.info("PROJECT_NAME")
212     mk_data["$ppath"] = relpath.relpath(project_info.info("PROJECT_SRC_PATH"), project_info.info("PROJECT_PATH"))
213     for key in mk_data:
214         makefile = makefile.replace(key, mk_data[key])
215     open(destination, "w").write(makefile)
216
217 def csrcGenerator(project_info):
218     modules = project_info.info("MODULES")
219     files = project_info.info("FILES")
220     if "harvard" in project_info.info("CPU_INFOS")["CPU_TAGS"]:
221         harvard = True
222     else:
223         harvard = False
224     # file to be included in CSRC variable
225     csrc = []
226     # file to be included in PCSRC variable
227     pcsrc = []
228     # files to be included in CPPASRC variable
229     cppasrc = []
230     # files to be included in CXXSRC variable
231     cxxsrc = []
232     # files to be included in ASRC variable
233     asrc = []
234     # constants to be included at the beginning of the makefile
235     constants = {}
236     for module, information in modules.items():
237         module_files = set([])
238         dependency_files = set([])
239         # assembly sources
240         asm_files = set([])
241         hwdir = os.path.basename(project_info.info("PROJECT_PATH")) + "/hw"
242         if information["enabled"]:
243             if "constants" in information:
244                 constants.update(information["constants"])
245             cfiles, sfiles = findModuleFiles(module, project_info)
246             module_files |= set(cfiles)
247             asm_files |= set(sfiles)
248             for file in information["hw"]:
249                 if file.endswith(".c"):
250                     module_files |= set([hwdir + "/" + os.path.basename(file)])
251             for file_dependency in information["depends"] + tuple(files.keys()):
252                     dependencyCFiles, dependencySFiles = findModuleFiles(file_dependency, project_info)
253                     dependency_files |= set(dependencyCFiles)
254                     asm_files |= set(dependencySFiles)
255             for file in module_files:
256                 if not harvard or information.get("harvard", "both") == "both":
257                     csrc.append(file)
258                 if harvard and "harvard" in information:
259                     pcsrc.append(file)
260             for file in dependency_files:
261                 csrc.append(file)
262             for file in project_info.info("CPU_INFOS")["C_SRC"]:
263                 csrc.append(file)
264             for file in project_info.info("CPU_INFOS")["PC_SRC"]:
265                 pcsrc.append(file)
266             for file in asm_files:
267                 cppasrc.append(file)
268     for file in project_info.info("CPU_INFOS")["CPPA_SRC"]:
269         cppasrc.append(file)
270     for file in project_info.info("CPU_INFOS")["CXX_SRC"]:
271         cxxsrc.append(file)
272     for file in project_info.info("CPU_INFOS")["ASRC"]:
273         asrc.append(file)
274     csrc = set(csrc)
275     csrc = " \\\n\t".join(csrc) + " \\"
276     pcsrc = set(pcsrc)
277     pcsrc = " \\\n\t".join(pcsrc) + " \\"
278     cppasrc = set(cppasrc)
279     cppasrc = " \\\n\t".join(cppasrc) + " \\"
280     cxxsrc = set(cxxsrc)
281     cxxsrc = " \\\n\t".join(cxxsrc) + " \\"
282     asrc = set(asrc)
283     asrc = " \\\n\t".join(asrc) + " \\"
284     constants = "\n".join([os.path.basename(project_info.info("PROJECT_PATH")) + "_" + key + " = " + unicode(value) for key, value in constants.items()])
285     return csrc, pcsrc, cppasrc, cxxsrc, asrc, constants
286
287 def findModuleFiles(module, project_info):
288     # Find the files related to the selected module
289     cfiles = []
290     sfiles = []
291     # .c files related to the module and the cpu architecture
292     for filename, path in project_info.searchFiles(module + ".c"):
293         path = path.replace(project_info.info("BERTOS_PATH") + os.sep, "")
294         path = replaceSeparators(path)
295         cfiles.append(path + "/" + filename)
296     # .s files related to the module and the cpu architecture
297     for filename, path in project_info.searchFiles(module + ".s") + \
298             project_info.searchFiles(module + ".S"):
299         path = path.replace(project_info.info("BERTOS_PATH") + os.sep, "")
300         path = replaceSeparators(path)
301         sfiles.append(path + "/" + filename)
302     # .c and .s files related to the module and the cpu tags
303     tags = project_info.info("CPU_INFOS")["CPU_TAGS"]
304
305     # Awful, but secure check for version
306     # TODO: split me in a method/function
307     try:
308         version_string = bertosVersion(project_info.info("BERTOS_PATH"))
309         version_list = [int(i) for i in version_string.split()[1].split('.')]
310     except ValueError:
311         # If the version file hasn't a valid version number assume it's an older
312         # project.
313         version_list = [0, 0]
314     if version_list < [2, 5]:
315         # For older versions of BeRTOS add the toolchain to the tags
316         tags.append(project_info.info("CPU_INFOS")["TOOLCHAIN"])
317
318     for tag in tags:
319         for filename, path in project_info.searchFiles(module + "_" + tag + ".c"):
320             path = path.replace(project_info.info("BERTOS_PATH") + os.sep, "")
321             if os.sep != "/":
322                 path = replaceSeparators(path)
323             cfiles.append(path + "/" + filename)
324         for filename, path in project_info.searchFiles(module + "_" + tag + ".s") + \
325                 project_info.searchFiles(module + "_" + tag + ".S"):
326             path = path.replace(project_info.info("BERTOS_PATH") + os.sep, "")
327             path = replaceSeparators(path)
328             sfiles.append(path + "/" + filename)
329     return cfiles, sfiles
330
331 def replaceSeparators(path):
332     """
333     Replace the separators in the given path with unix standard separator.
334     """
335     if os.sep != "/":
336         path = path.replace(os.sep, "/")
337     return path
338
339 def getSystemPath():
340     path = os.environ["PATH"]
341     if os.name == "nt":
342         path = path.split(";")
343     else:
344         path = path.split(":")
345     return path
346
347 def findToolchains(path_list):
348     toolchains = []
349     for element in path_list:
350         for toolchain in glob.glob(element+ "/" + const.GCC_NAME):
351             toolchains.append(toolchain)
352     return list(set(toolchains))
353
354 def getToolchainInfo(output):
355     info = {}
356     expr = re.compile("Target: .*")
357     target = expr.findall(output)
358     if len(target) == 1:
359         info["target"] = target[0].split("Target: ")[1]
360     expr = re.compile("gcc version [0-9,.]*")
361     version = expr.findall(output)
362     if len(version) == 1:
363         info["version"] = version[0].split("gcc version ")[1]
364     expr = re.compile("gcc version [0-9,.]* \(.*\)")
365     build = expr.findall(output)
366     if len(build) == 1:
367         build = build[0].split("gcc version ")[1]
368         build = build[build.find("(") + 1 : build.find(")")]
369         info["build"] = build
370     expr = re.compile("Configured with: .*")
371     configured = expr.findall(output)
372     if len(configured) == 1:
373         info["configured"] = configured[0].split("Configured with: ")[1]
374     expr = re.compile("Thread model: .*")
375     thread = expr.findall(output)
376     if len(thread) == 1:
377         info["thread"] = thread[0].split("Thread model: ")[1]
378     return info
379
380 def getToolchainName(toolchain_info):
381     name = "GCC " + toolchain_info["version"] + " - " + toolchain_info["target"].strip()
382     return name
383
384 def getTagSet(cpu_info):
385     tag_set = set([])
386     for cpu in cpu_info:
387         tag_set |= set([cpu["CPU_NAME"]])
388         tag_set |= set(cpu["CPU_TAGS"])
389         tag_set |= set([cpu["TOOLCHAIN"]])
390     return tag_set
391
392
393 def getInfos(definition):
394     D = {}
395     D.update(const.CPU_DEF)
396     def include(filename, dict = D, directory=definition[1]):
397         execfile(directory + "/" + filename, {}, D)
398     D["include"] = include
399     include(definition[0], D)
400     D["CPU_NAME"] = definition[0].split(".")[0]
401     D["DEFINITION_PATH"] = definition[1] + "/" + definition[0]
402     del D["include"]
403     return D
404
405 def getCommentList(string):
406     comment_list = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/", string)
407     comment_list = [re.findall(r"^\s*\* *(.*?)$", comment, re.MULTILINE) for comment in comment_list]
408     return comment_list
409
410 def loadModuleDefinition(first_comment):
411     to_be_parsed = False
412     module_definition = {}
413     for num, line in enumerate(first_comment):
414         index = line.find("$WIZ$")
415         if index != -1:
416             to_be_parsed = True
417             try:
418                 exec line[index + len("$WIZ$ "):] in {}, module_definition
419             except:
420                 raise ParseError(num, line[index:])
421         elif line.find("\\brief") != -1:
422             module_definition["module_description"] = line[line.find("\\brief") + len("\\brief "):]
423     module_dict = {}
424     if "module_name" in module_definition:
425         module_name = module_definition[const.MODULE_DEFINITION["module_name"]]
426         del module_definition[const.MODULE_DEFINITION["module_name"]]
427         module_dict[module_name] = {}
428         if const.MODULE_DEFINITION["module_depends"] in module_definition:
429             depends = module_definition[const.MODULE_DEFINITION["module_depends"]]
430             del module_definition[const.MODULE_DEFINITION["module_depends"]]
431             if type(depends) == str:
432                 depends = (depends,)
433             module_dict[module_name]["depends"] = depends
434         else:
435             module_dict[module_name]["depends"] = ()
436         if const.MODULE_DEFINITION["module_configuration"] in module_definition:
437             module_dict[module_name]["configuration"] = module_definition[const.MODULE_DEFINITION["module_configuration"]]
438             del module_definition[const.MODULE_DEFINITION["module_configuration"]]
439         else:
440             module_dict[module_name]["configuration"] = ""
441         if "module_description" in module_definition:
442             module_dict[module_name]["description"] = module_definition["module_description"]
443             del module_definition["module_description"]
444         if const.MODULE_DEFINITION["module_harvard"] in module_definition:
445             harvard = module_definition[const.MODULE_DEFINITION["module_harvard"]]
446             module_dict[module_name]["harvard"] = harvard
447             del module_definition[const.MODULE_DEFINITION["module_harvard"]]
448         if const.MODULE_DEFINITION["module_hw"] in module_definition:
449             hw = module_definition[const.MODULE_DEFINITION["module_hw"]]
450             del module_definition[const.MODULE_DEFINITION["module_hw"]]
451             if type(hw) == str:
452                 hw = (hw, )
453             module_dict[module_name]["hw"] = hw
454         else:
455             module_dict[module_name]["hw"] = ()
456         if const.MODULE_DEFINITION["module_supports"] in module_definition:
457             supports = module_definition[const.MODULE_DEFINITION["module_supports"]]
458             del module_definition[const.MODULE_DEFINITION["module_supports"]]
459             module_dict[module_name]["supports"] = supports
460         module_dict[module_name]["constants"] = module_definition
461         module_dict[module_name]["enabled"] = False
462     return to_be_parsed, module_dict
463
464 def isSupported(project, module=None, property_id=None):
465     if not module and property_id:
466         item = project.info("CONFIGURATIONS")[property_id[0]][property_id[1]]["informations"]
467     else:
468         item = project.info("MODULES")[module]
469     tag_dict = project.info("ALL_CPU_TAGS")
470     if "supports" in item:
471         support_string = item["supports"]
472         supported = {}
473         try:
474             exec "supported = " + support_string in tag_dict, supported
475         except:
476             raise SupportedException(support_string)
477         return supported["supported"]
478     else:
479         return True
480
481 def loadDefineLists(comment_list):
482     define_list = {}
483     for comment in comment_list:
484         for num, line in enumerate(comment):
485             index = line.find("$WIZ$")
486             if index != -1:
487                 try:
488                     exec line[index + len("$WIZ$ "):] in {}, define_list
489                 except:
490                     raise ParseError(num, line[index:])
491     for key, value in define_list.items():
492         if type(value) == str:
493             define_list[key] = (value,)
494     return define_list
495
496 def getDescriptionInformations(comment):
497     """
498     Take the doxygen comment and strip the wizard informations, returning the tuple
499     (comment, wizard_information)
500     """
501     brief = ""
502     description = ""
503     information = {}
504     for num, line in enumerate(comment):
505         index = line.find("$WIZ$")
506         if index != -1:
507             if len(brief) == 0:
508                 brief += line[:index].strip()
509             else:
510                 description += " " + line[:index]
511             try:
512                 exec line[index + len("$WIZ$ "):] in {}, information
513             except:
514                 raise ParseError(num, line[index:])
515         else:
516             if len(brief) == 0:
517                 brief += line.strip()
518             else:
519                 description += " " + line
520                 description = description.strip()
521     return brief.strip(), description.strip(), information
522
523 def getDefinitionBlocks(text):
524     """
525     Take a text and return a list of tuple (description, name-value).
526     """
527     block = []
528     block_tmp = re.finditer(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE)
529     for match in block_tmp:
530         # Only the first element is needed
531         comment = match.group(1)
532         define = match.group(2)
533         start = match.start()
534         block.append(([re.findall(r"^\s*\* *(.*?)$", line, re.MULTILINE)[0] for line in comment.splitlines()], define, start))
535     for match in re.finditer(r"/{3}\s*([^<].*?)\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
536         comment = match.group(1)
537         define = match.group(2)
538         start = match.start()
539         block.append(([comment], define, start))
540     for match in re.finditer(r"#define\s*(.*?)\s*/{3}<\s*(.+?)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
541         comment = match.group(2)
542         define = match.group(1)
543         start = match.start()
544         block.append(([comment], define, start))
545     return block
546
547 def formatParamNameValue(text):
548     """
549     Take the given string and return a tuple with the name of the parameter in the first position
550     and the value in the second.
551     """
552     block = re.findall("\s*([^\s]+)\s*(.+?)\s*$", text, re.MULTILINE)
553     return block[0]
554
555 def loadConfigurationInfos(path):
556     """
557     Return the module configurations found in the given file as a dict with the
558     parameter name as key and a dict containig the fields above as value:
559         "value": the value of the parameter
560         "description": the description of the parameter
561         "informations": a dict containig optional informations:
562             "type": "int" | "boolean" | "enum"
563             "min": the minimum value for integer parameters
564             "max": the maximum value for integer parameters
565             "long": boolean indicating if the num is a long
566             "unsigned": boolean indicating if the num is an unsigned
567             "value_list": the name of the enum for enum parameters
568             "conditional_deps": the list of conditional dependencies for boolean parameters
569     """
570     configuration_infos = {}
571     configuration_infos["paramlist"] = []
572     for comment, define, start in getDefinitionBlocks(open(path, "r").read()):
573         name, value = formatParamNameValue(define)
574         brief, description, informations = getDescriptionInformations(comment)
575         configuration_infos["paramlist"].append((start, name))
576         configuration_infos[name] = {}
577         configuration_infos[name]["value"] = value
578         configuration_infos[name]["informations"] = informations
579         if not "type" in configuration_infos[name]["informations"]:
580             configuration_infos[name]["informations"]["type"] = findParameterType(configuration_infos[name])
581         if ("type" in configuration_infos[name]["informations"] and
582                 configuration_infos[name]["informations"]["type"] == "int" and
583                 configuration_infos[name]["value"].find("L") != -1):
584             configuration_infos[name]["informations"]["long"] = True
585             configuration_infos[name]["value"] = configuration_infos[name]["value"].replace("L", "")
586         if ("type" in configuration_infos[name]["informations"] and
587                 configuration_infos[name]["informations"]["type"] == "int" and
588                 configuration_infos[name]["value"].find("U") != -1):
589             configuration_infos[name]["informations"]["unsigned"] = True
590             configuration_infos[name]["value"] = configuration_infos[name]["value"].replace("U", "")
591         if "conditional_deps" in configuration_infos[name]["informations"]:
592             if (type(configuration_infos[name]["informations"]["conditional_deps"]) == str or
593                     type(configuration_infos[name]["informations"]["conditional_deps"]) == unicode):
594                 configuration_infos[name]["informations"]["conditional_deps"] = (configuration_infos[name]["informations"]["conditional_deps"], )
595             elif type(configuration_infos[name]["informations"]["conditional_deps"]) == tuple:
596                 pass
597             else:
598                 configuration_infos[name]["informations"]["conditional_deps"] = ()
599         configuration_infos[name]["description"] = description
600         configuration_infos[name]["brief"] = brief
601     return configuration_infos
602
603 def updateConfigurationValues(def_conf, user_conf):
604     for param in def_conf["paramlist"]:
605         if param[1] in user_conf and "value" in user_conf[param[1]]:
606             def_conf[param[1]]["value"] = user_conf[param[1]]["value"]
607     return def_conf
608
609 def findParameterType(parameter):
610     if "value_list" in parameter["informations"]:
611         return "enum"
612     if "min" in parameter["informations"] or "max" in parameter["informations"] or re.match(r"^\d+U?L?$", parameter["value"]) != None:
613         return "int"
614
615 def sub(string, parameter, value):
616     """
617     Substitute the given value at the given parameter define in the given string
618     """
619     return re.sub(r"(?P<define>#define\s+" + parameter + r"\s+)([^\s]+)", r"\g<define>" + value, string)
620
621 def isInt(informations):
622     """
623     Return True if the value is a simple int.
624     """
625     if ("long" not in informatios or not informations["long"]) and ("unsigned" not in informations or informations["unsigned"]):
626         return True
627     else:
628         return False
629
630 def isLong(informations):
631     """
632     Return True if the value is a long.
633     """
634     if "long" in informations and informations["long"] and "unsigned" not in informations:
635         return True
636     else:
637         return False
638
639 def isUnsigned(informations):
640     """
641     Return True if the value is an unsigned.
642     """
643     if "unsigned" in informations and informations["unsigned"] and "long" not in informations:
644         return True
645     else:
646         return False
647
648 def isUnsignedLong(informations):
649     """
650     Return True if the value is an unsigned long.
651     """
652     if "unsigned" in informations and "long" in informations and informations["unsigned"] and informations["long"]:
653         return True
654     else:
655         return False
656
657 class ParseError(Exception):
658     def __init__(self, line_number, line):
659         Exception.__init__(self)
660         self.line_number = line_number
661         self.line = line
662
663 class SupportedException(Exception):
664     def __init__(self, support_string):
665         Exception.__init__(self)
666         self.support_string = support_string