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