Fixed an issue in the Project class causing the generation of project relative paths to fail, if they contain regexp pattern characters.

Sun, 28 Apr 2013 10:20:32 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 28 Apr 2013 10:20:32 +0200
changeset 2625
038d8dc1d813
parent 2624
e04b5d53281e
child 2626
f327632d56d2

Fixed an issue in the Project class causing the generation of project relative paths to fail, if they contain regexp pattern characters.

Project/Project.py file | annotate | diff | comparison | revisions
--- a/Project/Project.py	Sat Apr 27 13:56:42 2013 +0200
+++ b/Project/Project.py	Sun Apr 28 10:20:32 2013 +0200
@@ -14,7 +14,6 @@
 import fnmatch
 import copy
 import zipfile
-import re
 
 from PyQt4.QtCore import QFile, QFileInfo, pyqtSignal, QCryptographicHash, QIODevice, \
     QByteArray, QObject, Qt
@@ -361,7 +360,6 @@
         self.__dirty = False      # dirty flag
         self.pfile = ""         # name of the project file
         self.ppath = ""         # name of the project directory
-        self.ppathRe = None
         self.translationsRoot = ""  # the translations prefix
         self.name = ""
         self.opened = False
@@ -619,21 +617,6 @@
                 self.pdata[index].remove(file)
             self.setDirty(True)
         
-    def __makePpathRe(self):
-        """
-        Private method to generate a regular expression for the project path.
-        """
-        ppathRe = (self.ppath + os.sep)\
-            .replace("\\", "@@")\
-            .replace("/", "@@")\
-            .replace("@@", r"[\\/]")
-        if ppathRe.endswith(r"[\\/]"):
-            ppathRe += "*"
-        if Utilities.isWindowsPlatform():
-            self.ppathRe = re.compile(ppathRe, re.IGNORECASE)
-        else:
-            self.ppathRe = re.compile(ppathRe)
-        
     def __readProject(self, fn):
         """
         Private method to read in a project (.e4p) file.
@@ -658,7 +641,6 @@
         
         self.pfile = os.path.abspath(fn)
         self.ppath = os.path.abspath(os.path.dirname(fn))
-        self.__makePpathRe()
         
         # insert filename into list of recently opened projects
         self.__syncRecent()
@@ -753,7 +735,6 @@
         if res:
             self.pfile = os.path.abspath(fn)
             self.ppath = os.path.abspath(os.path.dirname(fn))
-            self.__makePpathRe()
             self.name = os.path.splitext(os.path.basename(fn))[0]
             self.setDirty(False)
             
@@ -1901,7 +1882,6 @@
         if dlg.exec_() == QDialog.Accepted:
             self.closeProject()
             dlg.storeData()
-            self.__makePpathRe()
             self.pdata["VCS"] = ['None']
             self.opened = True
             if not self.pdata["FILETYPES"]:
@@ -2868,10 +2848,14 @@
         
         @param path path to be checked (string)
         """
-        if self.ppath and path == self.ppath:
-            return True
-        elif self.ppathRe:
-            return self.ppathRe.match(path) is not None
+        if self.ppath:
+            if path == self.ppath:
+                return True
+            elif Utilities.normcasepath(Utilities.toNativeSeparators(path)).startswith(
+                 Utilities.normcasepath(Utilities.toNativeSeparators(self.ppath))):
+                return True
+            else:
+                return False
         else:
             return False
         
@@ -2929,7 +2913,10 @@
             if self.ppath and path == self.ppath:
                 return ""
             else:
-                return self.ppathRe.sub("", path, 1)
+                p = path[len(self.ppath):]
+                if p.startswith(("\\","/")):
+                    p = p[1:]
+                return p
         else:
             return path
         

eric ide

mercurial