Parse the filename for find the cpu name
[bertos.git] / wizard / bertos_utils.py
index de56cfe6c2c3d3e65105e093c6691d57be841f36..0f0dc709bcd5e4041509fedd0a7d8a258479769b 100644 (file)
@@ -10,6 +10,7 @@
 #
 
 import os
+import fnmatch
 
 def isBertosDir(directory):
    return os.path.exists(directory + "/VERSION")
@@ -21,4 +22,22 @@ def createBertosProject(directory):
     if not os.path.isdir(directory):
         os.mkdir(directory)
     open(directory + "/project.bertos", "w")
-    
\ No newline at end of file
+
+def findDefinitions(ftype, path):
+    L = os.walk(path)
+    for element in L:
+        for filename in element[2]:
+            if fnmatch.fnmatch(filename, "*." + ftype):
+                yield (filename, element[0])
+
+def loadCpuInfos(path):
+    cpuInfos = []
+    for definition in findDefinitions("cdef", path):
+        D = {}
+        def include(filename, dict = D, directory=definition[1]):
+            execfile(directory + "/" + filename, {}, D)
+        D["include"] = include
+        include(definition[0], D)
+        D["CPU_NAME"] = definition[0].split(".")[0]
+        cpuInfos.append(D)
+    return cpuInfos