From bcc49085f310cc8f30075b0f8577767f1668c860 Mon Sep 17 00:00:00 2001 From: duplo Date: Tue, 30 Mar 2010 10:28:42 +0000 Subject: [PATCH] Fix the #133 (projects created with older versions of the Wizard should be edited to let the modification works, otherwise the wizard couldn't open the project). git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3322 38d2e660-2303-0410-9eaa-f027e97ec537 --- wizard/BFolderPage.py | 1 + wizard/BProject.py | 4 ++-- wizard/bertos_utils.py | 15 ++++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/wizard/BFolderPage.py b/wizard/BFolderPage.py index 0014a886..3b34f14a 100644 --- a/wizard/BFolderPage.py +++ b/wizard/BFolderPage.py @@ -61,6 +61,7 @@ class BFolderPage(BWizardPage): self.setDefaultFolder(self._destination_folder) if self.pageContent.projectPath.text() != "None": self.setProjectInfo("PROJECT_PATH", unicode(self.pageContent.projectPath.text())) + self.setProjectInfo("PROJECT_NAME", os.path.basename(unicode(self.pageContent.projectPath.text()))) return True else: return False diff --git a/wizard/BProject.py b/wizard/BProject.py index 3fc56d7d..d5fd34bc 100644 --- a/wizard/BProject.py +++ b/wizard/BProject.py @@ -49,13 +49,13 @@ class BProject(object): """ self.infos[key] = value - def info(self, key): + def info(self, key, default=None): """ Retrieve the value associated with the name key. """ if key in self.infos: return copy.deepcopy(self.infos[key]) - return None + return default def __repr__(self): return repr(self.infos) \ No newline at end of file diff --git a/wizard/bertos_utils.py b/wizard/bertos_utils.py index 8a26aa1b..16d83648 100644 --- a/wizard/bertos_utils.py +++ b/wizard/bertos_utils.py @@ -61,18 +61,21 @@ def loadBertosProject(project_file, info_dict): project_dir = os.path.dirname(project_file) project_data = pickle.loads(open(project_file, "r").read()) project_info = BProject.BProject() + # If PROJECT_NAME is not defined it use the directory name as PROJECT_NAME + # NOTE: this can throw an Exception if the user has changed the directory containing the project + project_info.setInfo("PROJECT_NAME", project_data.get("PROJECT_NAME", os.path.basename(project_dir))) project_info.setInfo("PROJECT_PATH", os.path.dirname(project_file)) # Check for the Wizard version wizard_version = project_data.get("WIZARD_VERSION", 0) - if not wizard_version: - project_data["SOURCES_PATH"] = project_dir + # Ignore the SOURCES_PATH inside the project file + project_data["SOURCES_PATH"] = project_dir 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) - if not isBertosDir(os.path.dirname(project_file)): + 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) @@ -146,6 +149,7 @@ def projectFileGenerator(project_info): # Use the local BeRTOS version instead of the original one # project_data["SOURCES_PATH"] = project_info.info("SOURCES_PATH") project_data["SOURCES_PATH"] = directory + project_data["PROJECT_NAME"] = project_info.info("PROJECT_NAME", os.path.basename(directory)) project_data["TOOLCHAIN"] = project_info.info("TOOLCHAIN") project_data["CPU_NAME"] = project_info.info("CPU_NAME") project_data["SELECTED_FREQ"] = project_info.info("SELECTED_FREQ") @@ -185,7 +189,8 @@ def createBertosProject(project_info, edit=False): makefile = makefileGenerator(project_info, makefile) open(directory + "/Makefile", "w").write(makefile) # Destination project dir - prjdir = directory + "/" + os.path.basename(directory) + # prjdir = directory + "/" + os.path.basename(directory) + prjdir = os.path.join(directory, project_info.info("PROJECT_NAME")) if not edit: shutil.rmtree(prjdir, True) os.mkdir(prjdir) @@ -677,7 +682,7 @@ def loadModuleData(project, edit=False): raise DefineException.ConfigurationDefineException(project.info("SOURCES_PATH") + "/" + configuration, err.line_number, err.line) if edit: try: - path = os.path.basename(project.info("PROJECT_PATH")) + path = project.info("PROJECT_NAME") directory = project.info("PROJECT_PATH") user_configuration = loadConfigurationInfos(directory + "/" + configuration.replace("bertos", path)) configuration_info[configuration] = updateConfigurationValues(configuration_info[configuration], user_configuration) -- 2.25.1