More efficient way to track BeRTOS files.
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 30 Mar 2010 14:37:27 +0000 (14:37 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 30 Mar 2010 14:37:27 +0000 (14:37 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3332 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/BProject.py
wizard/bertos_utils.py

index 6ecd3bc2cd440a9fd546f169b501463d5ef8d7b6..eaff6d62612c6609cbbe2fe9a7de3f5cfb5d6bda 100644 (file)
@@ -63,22 +63,26 @@ class BProject(object):
     def loadSourceTree(self):
         # Index only the SOURCES_PATH/bertos content
         bertos_sources_dir = os.path.join(self.info("SOURCES_PATH"), 'bertos')
+        file_dict = {}
         if os.path.exists(bertos_sources_dir):
-            fileList = [f for f in os.walk(bertos_sources_dir)]
-        else:
-            fileList = []
-        self.setInfo("FILE_LIST", fileList)
+            for element in os.walk(bertos_sources_dir):
+                for f in element[2]:
+                    file_dict[f] = file_dict.get(f, []) + [element[0]]
+        self.setInfo("FILE_DICT", file_dict)
+
+    def searchFiles(self, filename):
+        file_dict = self.infos["FILE_DICT"]
+        return [(filename, dirname) for dirname in file_dict.get(filename, [])]
 
     def findDefinitions(self, ftype):
         definitions = self._cached_queries.get(ftype, None)
         if definitions is not None:
             return definitions
-        L = self.infos["FILE_LIST"]
+        file_dict = self.infos["FILE_DICT"]
         definitions = []
-        for element in L:
-            for filename in element[2]:
-                if fnmatch.fnmatch(filename, ftype):
-                    definitions.append((filename, element[0]))
+        for filename in file_dict:
+            if fnmatch.fnmatch(filename, ftype):
+                definitions += [(filename, dirname) for dirname in file_dict.get(filename, [])]
         self._cached_queries[ftype] = definitions
         return definitions
 
index 0fbb953245706b918c0e01529ee344aca9f11b9c..e291f56bd3b554f0d049f190605f27b0a05419fa 100644 (file)
@@ -381,28 +381,28 @@ def findModuleFiles(module, project_info):
     cfiles = []
     sfiles = []
     # .c files related to the module and the cpu architecture
-    for filename, path in project_info.findDefinitions(module + ".c") + \
-            project_info.findDefinitions(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".c"):
+    for filename, path in project_info.searchFiles(module + ".c") + \
+            project_info.searchFiles(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".c"):
         path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
         path = replaceSeparators(path)
         cfiles.append(path + "/" + filename)
     # .s files related to the module and the cpu architecture
-    for filename, path in project_info.findDefinitions(module + ".s") + \
-            project_info.findDefinitions(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".s") + \
-            project_info.findDefinitions(module + ".S") + \
-            project_info.findDefinitions(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".S"):
+    for filename, path in project_info.searchFiles(module + ".s") + \
+            project_info.searchFiles(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".s") + \
+            project_info.searchFiles(module + ".S") + \
+            project_info.searchFiles(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".S"):
         path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
         path = replaceSeparators(path)
         sfiles.append(path + "/" + filename)
     # .c and .s files related to the module and the cpu tags
     for tag in project_info.info("CPU_INFOS")["CPU_TAGS"]:
-        for filename, path in project_info.findDefinitions(module + "_" + tag + ".c"):
+        for filename, path in project_info.searchFiles(module + "_" + tag + ".c"):
             path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
             if os.sep != "/":
                 path = replaceSeparators(path)
             cfiles.append(path + "/" + filename)
-        for filename, path in project_info.findDefinitions(module + "_" + tag + ".s") + \
-                project_info.findDefinitions(module + "_" + tag + ".S"):
+        for filename, path in project_info.searchFiles(module + "_" + tag + ".s") + \
+                project_info.searchFiles(module + "_" + tag + ".S"):
             path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
             path = replaceSeparators(path)
             sfiles.append(path + "/" + filename)