Project/Project.py

branch
Py2 comp.
changeset 2677
3d4277929fb3
parent 2541
1ffa9f2f1be5
parent 2632
94121e2f55b9
child 2791
a9577f248f04
equal deleted inserted replaced
2670:e60ea6cb8e11 2677:3d4277929fb3
18 import shutil 18 import shutil
19 import glob 19 import glob
20 import fnmatch 20 import fnmatch
21 import copy 21 import copy
22 import zipfile 22 import zipfile
23 import re
24 23
25 from PyQt4.QtCore import QFile, QFileInfo, pyqtSignal, QCryptographicHash, QIODevice, \ 24 from PyQt4.QtCore import QFile, QFileInfo, pyqtSignal, QCryptographicHash, QIODevice, \
26 QByteArray, QObject, Qt 25 QByteArray, QObject, Qt
27 from PyQt4.QtGui import QCursor, QLineEdit, QToolBar, QDialog, QInputDialog, \ 26 from PyQt4.QtGui import QCursor, QLineEdit, QToolBar, QDialog, QInputDialog, \
28 QApplication, QMenu, QAction 27 QApplication, QMenu, QAction
365 """ 364 """
366 self.loaded = False # flag for the loaded status 365 self.loaded = False # flag for the loaded status
367 self.__dirty = False # dirty flag 366 self.__dirty = False # dirty flag
368 self.pfile = "" # name of the project file 367 self.pfile = "" # name of the project file
369 self.ppath = "" # name of the project directory 368 self.ppath = "" # name of the project directory
370 self.ppathRe = None
371 self.translationsRoot = "" # the translations prefix 369 self.translationsRoot = "" # the translations prefix
372 self.name = "" 370 self.name = ""
373 self.opened = False 371 self.opened = False
374 self.subdirs = [""] # record the project dir as a relative path (i.e. empty path) 372 self.subdirs = [""] # record the project dir as a relative path (i.e. empty path)
375 self.otherssubdirs = [] 373 self.otherssubdirs = []
623 if removed: 621 if removed:
624 for file in removelist: 622 for file in removelist:
625 self.pdata[index].remove(file) 623 self.pdata[index].remove(file)
626 self.setDirty(True) 624 self.setDirty(True)
627 625
628 def __makePpathRe(self):
629 """
630 Private method to generate a regular expression for the project path.
631 """
632 ppathRe = (self.ppath + os.sep)\
633 .replace("\\", "@@")\
634 .replace("/", "@@")\
635 .replace("@@", r"[\\/]")
636 if ppathRe.endswith(r"[\\/]"):
637 ppathRe += "*"
638 if Utilities.isWindowsPlatform():
639 self.ppathRe = re.compile(ppathRe, re.IGNORECASE)
640 else:
641 self.ppathRe = re.compile(ppathRe)
642
643 def __readProject(self, fn): 626 def __readProject(self, fn):
644 """ 627 """
645 Private method to read in a project (.e4p) file. 628 Private method to read in a project (.e4p) file.
646 629
647 @param fn filename of the project file to be read (string) 630 @param fn filename of the project file to be read (string)
662 .format(fn)) 645 .format(fn))
663 return False 646 return False
664 647
665 self.pfile = os.path.abspath(fn) 648 self.pfile = os.path.abspath(fn)
666 self.ppath = os.path.abspath(os.path.dirname(fn)) 649 self.ppath = os.path.abspath(os.path.dirname(fn))
667 self.__makePpathRe()
668 650
669 # insert filename into list of recently opened projects 651 # insert filename into list of recently opened projects
670 self.__syncRecent() 652 self.__syncRecent()
671 653
672 if res: 654 if res:
757 res = False 739 res = False
758 740
759 if res: 741 if res:
760 self.pfile = os.path.abspath(fn) 742 self.pfile = os.path.abspath(fn)
761 self.ppath = os.path.abspath(os.path.dirname(fn)) 743 self.ppath = os.path.abspath(os.path.dirname(fn))
762 self.__makePpathRe()
763 self.name = os.path.splitext(os.path.basename(fn))[0] 744 self.name = os.path.splitext(os.path.basename(fn))[0]
764 self.setDirty(False) 745 self.setDirty(False)
765 746
766 # insert filename into list of recently opened projects 747 # insert filename into list of recently opened projects
767 self.__syncRecent() 748 self.__syncRecent()
823 fn = os.path.join(self.getProjectManagementDir(), 804 fn = os.path.join(self.getProjectManagementDir(),
824 '{0}.e4s'.format(fn)) 805 '{0}.e4s'.format(fn))
825 enable = os.path.exists(fn) 806 enable = os.path.exists(fn)
826 self.sessActGrp.findChild(QAction, "project_load_session").setEnabled(enable) 807 self.sessActGrp.findChild(QAction, "project_load_session").setEnabled(enable)
827 self.sessActGrp.findChild(QAction, "project_delete_session").setEnabled(enable) 808 self.sessActGrp.findChild(QAction, "project_delete_session").setEnabled(enable)
828
829 809
830 def __readSession(self, quiet=False, indicator=""): 810 def __readSession(self, quiet=False, indicator=""):
831 """ 811 """
832 Private method to read in the project session file (.e4s) 812 Private method to read in the project session file (.e4s)
833 813
1905 from .PropertiesDialog import PropertiesDialog 1885 from .PropertiesDialog import PropertiesDialog
1906 dlg = PropertiesDialog(self, True) 1886 dlg = PropertiesDialog(self, True)
1907 if dlg.exec_() == QDialog.Accepted: 1887 if dlg.exec_() == QDialog.Accepted:
1908 self.closeProject() 1888 self.closeProject()
1909 dlg.storeData() 1889 dlg.storeData()
1910 self.__makePpathRe()
1911 self.pdata["VCS"] = ['None'] 1890 self.pdata["VCS"] = ['None']
1912 self.opened = True 1891 self.opened = True
1913 if not self.pdata["FILETYPES"]: 1892 if not self.pdata["FILETYPES"]:
1914 self.initFileTypes() 1893 self.initFileTypes()
1915 self.setDirty(True) 1894 self.setDirty(True)
2133 self.newProject.emit() 2112 self.newProject.emit()
2134 2113
2135 else: 2114 else:
2136 self.newProjectHooks.emit() 2115 self.newProjectHooks.emit()
2137 self.newProject.emit() 2116 self.newProject.emit()
2138
2139 2117
2140 def newProjectAddFiles(self, mainscript): 2118 def newProjectAddFiles(self, mainscript):
2141 """ 2119 """
2142 Public method to add files to a new project. 2120 Public method to add files to a new project.
2143 2121
2872 """ 2850 """
2873 Public method to check, if a path starts with the project path. 2851 Public method to check, if a path starts with the project path.
2874 2852
2875 @param path path to be checked (string) 2853 @param path path to be checked (string)
2876 """ 2854 """
2877 if self.ppath and path == self.ppath: 2855 if self.ppath:
2878 return True 2856 if path == self.ppath:
2879 elif self.ppathRe: 2857 return True
2880 return self.ppathRe.match(path) is not None 2858 elif Utilities.normcasepath(Utilities.toNativeSeparators(path)).startswith(
2859 Utilities.normcasepath(Utilities.toNativeSeparators(self.ppath + "/"))):
2860 return True
2861 else:
2862 return False
2881 else: 2863 else:
2882 return False 2864 return False
2883 2865
2884 def getProjectFile(self): 2866 def getProjectFile(self):
2885 """ 2867 """
2933 """ 2915 """
2934 if self.startswithProjectPath(path): 2916 if self.startswithProjectPath(path):
2935 if self.ppath and path == self.ppath: 2917 if self.ppath and path == self.ppath:
2936 return "" 2918 return ""
2937 else: 2919 else:
2938 return self.ppathRe.sub("", path, 1) 2920 return path[len(self.ppath) + 1:]
2939 else: 2921 else:
2940 return path 2922 return path
2941 2923
2942 def getRelativeUniversalPath(self, path): 2924 def getRelativeUniversalPath(self, path):
2943 """ 2925 """

eric ide

mercurial