Attempt to fix the BeRTOS Wizard running directory-related issue.
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 26 Mar 2010 15:22:37 +0000 (15:22 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 26 Mar 2010 15:22:37 +0000 (15:22 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3274 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/BWizardPage.py
wizard/bertos.py
wizard/bertos_utils.py
wizard/const.py
wizard/plugins/codelite.py

index 980cb45cf788784321f848660d25086230d56753..be66756206897d489e8c33cb82187f4340e7e65b 100644 (file)
 # Author: Lorenzo Berni <duplo@develer.com>
 #
 
+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)
index 53fa11383f47ad2131c543c31939f7c37c7b0395..e4255177a62557bcab7a05d8b93225df8e0479c8 100755 (executable)
@@ -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()
 
index 004e67bf5512b53e1d55eaae7f32f250aa058c05..5fbd69145ca71e8e0fb721da7ba73a5df3ff77c3 100644 (file)
@@ -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 = {}
index 4f226328f9cc719167626617a0d7eef6612e5f34..697cd4637c0db2cb44b3d500e5f14203ca5d69c9 100644 (file)
 # Author: Lorenzo Berni <duplo@develer.com>
 #
 
+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": "",
index f6555a8be406c8e823c2c6c514d4dfa7232287a0..7f4daac885cb8d067ece5c27c01bbf879663ebf2 100644 (file)
@@ -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)