Project/Project.py

changeset 2625
038d8dc1d813
parent 2540
f346433ea963
child 2629
95be6907871c
equal deleted inserted replaced
2624:e04b5d53281e 2625:038d8dc1d813
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)
656 .format(fn)) 639 .format(fn))
657 return False 640 return False
658 641
659 self.pfile = os.path.abspath(fn) 642 self.pfile = os.path.abspath(fn)
660 self.ppath = os.path.abspath(os.path.dirname(fn)) 643 self.ppath = os.path.abspath(os.path.dirname(fn))
661 self.__makePpathRe()
662 644
663 # insert filename into list of recently opened projects 645 # insert filename into list of recently opened projects
664 self.__syncRecent() 646 self.__syncRecent()
665 647
666 if res: 648 if res:
751 res = False 733 res = False
752 734
753 if res: 735 if res:
754 self.pfile = os.path.abspath(fn) 736 self.pfile = os.path.abspath(fn)
755 self.ppath = os.path.abspath(os.path.dirname(fn)) 737 self.ppath = os.path.abspath(os.path.dirname(fn))
756 self.__makePpathRe()
757 self.name = os.path.splitext(os.path.basename(fn))[0] 738 self.name = os.path.splitext(os.path.basename(fn))[0]
758 self.setDirty(False) 739 self.setDirty(False)
759 740
760 # insert filename into list of recently opened projects 741 # insert filename into list of recently opened projects
761 self.__syncRecent() 742 self.__syncRecent()
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 """

eric ide

mercurial