12 import shutil |
12 import shutil |
13 import glob |
13 import glob |
14 import fnmatch |
14 import fnmatch |
15 import copy |
15 import copy |
16 import zipfile |
16 import zipfile |
17 import re |
|
18 |
17 |
19 from PyQt4.QtCore import QFile, QFileInfo, pyqtSignal, QCryptographicHash, QIODevice, \ |
18 from PyQt4.QtCore import QFile, QFileInfo, pyqtSignal, QCryptographicHash, QIODevice, \ |
20 QByteArray, QObject, Qt |
19 QByteArray, QObject, Qt |
21 from PyQt4.QtGui import QCursor, QLineEdit, QToolBar, QDialog, QInputDialog, \ |
20 from PyQt4.QtGui import QCursor, QLineEdit, QToolBar, QDialog, QInputDialog, \ |
22 QApplication, QMenu, QAction |
21 QApplication, QMenu, QAction |
359 """ |
358 """ |
360 self.loaded = False # flag for the loaded status |
359 self.loaded = False # flag for the loaded status |
361 self.__dirty = False # dirty flag |
360 self.__dirty = False # dirty flag |
362 self.pfile = "" # name of the project file |
361 self.pfile = "" # name of the project file |
363 self.ppath = "" # name of the project directory |
362 self.ppath = "" # name of the project directory |
364 self.ppathRe = None |
|
365 self.translationsRoot = "" # the translations prefix |
363 self.translationsRoot = "" # the translations prefix |
366 self.name = "" |
364 self.name = "" |
367 self.opened = False |
365 self.opened = False |
368 self.subdirs = [""] # record the project dir as a relative path (i.e. empty path) |
366 self.subdirs = [""] # record the project dir as a relative path (i.e. empty path) |
369 self.otherssubdirs = [] |
367 self.otherssubdirs = [] |
617 if removed: |
615 if removed: |
618 for file in removelist: |
616 for file in removelist: |
619 self.pdata[index].remove(file) |
617 self.pdata[index].remove(file) |
620 self.setDirty(True) |
618 self.setDirty(True) |
621 |
619 |
622 def __makePpathRe(self): |
|
623 """ |
|
624 Private method to generate a regular expression for the project path. |
|
625 """ |
|
626 ppathRe = (self.ppath + os.sep)\ |
|
627 .replace("\\", "@@")\ |
|
628 .replace("/", "@@")\ |
|
629 .replace("@@", r"[\\/]") |
|
630 if ppathRe.endswith(r"[\\/]"): |
|
631 ppathRe += "*" |
|
632 if Utilities.isWindowsPlatform(): |
|
633 self.ppathRe = re.compile(ppathRe, re.IGNORECASE) |
|
634 else: |
|
635 self.ppathRe = re.compile(ppathRe) |
|
636 |
|
637 def __readProject(self, fn): |
620 def __readProject(self, fn): |
638 """ |
621 """ |
639 Private method to read in a project (.e4p) file. |
622 Private method to read in a project (.e4p) file. |
640 |
623 |
641 @param fn filename of the project file to be read (string) |
624 @param fn filename of the project file to be read (string) |
1899 from .PropertiesDialog import PropertiesDialog |
1880 from .PropertiesDialog import PropertiesDialog |
1900 dlg = PropertiesDialog(self, True) |
1881 dlg = PropertiesDialog(self, True) |
1901 if dlg.exec_() == QDialog.Accepted: |
1882 if dlg.exec_() == QDialog.Accepted: |
1902 self.closeProject() |
1883 self.closeProject() |
1903 dlg.storeData() |
1884 dlg.storeData() |
1904 self.__makePpathRe() |
|
1905 self.pdata["VCS"] = ['None'] |
1885 self.pdata["VCS"] = ['None'] |
1906 self.opened = True |
1886 self.opened = True |
1907 if not self.pdata["FILETYPES"]: |
1887 if not self.pdata["FILETYPES"]: |
1908 self.initFileTypes() |
1888 self.initFileTypes() |
1909 self.setDirty(True) |
1889 self.setDirty(True) |
2866 """ |
2846 """ |
2867 Public method to check, if a path starts with the project path. |
2847 Public method to check, if a path starts with the project path. |
2868 |
2848 |
2869 @param path path to be checked (string) |
2849 @param path path to be checked (string) |
2870 """ |
2850 """ |
2871 if self.ppath and path == self.ppath: |
2851 if self.ppath: |
2872 return True |
2852 if path == self.ppath: |
2873 elif self.ppathRe: |
2853 return True |
2874 return self.ppathRe.match(path) is not None |
2854 elif Utilities.normcasepath(Utilities.toNativeSeparators(path)).startswith( |
|
2855 Utilities.normcasepath(Utilities.toNativeSeparators(self.ppath))): |
|
2856 return True |
|
2857 else: |
|
2858 return False |
2875 else: |
2859 else: |
2876 return False |
2860 return False |
2877 |
2861 |
2878 def getProjectFile(self): |
2862 def getProjectFile(self): |
2879 """ |
2863 """ |
2927 """ |
2911 """ |
2928 if self.startswithProjectPath(path): |
2912 if self.startswithProjectPath(path): |
2929 if self.ppath and path == self.ppath: |
2913 if self.ppath and path == self.ppath: |
2930 return "" |
2914 return "" |
2931 else: |
2915 else: |
2932 return self.ppathRe.sub("", path, 1) |
2916 p = path[len(self.ppath):] |
|
2917 if p.startswith(("\\","/")): |
|
2918 p = p[1:] |
|
2919 return p |
2933 else: |
2920 else: |
2934 return path |
2921 return path |
2935 |
2922 |
2936 def getRelativeUniversalPath(self, path): |
2923 def getRelativeUniversalPath(self, path): |
2937 """ |
2924 """ |