Changed multi project files to contain relative paths to the contained project files.

Sat, 27 Sep 2014 15:59:38 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Sep 2014 15:59:38 +0200
changeset 3833
64b5f5fa3b00
parent 3830
70831a7beb3f
child 3834
e465278aa177

Changed multi project files to contain relative paths to the contained project files.

E5XML/MultiProjectReader.py file | annotate | diff | comparison | revisions
E5XML/MultiProjectWriter.py file | annotate | diff | comparison | revisions
Utilities/__init__.py file | annotate | diff | comparison | revisions
--- a/E5XML/MultiProjectReader.py	Sat Sep 27 14:30:40 2014 +0200
+++ b/E5XML/MultiProjectReader.py	Sat Sep 27 15:59:38 2014 +0200
@@ -9,6 +9,8 @@
 
 from __future__ import unicode_literals
 
+import os
+
 from .Config import multiProjectFileFormatVersion
 from .XMLStreamReaderBase import XMLStreamReaderBase
 
@@ -32,6 +34,7 @@
         XMLStreamReaderBase.__init__(self, device)
         
         self.multiProject = multiProject
+        self.path = os.path.dirname(device.fileName())
         
         self.version = ""
     
@@ -100,8 +103,8 @@
                 if self.name() == "ProjectName":
                     project["name"] = self.readElementText()
                 elif self.name() == "ProjectFile":
-                    project["file"] = Utilities.toNativeSeparators(
-                        self.readElementText())
+                    project["file"] = Utilities.absoluteUniversalPath(
+                        self.readElementText(), self.path)
                 elif self.name() == "ProjectDescription":
                     project["description"] = self.readElementText()
                 elif self.name() == "ProjectCategory":
--- a/E5XML/MultiProjectWriter.py	Sat Sep 27 14:30:40 2014 +0200
+++ b/E5XML/MultiProjectWriter.py	Sat Sep 27 15:59:38 2014 +0200
@@ -9,6 +9,7 @@
 
 from __future__ import unicode_literals
 
+import os
 import time
 
 from .XMLStreamWriterBase import XMLStreamWriterBase
@@ -34,6 +35,7 @@
         
         self.name = multiProjectName
         self.multiProject = multiProject
+        self.path = os.path.dirname(device.fileName())
     
     def writeXML(self):
         """
@@ -69,7 +71,7 @@
             self.writeTextElement("ProjectName", project['name'])
             self.writeTextElement(
                 "ProjectFile",
-                Utilities.fromNativeSeparators(project['file']))
+                Utilities.relativeUniversalPath(project['file'], self.path))
             self.writeTextElement("ProjectDescription", project['description'])
             self.writeTextElement("ProjectCategory", project['category'])
             self.writeEndElement()
--- a/Utilities/__init__.py	Sat Sep 27 14:30:40 2014 +0200
+++ b/Utilities/__init__.py	Sat Sep 27 15:59:38 2014 +0200
@@ -798,7 +798,87 @@
             return True
     
     return False
+
+
+def startswithPath(path, start):
+    """
+    Function to check, if a path starts with a given start path.
     
+    @param path path to be checked (string)
+    @param start start path (string)
+    @return flag indicating that the path starts with the given start
+        path (boolean)
+    """
+    if start:
+        if path == start:
+            return True
+        elif normcasepath(toNativeSeparators(path)).startswith(
+                normcasepath(toNativeSeparators(start + "/"))):
+            return True
+        else:
+            return False
+    else:
+        return False
+
+
+def relativePath(path, start):
+    """
+    Function to convert a file path to a path relative to a start path.
+    
+    @param path file or directory name to convert (string)
+    @param start start path (string)
+    @return relative path or unchanged path, if path does not start with
+        the start path (string)
+    """
+    if startswithPath(path, start):
+        if path == start:
+            return ""
+        else:
+            return path[len(start) + 1:]
+    else:
+        return path
+
+
+def relativeUniversalPath(path, start):
+    """
+    Function to convert a file path to a path relative to a start path
+    with universal separators.
+    
+    @param path file or directory name to convert (string)
+    @param start start path (string)
+    @return relative path or unchanged path, if path does not start with
+        the start path with universal separators (string)
+    """
+    return fromNativeSeparators(relativePath(path, start))
+
+
+def absolutePath(path, start):
+    """
+    Public method to convert a path relative to a start path to an
+    absolute path.
+    
+    @param path file or directory name to convert (string)
+    @param start start path (string)
+    @return absolute path (string)
+    """
+    if not os.path.isabs(path):
+        path = os.path.join(start, path)
+    return path
+
+
+def absoluteUniversalPath(path, start):
+    """
+    Public method to convert a path relative to a start path with
+    universal separators to an absolute path.
+    
+    @param path file or directory name to convert (string)
+    @param start start path (string)
+    @return absolute path with native separators (string)
+    """
+    if not os.path.isabs(path):
+        path = toNativeSeparators(os.path.join(start, path))
+    return path
+
 
 def getExecutablePath(file):
     """

eric ide

mercurial