Workaround to fix the bug related to the copy of the project from a machine to another.
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 15 Sep 2009 12:49:42 +0000 (12:49 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 15 Sep 2009 12:49:42 +0000 (12:49 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2943 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/BEditingDialog.py
wizard/BToolchainPage.py
wizard/LoadException.py [new file with mode: 0644]
wizard/bertos.py
wizard/bertos_utils.py

index 2f07643085a855fd30dfc42f2da1d85a14e087e5..7b7589e6756aaf734dae343274657d2d71afd400 100644 (file)
@@ -112,7 +112,7 @@ class BEditingDialog(QDialog):
         dialog = BToolchainDialog()
         if dialog.exec_():
             toolchain = qvariant_converter.getStringDict(dialog.toolchain_page.currentItem().data(Qt.UserRole))
-            toolchain_page.setProjectInfo("TOOLCHAIN", toolchain)
+            dialog.toolchain_page.setProjectInfo("TOOLCHAIN", toolchain)
     
     def changeBertosVersion(self):
         dialog = BVersionDialog()
@@ -183,10 +183,11 @@ class BToolchainDialog(QDialog):
        # TODO: to be moved in BToolchainPage
        for toolchain_row in range(toolchain_page.pageContent.toolchainList.count()):
             toolchain = qvariant_converter.getStringDict(toolchain_page.pageContent.toolchainList.item(toolchain_row).data(Qt.UserRole))
-           if toolchain["path"] == current_toolchain["path"]:
+           if current_toolchain and toolchain["path"] == current_toolchain["path"]:
                 toolchain_page.pageContent.toolchainList.setCurrentRow(toolchain_row)
                toolchain_page.selectionChanged()
                break
+       self.toolchain_page = toolchain_page
         layout.addWidget(toolchain_page)
         button_layout = QHBoxLayout()
         button_layout.addStretch()
@@ -207,6 +208,7 @@ class BVersionDialog(QDialog):
         layout = QVBoxLayout()
         version_page = BVersionPage()
         version_page.reloadData()
+       self.version_page = version_page
         layout.addWidget(version_page)
         button_layout = QHBoxLayout()
         button_layout.addStretch()
index 24105c196d50391811ff6570d6929417cd7c9476..6239a1d9dd0f1fa9503185b2428a272dde643452 100644 (file)
@@ -174,13 +174,18 @@ class BToolchainPage(BWizardPage):
                 toolchains[toolchain] = True
         sel_toolchain = self.projectInfo("TOOLCHAIN")
         for key, value in toolchains.items():
-            item = QListWidgetItem(key)
-            item.setData(Qt.UserRole, qvariant_converter.convertStringDict({"path": key}))
-            self.pageContent.toolchainList.addItem(item)
-            if sel_toolchain and sel_toolchain["path"] == key:
-                self.pageContent.toolchainList.setCurrentItem(item)
-            if value:
-                self.validateToolchain(self.pageContent.toolchainList.row(item))
+            if os.path.exists(key):
+                item = QListWidgetItem(key)
+                item.setData(Qt.UserRole, qvariant_converter.convertStringDict({"path": key}))
+                self.pageContent.toolchainList.addItem(item)
+                if sel_toolchain and sel_toolchain["path"] == key:
+                    self.pageContent.toolchainList.setCurrentItem(item)
+                if value:
+                    self.validateToolchain(self.pageContent.toolchainList.row(item))
+
+    def currentToolchain(self):
+        selected_toolchain = qvariant_converter.getStringDict(self.pageContent.toolchainList.currentItem().data(Qt.UserRole))
+        return selected_toolchain
 
     def _clearList(self):
         """
diff --git a/wizard/LoadException.py b/wizard/LoadException.py
new file mode 100644 (file)
index 0000000..99b30c9
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/env python\r
+# encoding: utf-8\r
+#\r
+# This file is part of BeRTOS.\r
+#\r
+# Bertos is free software; you can redistribute it and/or modify\r
+# it under the terms of the GNU General Public License as published by\r
+# the Free Software Foundation; either version 2 of the License, or\r
+# (at your option) any later version.\r
+#\r
+# This program is distributed in the hope that it will be useful,\r
+# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+# GNU General Public License for more details.\r
+#\r
+# You should have received a copy of the GNU General Public License\r
+# along with this program; if not, write to the Free Software\r
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
+#\r
+# As a special exception, you may use this file as part of a free software\r
+# library without restriction.  Specifically, if other files instantiate\r
+# templates or use macros or inline functions from this file, or you compile\r
+# this file and link it with other files to produce an executable, this\r
+# file does not by itself cause the resulting executable to be covered by\r
+# the GNU General Public License.  This exception does not however\r
+# invalidate any other reasons why the executable file might be covered by\r
+# the GNU General Public License.\r
+#\r
+# Copyright 2008 Develer S.r.l. (http://www.develer.com/)\r
+#\r
+# $Id: DefineException.py 2645 2009-04-23 09:28:13Z duplo $\r
+#\r
+# Author: Lorenzo Berni <duplo@develer.com>\r
+#\r
+\r
+class ToolchainException(Exception):\r
+    def __init__(self, partial_project):\r
+        self.partial_project = partial_project\r
+\r
+class VersionException(Exception):\r
+    def __init__(self, partial_project):\r
+        self.partial_project = partial_project\r
index 54f2885b59ec544666b7891fbdd8d54809909750..edb131d67663c3f27282f592222dbefe158febf5 100755 (executable)
@@ -57,10 +57,12 @@ from BOutputPage import BOutputPage
 from BCreationPage import BCreationPage
 from BFinalPage import BFinalPage
 
-from BEditingDialog import BEditingDialog
+from BEditingDialog import BEditingDialog, BVersionDialog, BToolchainDialog
 
 import bertos_utils
 
+from LoadException import VersionException, ToolchainException
+
 def newProject():
     page_list = [BFolderPage, BVersionPage, BCpuPage, BToolchainPage, BModulePage, BOutputPage, BCreationPage, BFinalPage]
     wizard = BWizard.BWizard(page_list)
@@ -78,7 +80,34 @@ def newProject():
     sys.exit()
     
 def editProject(project_file):
-    QApplication.instance().project = bertos_utils.loadBertosProject(project_file)
+    info_dict = {}
+    while(True):
+        try:
+            QApplication.instance().project = bertos_utils.loadBertosProject(project_file, info_dict)
+        except VersionException:
+            QMessageBox.critical(
+                None,
+                QObject().tr("BeRTOS version not found!"),
+                QObject().tr("The selected BeRTOS version is not found, please select an existing one...")
+            )
+            dialog = BVersionDialog()
+            if dialog.exec_():
+                version = dialog.version_page.currentVersion()
+                info_dict["SOURCES_PATH"] = version
+            continue
+        except ToolchainException, exc:
+            QMessageBox.critical(
+                None,
+                QObject().tr("Toolchain not found!"),
+                QObject().tr("The selected toolchain is not found, please select an existing one...")
+            )
+            QApplication.instance().project = exc.partial_project
+            dialog = BToolchainDialog()
+            if dialog.exec_():
+                toolchain = dialog.toolchain_page.currentToolchain()
+                info_dict["TOOLCHAIN"] = toolchain
+            continue
+        break
     dialog = BEditingDialog()
     dialog.exec_()
 
index e17a4ed586d6bebc090619913d6fb2cc3a659674..5402e01432447d751baf20347f7fc9183a152458 100644 (file)
@@ -47,20 +47,24 @@ import plugins
 import DefineException
 import BProject
 
+from LoadException import VersionException, ToolchainException
+
 def isBertosDir(directory):
    return os.path.exists(directory + "/VERSION")
 
 def bertosVersion(directory):
    return open(directory + "/VERSION").readline().strip()
 
-def loadBertosProject(project_file):
+def loadBertosProject(project_file, info_dict):
     project_data = pickle.loads(open(project_file, "r").read())
     project_info = BProject.BProject()
     project_info.setInfo("PROJECT_PATH", os.path.dirname(project_file))
-    project_info.setInfo("SOURCES_PATH", project_data["SOURCES_PATH"])
-    project_info.setInfo("TOOLCHAIN", project_data["TOOLCHAIN"])
-    project_info.setInfo("SELECTED_FREQ", project_data["SELECTED_FREQ"])
-    project_info.setInfo("OUTPUT", project_data["OUTPUT"])
+    if "SOURCES_PATH" in info_dict:
+        project_data["SOURCES_PATH"] = info_dict["SOURCES_PATH"]
+    if os.path.exists(project_data["SOURCES_PATH"]):
+        project_info.setInfo("SOURCES_PATH", project_data["SOURCES_PATH"])
+    else:
+        raise VersionException(project_info)
     loadSourceTree(project_info)
     cpu_name = project_data["CPU_NAME"]
     project_info.setInfo("CPU_NAME", cpu_name)
@@ -81,6 +85,14 @@ def loadBertosProject(project_file):
         else:
             tag_dict[tag] = False
     project_info.setInfo("ALL_CPU_TAGS", tag_dict)
+    if "TOOLCHAIN" in info_dict:
+        project_data["TOOLCHAIN"] = info_dict["TOOLCHAIN"]
+    if os.path.exists(project_data["TOOLCHAIN"]["path"]):
+        project_info.setInfo("TOOLCHAIN", project_data["TOOLCHAIN"])
+    else:
+        raise ToolchainException(project_info)
+    project_info.setInfo("SELECTED_FREQ", project_data["SELECTED_FREQ"])
+    project_info.setInfo("OUTPUT", project_data["OUTPUT"])
     loadModuleData(project_info, True)
     setEnabledModules(project_info, project_data["ENABLED_MODULES"])
     return project_info