Created
May 3, 2012 08:56
-
-
Save gariels/2584467 to your computer and use it in GitHub Desktop.
New "projectpath" attribute on "Project" element in the project file used to inform the root path of the project.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HG changeset patch | |
# Parent e18f96b1714b2353c7988d7b274925fa12bb0343 | |
Addition of "projectpath" attribute. | |
New "projectpath" attribute on "Project" element in the project file used to | |
inform the root path of the project. Eric5 expects project file to be saved at | |
the root; this hack enables the project files to be saved anywhere inside the | |
project directory and yet retaining the project root path for the IDE. | |
diff --git a/E5XML/ProjectReader.py b/E5XML/ProjectReader.py | |
--- a/E5XML/ProjectReader.py | |
+++ b/E5XML/ProjectReader.py | |
@@ -45,6 +45,19 @@ | |
self.attribute("version", projectFileFormatVersion) | |
if self.version not in self.supportedVersions: | |
self.raiseUnsupportedFormatVersion(self.version) | |
+ | |
+ # Accept a new attribute called "projectpath" which could | |
+ # tell us the actual project path *RELATIVE* to this project | |
+ # file location. | |
+ ppath = self.attribute("projectpath", None) | |
+ if ppath is not None: | |
+ # I hope I'm not polluting :p | |
+ self.project.pdata["^^PROJECTPATH"] = ppath | |
+ # Now because the key "^^PROJECTPATH" will only exists | |
+ # if the "projectpath" attribute exists when reading the | |
+ # project, this means for now, to use this feature I | |
+ # have to manually add the "projectpath" attribute to | |
+ # the "Project" element in the xml file. | |
elif self.name() == "Language": | |
self.project.pdata["SPELLLANGUAGE"] = [self.readElementText()] | |
elif self.name() == "ProjectWordList": | |
diff --git a/E5XML/ProjectWriter.py b/E5XML/ProjectWriter.py | |
--- a/E5XML/ProjectWriter.py | |
+++ b/E5XML/ProjectWriter.py | |
@@ -7,8 +7,11 @@ | |
Module implementing the writer class for writing an XML project file. | |
""" | |
+import os | |
import time | |
+from PyQt4.QtCore import QFile | |
+ | |
from E5Gui.E5Application import e5App | |
from .XMLStreamWriterBase import XMLStreamWriterBase | |
@@ -32,6 +35,7 @@ | |
XMLStreamWriterBase.__init__(self, device) | |
self.pdata = e5App().getObject("Project").pdata | |
+ self.ppath = e5App().getObject("Project").ppath | |
self.name = projectName | |
def writeXML(self): | |
@@ -55,6 +59,22 @@ | |
# add the main tag | |
self.writeStartElement("Project") | |
self.writeAttribute("version", projectFileFormatVersion) | |
+ | |
+ # write "projectpath" attribute, only if we have to write it | |
+ if ("^^PROJECTPATH" in self.pdata) and os.path.isdir(self.ppath): | |
+ # Someday, the "^^PROJECTPATH" testing can be removed if my hack got | |
+ # accepted; as without its existence in pdata the "projectpath" | |
+ # should never be written. | |
+ devc = self.device() | |
+ if isinstance(devc, QFile): | |
+ ppath = os.path.relpath(self.ppath, | |
+ os.path.dirname(devc.fileName())) | |
+ if ppath != '.': | |
+ self.writeAttribute("projectpath", ppath) | |
+ # update the project data | |
+ self.pdata["^^PROJECTPATH"] = ppath | |
+ else: | |
+ del self.pdata["^^PROJECTPATH"] | |
# do the language (used for spell checking) | |
self.writeTextElement("Language", self.pdata["SPELLLANGUAGE"][0]) | |
diff --git a/Project/Project.py b/Project/Project.py | |
--- a/Project/Project.py | |
+++ b/Project/Project.py | |
@@ -613,6 +613,9 @@ | |
self.pfile = os.path.abspath(fn) | |
self.ppath = os.path.abspath(os.path.dirname(fn)) | |
+ if res: | |
+ self.__updateppath() | |
+ | |
self.__makePpathRe() | |
# insert filename into list of recently opened projects | |
@@ -700,6 +703,8 @@ | |
if res: | |
self.pfile = os.path.abspath(fn) | |
self.ppath = os.path.abspath(os.path.dirname(fn)) | |
+ self.__updateppath() | |
+ | |
self.__makePpathRe() | |
self.name = os.path.splitext(os.path.basename(fn))[0] | |
self.setDirty(False) | |
@@ -708,6 +713,22 @@ | |
self.__syncRecent() | |
return res | |
+ | |
+ def __updateppath(self): | |
+ """ | |
+ Private method to update ppath relative to project file location. | |
+ """ | |
+ | |
+ # This is to set project path to a certain location relative to the | |
+ # project file location. We got this from "^^PROJECTPATH" value | |
+ # from reading the project file. | |
+ if "^^PROJECTPATH" not in self.pdata: | |
+ return | |
+ | |
+ ppath = os.path.normpath(os.path.join(self.ppath, | |
+ self.pdata["^^PROJECTPATH"])) | |
+ if os.path.isdir(ppath): | |
+ self.ppath = os.path.abspath(ppath) | |
def __readUserProperties(self): | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment