From cf36efa296379eb024dd593fc2806a42093e6c97 Mon Sep 17 00:00:00 2001 From: duplo Date: Fri, 26 Mar 2010 15:22:37 +0000 Subject: [PATCH] Attempt to fix the BeRTOS Wizard running directory-related issue. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3274 38d2e660-2303-0410-9eaa-f027e97ec537 --- wizard/BWizardPage.py | 6 +++++- wizard/bertos.py | 17 +++++++---------- wizard/bertos_utils.py | 8 ++++---- wizard/const.py | 8 ++++++++ wizard/plugins/codelite.py | 4 ++-- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/wizard/BWizardPage.py b/wizard/BWizardPage.py index 980cb45c..be667562 100644 --- a/wizard/BWizardPage.py +++ b/wizard/BWizardPage.py @@ -33,12 +33,16 @@ # Author: Lorenzo Berni # +import os + from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4 import uic import qvariant_converter +import const + class BWizardPage(QWizardPage): """ Base class for all the wizard pages. It has the utility method used in all @@ -47,7 +51,7 @@ class BWizardPage(QWizardPage): def __init__(self, wizardGui, parent = None): QWizardPage.__init__(self, parent) - self.pageContent = uic.loadUi(wizardGui, None) + self.pageContent = uic.loadUi(os.path.join(const.DATA_DIR, wizardGui), None) layout = QVBoxLayout() layout.addWidget(self.pageContent) self.setLayout(layout) diff --git a/wizard/bertos.py b/wizard/bertos.py index 53fa1138..e4255177 100755 --- a/wizard/bertos.py +++ b/wizard/bertos.py @@ -61,6 +61,7 @@ from BFinalPage import BFinalPage from BEditingDialog import BEditingDialog, BVersionDialog, BToolchainDialog import bertos_utils +import const from LoadException import VersionException, ToolchainException @@ -119,21 +120,17 @@ def showStartPage(): QApplication.instance().dialog.show() def main(): - rundir = os.getcwd() - datadir = sys.argv[0] - if os.path.islink(datadir): - datadir = os.readlink(datadir) - datadir = os.path.dirname(os.path.abspath(datadir)) - os.chdir(datadir) app = QApplication(sys.argv) app.settings = QSettings("Develer", "Bertos Configurator") app.project = BProject.BProject() # Development utility lines, to be removed for production - if not (hasattr(sys, "frozen") and sys.frozen) and newer("bertos.qrc", "bertos.rcc"): - os.system("rcc -binary bertos.qrc -o bertos.rcc") - QResource.registerResource("bertos.rcc") + datadir = const.DATA_DIR + qrc, rcc = os.path.join(datadir, 'bertos.qrc'), os.path.join(datadir, 'bertos.rcc') + if not (hasattr(sys, "frozen") and sys.frozen) and newer(qrc, rcc): + os.system("rcc -binary %s -o %s" %(qrc, rcc)) + QResource.registerResource(rcc) if len(sys.argv) == 3 and sys.argv[1] == "--edit": - editProject(os.path.join(rundir, sys.argv[2])) + editProject(sys.argv[2]) else: newProject() diff --git a/wizard/bertos_utils.py b/wizard/bertos_utils.py index 004e67bf..5fbd6914 100644 --- a/wizard/bertos_utils.py +++ b/wizard/bertos_utils.py @@ -167,7 +167,7 @@ def createBertosProject(project_info, edit=False): mergeSources(srcdir, sources_dir, old_sources_dir) # Destination makefile makefile = directory + "/Makefile" - makefile = open("mktemplates/Makefile").read() + makefile = open(os.path.join(const.DATA_DIR, "mktemplates/Makefile"), 'r').read() makefile = makefileGenerator(project_info, makefile) open(directory + "/Makefile", "w").write(makefile) # Destination project dir @@ -219,16 +219,16 @@ def createBertosProject(project_info, edit=False): f.close() if not edit: # Destination user mk file (only on project creation) - makefile = open("mktemplates/template.mk", "r").read() + makefile = open(os.path.join(const.DATA_DIR, "mktemplates/template.mk"), "r").read() makefile = mkGenerator(project_info, makefile) open(prjdir + "/" + os.path.basename(prjdir) + ".mk", "w").write(makefile) # Destination wizard mk file - makefile = open("mktemplates/template_wiz.mk", "r").read() + makefile = open(os.path.join(const.DATA_DIR, "mktemplates/template_wiz.mk"), "r").read() makefile = mkGenerator(project_info, makefile) open(prjdir + "/" + os.path.basename(prjdir) + "_wiz.mk", "w").write(makefile) # Destination main.c file if not edit: - main = open("srctemplates/main.c", "r").read() + main = open(os.path.join(const.DATA_DIR, "srctemplates/main.c"), "r").read() open(prjdir + "/main.c", "w").write(main) # Files for selected plugins relevants_files = {} diff --git a/wizard/const.py b/wizard/const.py index 4f226328..697cd463 100644 --- a/wizard/const.py +++ b/wizard/const.py @@ -33,6 +33,14 @@ # Author: Lorenzo Berni # +import os, sys + +_tmp = sys.argv[0] +if os.path.islink(_tmp): + _tmp = os.readlink(_tmp) +DATA_DIR = os.path.dirname(os.path.abspath(_tmp)) +del _tmp + CPU_DEF = { "CPU_NAME": "", "CPU_DIR": "", diff --git a/wizard/plugins/codelite.py b/wizard/plugins/codelite.py index f6555a8b..7f4daac8 100644 --- a/wizard/plugins/codelite.py +++ b/wizard/plugins/codelite.py @@ -99,7 +99,7 @@ def codeliteProjectGenerator(project_info): """ Returns the string rapresenting the codelite project. """ - template = open("cltemplates/bertos.project", "r").read() + template = open(os.path.join(const.DATA_DIR, "cltemplates/bertos.project"), "r").read() filelist = "\n".join(clFiles(findSources(project_info.info("PROJECT_PATH")), "")) debugger_path = project_info.info("TOOLCHAIN")["path"].replace("gcc", "gdb") init_script = project_info.info("CPU_INFOS")["GDB_INIT_SCRIPT"] @@ -118,7 +118,7 @@ def codeliteWorkspaceGenerator(project_info): """ Returns the string rapresentig the codelite workspace. """ - template = open("cltemplates/bertos.workspace", "r").read() + template = open(os.path.join(const.DATA_DIR, "cltemplates/bertos.workspace"), "r").read() project_name = os.path.basename(project_info.info("PROJECT_PATH")) while template.find("$project") != -1: template = template.replace("$project", project_name) -- 2.25.1