Parse the filename for find the cpu name
[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 def isBertosDir(directory):
16    return os.path.exists(directory + "/VERSION")
17
18 def bertosVersion(directory):
19    return open(directory + "/VERSION").readline().strip()
20
21 def createBertosProject(directory):
22     if not os.path.isdir(directory):
23         os.mkdir(directory)
24     open(directory + "/project.bertos", "w")
25
26 def findDefinitions(ftype, path):
27     L = os.walk(path)
28     for element in L:
29         for filename in element[2]:
30             if fnmatch.fnmatch(filename, "*." + ftype):
31                 yield (filename, element[0])
32
33 def loadCpuInfos(path):
34     cpuInfos = []
35     for definition in findDefinitions("cdef", path):
36         D = {}
37         def include(filename, dict = D, directory=definition[1]):
38             execfile(directory + "/" + filename, {}, D)
39         D["include"] = include
40         include(definition[0], D)
41         D["CPU_NAME"] = definition[0].split(".")[0]
42         cpuInfos.append(D)
43     return cpuInfos