Add the const string containing the pattern of the cpu definition filenames
[bertos.git] / wizard / bertos_utils.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
5 # All rights reserved.
6 #
7 # $Id:$
8 #
9 # Author: Lorenzo Berni <duplo@develer.com>
10 #
11
12 import os
13 import fnmatch
14
15 import const
16
17 def isBertosDir(directory):
18    return os.path.exists(directory + "/VERSION")
19
20 def bertosVersion(directory):
21    return open(directory + "/VERSION").readline().strip()
22
23 def createBertosProject(directory):
24     if not os.path.isdir(directory):
25         os.mkdir(directory)
26     open(directory + "/project.bertos", "w")
27
28 def findDefinitions(ftype, path):
29     L = os.walk(path)
30     for element in L:
31         for filename in element[2]:
32             if fnmatch.fnmatch(filename, ftype):
33                 yield (filename, element[0])
34
35 def loadCpuInfos(path):
36     cpuInfos = []
37     for definition in findDefinitions(const.CPU_DEFINITION, path):
38         D = {}
39         D.update(const.CPU_DEF)
40         def include(filename, dict = D, directory=definition[1]):
41             execfile(directory + "/" + filename, {}, D)
42         D["include"] = include
43         include(definition[0], D)
44         D["CPU_NAME"] = definition[0].split(".")[0]
45         cpuInfos.append(D)
46     return cpuInfos