Add the findToolchains function that allow to find the files that match the toolchain...
[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 import glob
15
16 import const
17
18 def isBertosDir(directory):
19    return os.path.exists(directory + "/VERSION")
20
21 def bertosVersion(directory):
22    return open(directory + "/VERSION").readline().strip()
23
24 def createBertosProject(directory):
25     if not os.path.isdir(directory):
26         os.mkdir(directory)
27     open(directory + "/project.bertos", "w")
28
29 def findToolchains(pathList):
30     toolchains = []
31     for element in pathList:
32         toolchains += glob.glob(element+ "/" + const.GCC_NAME)
33     return toolchains
34
35 def findDefinitions(ftype, path):
36     L = os.walk(path)
37     for element in L:
38         for filename in element[2]:
39             if fnmatch.fnmatch(filename, ftype):
40                 yield (filename, element[0])
41
42 def loadCpuInfos(path):
43     cpuInfos = []
44     for definition in findDefinitions(const.CPU_DEFINITION, path):
45         D = {}
46         D.update(const.CPU_DEF)
47         def include(filename, dict = D, directory=definition[1]):
48             execfile(directory + "/" + filename, {}, D)
49         D["include"] = include
50         include(definition[0], D)
51         D["CPU_NAME"] = definition[0].split(".")[0]
52         cpuInfos.append(D)
53     return cpuInfos