Add the getSystemPath function that returns a list of string containig the path
[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 getSystemPath():
30     path = os.environ["PATH"]
31     if os.name == "nt":
32         path = path.split(";")
33     else:
34         path = path.split(":")
35     return path
36
37 def findToolchains(pathList):
38     toolchains = []
39     for element in pathList:
40         toolchains += glob.glob(element+ "/" + const.GCC_NAME)
41     return toolchains
42
43 def findDefinitions(ftype, path):
44     L = os.walk(path)
45     for element in L:
46         for filename in element[2]:
47             if fnmatch.fnmatch(filename, ftype):
48                 yield (filename, element[0])
49
50 def loadCpuInfos(path):
51     cpuInfos = []
52     for definition in findDefinitions(const.CPU_DEFINITION, path):
53         D = {}
54         D.update(const.CPU_DEF)
55         def include(filename, dict = D, directory=definition[1]):
56             execfile(directory + "/" + filename, {}, D)
57         D["include"] = include
58         include(definition[0], D)
59         D["CPU_NAME"] = definition[0].split(".")[0]
60         cpuInfos.append(D)
61     return cpuInfos