Improve the validation process, showing the results
[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 import re
16
17 import const
18
19 def isBertosDir(directory):
20    return os.path.exists(directory + "/VERSION")
21
22 def bertosVersion(directory):
23    return open(directory + "/VERSION").readline().strip()
24
25 def createBertosProject(directory):
26     if not os.path.isdir(directory):
27         os.mkdir(directory)
28     open(directory + "/project.bertos", "w")
29
30 def getSystemPath():
31     path = os.environ["PATH"]
32     if os.name == "nt":
33         path = path.split(";")
34     else:
35         path = path.split(":")
36     return path
37
38 def findToolchains(pathList):
39     toolchains = []
40     for element in pathList:
41         toolchains += glob.glob(element+ "/" + const.GCC_NAME)
42     return toolchains
43
44 def getToolchainInfo(output):
45     info = {}
46     expr = re.compile("Target: .*")
47     target = expr.findall(output)
48     if len(target) == 1:
49         info["target"] = target[0].split("Target: ")[1]
50     expr = re.compile("gcc version .*")
51     version = expr.findall(output)
52     if len(version) == 1:
53         info["version"] = version[0].split("gcc version ")[1]
54     expr = re.compile("Configured with: .*")
55     configured = expr.findall(output)
56     if len(configured) == 1:
57         info["configured"] = configured[0].split("Configured with: ")[1]
58     expr = re.compile("Thread model: .*")
59     thread = expr.findall(output)
60     if len(thread) == 1:
61         info["thread"] = thread[0].split("Thread model: ")[1]
62     return info
63
64 def findDefinitions(ftype, path):
65     L = os.walk(path)
66     for element in L:
67         for filename in element[2]:
68             if fnmatch.fnmatch(filename, ftype):
69                 yield (filename, element[0])
70
71 def loadCpuInfos(path):
72     cpuInfos = []
73     for definition in findDefinitions(const.CPU_DEFINITION, path):
74         D = {}
75         D.update(const.CPU_DEF)
76         def include(filename, dict = D, directory=definition[1]):
77             execfile(directory + "/" + filename, {}, D)
78         D["include"] = include
79         include(definition[0], D)
80         D["CPU_NAME"] = definition[0].split(".")[0]
81         cpuInfos.append(D)
82     return cpuInfos