Move loadSourceTree and findDefinitions function into BProject class (to avoid useles...
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 30 Mar 2010 13:52:10 +0000 (13:52 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 30 Mar 2010 13:52:10 +0000 (13:52 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3327 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/BCpuPage.py
wizard/BEditingDialog.py
wizard/BProject.py
wizard/bertos_utils.py
wizard/test/testCpuTagsImport.py
wizard/test/testModulePage.py

index ce854bb24abae60789953d331a976815b5d48d10..085b06e75093763130fc1d38c81f8209ddea2d0b 100644 (file)
@@ -108,7 +108,7 @@ class BCpuPage(BWizardPage):
         Overload of the BWizardPage reloadData method.
         """
         QApplication.instance().setOverrideCursor(Qt.WaitCursor)
-        bertos_utils.loadSourceTree(self.project())
+        self.project().loadSourceTree()
         self.populateCpuList()
         cpu_name = self.projectInfo("CPU_NAME")
         selected_freq = self.projectInfo("SELECTED_FREQ")
index 1c3ed0d184dadf7a3da32fe6a87f72517885af7b..9ea436f77fd2431635bd36fdfcdfdbf23c927c2c 100644 (file)
@@ -130,7 +130,7 @@ class BEditingDialog(QDialog):
                 dialog.version_page.setProjectInfo("OLD_SOURCES_PATH", current_version)
                 enabled_modules = bertos_utils.enabledModules(dialog.version_page.project())
                 old_configuration = dialog.version_page.projectInfo("CONFIGURATIONS")
-                bertos_utils.loadSourceTree(dialog.version_page.project())
+                dialog.version_page.project().loadSourceTree()
                 bertos_utils.loadModuleData(dialog.version_page.project())
                 new_configuration = dialog.version_page.projectInfo("CONFIGURATIONS")
                 merged_configuration = {}
@@ -150,7 +150,12 @@ class BEditingDialog(QDialog):
 
     def apply(self):
         qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
-        createBertosProject(self.module_page.project(), edit=True)
+        def foo():
+            print "qui"
+            createBertosProject(self.module_page.project(), edit=True)
+        import cProfile
+        print "quo"
+        cProfile.runctx("foo()", globals(), locals(), sort=1)
         qApp.restoreOverrideCursor()
         self.accept()
 
index d5fd34bc3fe9b5053f683ef6cfd5f7441e1d5bb4..6ecd3bc2cd440a9fd546f169b501463d5ef8d7b6 100644 (file)
@@ -33,6 +33,8 @@
 # Author: Lorenzo Berni <duplo@develer.com>
 #
 
+import os
+import fnmatch
 import copy
 
 class BProject(object):
@@ -42,6 +44,7 @@ class BProject(object):
     
     def __init__(self):
         self.infos = {}
+        self._cached_queries = {}
     
     def setInfo(self, key, value):
         """
@@ -56,6 +59,28 @@ class BProject(object):
         if key in self.infos:
             return copy.deepcopy(self.infos[key])
         return default
-    
+
+    def loadSourceTree(self):
+        # Index only the SOURCES_PATH/bertos content
+        bertos_sources_dir = os.path.join(self.info("SOURCES_PATH"), 'bertos')
+        if os.path.exists(bertos_sources_dir):
+            fileList = [f for f in os.walk(bertos_sources_dir)]
+        else:
+            fileList = []
+        self.setInfo("FILE_LIST", fileList)
+
+    def findDefinitions(self, ftype):
+        definitions = self._cached_queries.get(ftype, None)
+        if definitions is not None:
+            return definitions
+        L = self.infos["FILE_LIST"]
+        definitions = []
+        for element in L:
+            for filename in element[2]:
+                if fnmatch.fnmatch(filename, ftype):
+                    definitions.append((filename, element[0]))
+        self._cached_queries[ftype] = definitions
+        return definitions
+
     def __repr__(self):
         return repr(self.infos)
\ No newline at end of file
index 16d836480a8b8f3364b9203f32c38aa44b1b8045..0fbb953245706b918c0e01529ee344aca9f11b9c 100644 (file)
@@ -78,7 +78,7 @@ def loadBertosProject(project_file, info_dict):
     if not isBertosDir(project_dir):
         version_file = open(os.path.join(const.DATA_DIR, "vtemplates/VERSION"), "r").read()
         open(os.path.join(project_dir, "VERSION"), "w").write(version_file.replace("$version", "").strip())
-    loadSourceTree(project_info)
+    project_info.loadSourceTree()
     cpu_name = project_data["CPU_NAME"]
     project_info.setInfo("CPU_NAME", cpu_name)
     cpu_info = loadCpuInfos(project_info)
@@ -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 findDefinitions(module + ".c", project_info) + \
-            findDefinitions(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".c", project_info):
+    for filename, path in project_info.findDefinitions(module + ".c") + \
+            project_info.findDefinitions(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 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", project_info):
+    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"):
         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 findDefinitions(module + "_" + tag + ".c", project_info):
+        for filename, path in project_info.findDefinitions(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 findDefinitions(module + "_" + tag + ".s", project_info) + \
-                findDefinitions(module + "_" + tag + ".S", project_info):
+        for filename, path in project_info.findDefinitions(module + "_" + tag + ".s") + \
+                project_info.findDefinitions(module + "_" + tag + ".S"):
             path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
             path = replaceSeparators(path)
             sfiles.append(path + "/" + filename)
@@ -462,33 +462,9 @@ def getToolchainName(toolchain_info):
     name = "GCC " + toolchain_info["version"] + " - " + toolchain_info["target"].strip()
     return name
 
-def loadSourceTree(project):
-    # Index only the SOURCES_PATH/bertos content
-    bertos_sources_dir = os.path.join(project.info("SOURCES_PATH"), 'bertos')
-    if os.path.exists(bertos_sources_dir):
-        fileList = [f for f in os.walk(bertos_sources_dir)]
-    else:
-        fileList = []
-    project.setInfo("FILE_LIST", fileList)
-
-_cached_queries = {}
-
-def findDefinitions(ftype, project):
-    definitions = _cached_queries.get(ftype, None)
-    if definitions is not None:
-        return definitions
-    L = project.info("FILE_LIST")
-    definitions = []
-    for element in L:
-        for filename in element[2]:
-            if fnmatch.fnmatch(filename, ftype):
-                definitions.append((filename, element[0]))
-    _cached_queries[ftype] = definitions
-    return definitions
-
-def loadCpuInfos(project):
+def loadCpuInfos(project_info):
     cpuInfos = []
-    for definition in findDefinitions(const.CPU_DEFINITION, project):
+    for definition in project_info.findDefinitions(const.CPU_DEFINITION):
         cpuInfos.append(getInfos(definition))
     return cpuInfos
 
@@ -655,12 +631,12 @@ def getDefinitionBlocks(text):
         block.append(([comment], define, start))
     return block
 
-def loadModuleData(project, edit=False):
+def loadModuleData(project_info, edit=False):
     module_info_dict = {}
     list_info_dict = {}
     configuration_info_dict = {}
     file_dict = {}
-    for filename, path in findDefinitions("*.h", project) + findDefinitions("*.c", project) + findDefinitions("*.s", project) + findDefinitions("*.S", project):
+    for filename, path in project_info.findDefinitions("*.h") + project_info.findDefinitions("*.c") + project_info.findDefinitions("*.s") + project_info.findDefinitions("*.S"):
         comment_list = getCommentList(open(path + "/" + filename, "r").read())
         if len(comment_list) > 0:
             module_info = {}
@@ -677,13 +653,13 @@ def loadModuleData(project, edit=False):
                 if "configuration" in information and len(information["configuration"]):
                     configuration = module_dict[module]["configuration"]
                     try:
-                        configuration_info[configuration] = loadConfigurationInfos(project.info("SOURCES_PATH") + "/" + configuration)
+                        configuration_info[configuration] = loadConfigurationInfos(project_info.info("SOURCES_PATH") + "/" + configuration)
                     except ParseError, err:
-                        raise DefineException.ConfigurationDefineException(project.info("SOURCES_PATH") + "/" + configuration, err.line_number, err.line)
+                        raise DefineException.ConfigurationDefineException(project_info.info("SOURCES_PATH") + "/" + configuration, err.line_number, err.line)
                     if edit:
                         try:
-                            path = project.info("PROJECT_NAME")
-                            directory = project.info("PROJECT_PATH")
+                            path = project_info.info("PROJECT_NAME")
+                            directory = project_info.info("PROJECT_PATH")
                             user_configuration = loadConfigurationInfos(directory + "/" + configuration.replace("bertos", path))
                             configuration_info[configuration] = updateConfigurationValues(configuration_info[configuration], user_configuration)
                         except ParseError, err:
@@ -696,17 +672,17 @@ def loadModuleData(project, edit=False):
                     list_info_dict.update(list_dict)
                 except ParseError, err:
                     raise DefineException.EnumDefineException(path, err.line_number, err.line)
-    for filename, path in findDefinitions("*_" + project.info("CPU_INFOS")["TOOLCHAIN"] + ".h", project):
+    for filename, path in project_info.findDefinitions("*_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".h"):
         comment_list = getCommentList(open(path + "/" + filename, "r").read())
         list_info_dict.update(loadDefineLists(comment_list))
-    for tag in project.info("CPU_INFOS")["CPU_TAGS"]:
-        for filename, path in findDefinitions("*_" + tag + ".h", project):
+    for tag in project_info.info("CPU_INFOS")["CPU_TAGS"]:
+        for filename, path in project_info.findDefinitions("*_" + tag + ".h"):
             comment_list = getCommentList(open(path + "/" + filename, "r").read())
             list_info_dict.update(loadDefineLists(comment_list))
-    project.setInfo("MODULES", module_info_dict)
-    project.setInfo("LISTS", list_info_dict)
-    project.setInfo("CONFIGURATIONS", configuration_info_dict)
-    project.setInfo("FILES", file_dict)
+    project_info.setInfo("MODULES", module_info_dict)
+    project_info.setInfo("LISTS", list_info_dict)
+    project_info.setInfo("CONFIGURATIONS", configuration_info_dict)
+    project_info.setInfo("FILES", file_dict)
 
 def formatParamNameValue(text):
     """
index b5e77fc708b52a7b61b818d9faa52a65a219d40c..19a1e37614b4adf197d396fb9028ad6c16aff5ef 100644 (file)
@@ -39,13 +39,13 @@ import os
 
 sys.path.append("../")
 
-from BProject import BProject
+import BProject
 from bertos_utils import *
 
 def main():
-    p = BProject()
+    p = BProject.BProject()
     p.setInfo("SOURCES_PATH", "../../")
-    loadSourceTree(p)
+    p.loadSourceTree()
     info = loadCpuInfos(p)
     tags = getTagSet(info)
     print tags
index 49f2d0107d1a8fb9b10a7fb8442031519b1f6797..ce23fadeb36f620ef470e8ccdcde3a6939f32087 100644 (file)
@@ -54,7 +54,7 @@ def main():
     page = BModulePage.BModulePage()
     page.setProjectInfo("SOURCES_PATH", "../../")
     page.setProjectInfo("CPU_INFOS", {"TOOLCHAIN": "avr", "CPU_TAGS": []})
-    bertos_utils.loadSourceTree(page.project())
+    page.project().loadSourceTree()
     page.reloadData()
     page.show()
     app.exec_()