From: duplo Date: Tue, 15 Sep 2009 12:49:42 +0000 (+0000) Subject: Workaround to fix the bug related to the copy of the project from a machine to another. X-Git-Tag: 2.2.0~25 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=efa322fd22f708abb3cb46c750908b065ba6290e;p=bertos.git Workaround to fix the bug related to the copy of the project from a machine to another. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2943 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/wizard/BEditingDialog.py b/wizard/BEditingDialog.py index 2f076430..7b7589e6 100644 --- a/wizard/BEditingDialog.py +++ b/wizard/BEditingDialog.py @@ -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() diff --git a/wizard/BToolchainPage.py b/wizard/BToolchainPage.py index 24105c19..6239a1d9 100644 --- a/wizard/BToolchainPage.py +++ b/wizard/BToolchainPage.py @@ -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 index 00000000..99b30c9f --- /dev/null +++ b/wizard/LoadException.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +# encoding: utf-8 +# +# This file is part of BeRTOS. +# +# Bertos is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +# As a special exception, you may use this file as part of a free software +# library without restriction. Specifically, if other files instantiate +# templates or use macros or inline functions from this file, or you compile +# this file and link it with other files to produce an executable, this +# file does not by itself cause the resulting executable to be covered by +# the GNU General Public License. This exception does not however +# invalidate any other reasons why the executable file might be covered by +# the GNU General Public License. +# +# Copyright 2008 Develer S.r.l. (http://www.develer.com/) +# +# $Id: DefineException.py 2645 2009-04-23 09:28:13Z duplo $ +# +# Author: Lorenzo Berni +# + +class ToolchainException(Exception): + def __init__(self, partial_project): + self.partial_project = partial_project + +class VersionException(Exception): + def __init__(self, partial_project): + self.partial_project = partial_project diff --git a/wizard/bertos.py b/wizard/bertos.py index 54f2885b..edb131d6 100755 --- a/wizard/bertos.py +++ b/wizard/bertos.py @@ -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_() diff --git a/wizard/bertos_utils.py b/wizard/bertos_utils.py index e17a4ed5..5402e014 100644 --- a/wizard/bertos_utils.py +++ b/wizard/bertos_utils.py @@ -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