eric6/Project/Project.py

branch
jsonfiles
changeset 8009
29818ac4853c
parent 8006
c4110b8b5931
child 8010
7ce2b8bb0d9b
equal deleted inserted replaced
8006:c4110b8b5931 8009:29818ac4853c
42 import Utilities 42 import Utilities
43 43
44 from .ProjectFile import ProjectFile 44 from .ProjectFile import ProjectFile
45 from .UserProjectFile import UserProjectFile 45 from .UserProjectFile import UserProjectFile
46 from .DebuggerPropertiesFile import DebuggerPropertiesFile 46 from .DebuggerPropertiesFile import DebuggerPropertiesFile
47
48 from Sessions.SessionFile import SessionFile
47 49
48 50
49 class Project(QObject): 51 class Project(QObject):
50 """ 52 """
51 Class implementing the project management functionality. 53 Class implementing the project management functionality.
189 self.__initData() 191 self.__initData()
190 192
191 self.__projectFile = ProjectFile(self) 193 self.__projectFile = ProjectFile(self)
192 self.__userProjectFile = UserProjectFile(self) 194 self.__userProjectFile = UserProjectFile(self)
193 self.__debuggerPropertiesFile = DebuggerPropertiesFile(self) 195 self.__debuggerPropertiesFile = DebuggerPropertiesFile(self)
196 self.__sessionFile = SessionFile(False)
194 197
195 self.recent = [] 198 self.recent = []
196 self.__loadRecent() 199 self.__loadRecent()
197 200
198 if filename is not None: 201 if filename is not None:
445 self.dbgExcList = [] 448 self.dbgExcList = []
446 self.dbgExcIgnoreList = [] 449 self.dbgExcIgnoreList = []
447 self.dbgAutoClearShell = True 450 self.dbgAutoClearShell = True
448 self.dbgTracePython = False 451 self.dbgTracePython = False
449 self.dbgAutoContinue = True 452 self.dbgAutoContinue = True
453 self.dbgEnableMultiprocess = True
454 self.dbgMultiprocessNoDebug = ""
450 455
451 self.pdata = { 456 self.pdata = {
452 "DESCRIPTION": "", 457 "DESCRIPTION": "",
453 "VERSION": "", 458 "VERSION": "",
454 "SOURCES": [], 459 "SOURCES": [],
948 .e4q). 953 .e4q).
949 """ 954 """
950 if self.pfile is None: 955 if self.pfile is None:
951 return 956 return
952 957
953 fn, ext = os.path.splitext(os.path.basename(self.pfile)) 958 fn1, ext = os.path.splitext(os.path.basename(self.pfile))
954 fn = os.path.join(self.getProjectManagementDir(), '{0}.eqj'.format(fn)) 959 fn = os.path.join(self.getProjectManagementDir(), '{0}.eqj'.format(fn1))
955 if os.path.exists(fn): 960 if os.path.exists(fn):
956 # try the new JSON based format first 961 # try the new JSON based format first
957 self.__userProjectFile.readFile(fn) 962 self.__userProjectFile.readFile(fn)
958 else: 963 else:
959 # try the old XML based format second 964 # try the old XML based format second
960 fn = os.path.join(self.getProjectManagementDir(), 965 fn = os.path.join(self.getProjectManagementDir(),
961 '{0}.e4q'.format(fn)) 966 '{0}.e4q'.format(fn1))
962 if os.path.exists(fn): 967 if os.path.exists(fn):
963 f = QFile(fn) 968 f = QFile(fn)
964 if f.open(QIODevice.ReadOnly): 969 if f.open(QIODevice.ReadOnly):
965 from E5XML.UserProjectReader import UserProjectReader 970 from E5XML.UserProjectReader import UserProjectReader
966 reader = UserProjectReader(f, self) 971 reader = UserProjectReader(f, self)
995 if self.pfile is None: 1000 if self.pfile is None:
996 enable = False 1001 enable = False
997 else: 1002 else:
998 fn, ext = os.path.splitext(os.path.basename(self.pfile)) 1003 fn, ext = os.path.splitext(os.path.basename(self.pfile))
999 fn_new = os.path.join(self.getProjectManagementDir(), 1004 fn_new = os.path.join(self.getProjectManagementDir(),
1005 '{0}.esj'.format(fn))
1006 fn_old = os.path.join(self.getProjectManagementDir(),
1000 '{0}.e5s'.format(fn)) 1007 '{0}.e5s'.format(fn))
1001 fn_old = os.path.join(self.getProjectManagementDir(),
1002 '{0}.e4s'.format(fn))
1003 enable = os.path.exists(fn_new) or os.path.exists(fn_old) 1008 enable = os.path.exists(fn_new) or os.path.exists(fn_old)
1004 self.sessActGrp.findChild( 1009 self.sessActGrp.findChild(
1005 QAction, "project_load_session").setEnabled(enable) 1010 QAction, "project_load_session").setEnabled(enable)
1006 self.sessActGrp.findChild( 1011 self.sessActGrp.findChild(
1007 QAction, "project_delete_session").setEnabled(enable) 1012 QAction, "project_delete_session").setEnabled(enable)
1008 1013
1009 @pyqtSlot() 1014 @pyqtSlot()
1010 def __readSession(self, quiet=False, indicator=""): 1015 def __readSession(self, quiet=False, indicator=""):
1011 """ 1016 """
1012 Private method to read in the project session file (.e5s or .e4s). 1017 Private method to read in the project session file (.esj or .e5s).
1013 1018
1014 @param quiet flag indicating quiet operations. 1019 @param quiet flag indicating quiet operations.
1015 If this flag is true, no errors are reported. 1020 If this flag is true, no errors are reported.
1016 @param indicator indicator string (string) 1021 @param indicator indicator string (string)
1017 """ 1022 """
1018 # TODO: read project session
1019 if self.pfile is None: 1023 if self.pfile is None:
1020 if not quiet: 1024 if not quiet:
1021 E5MessageBox.critical( 1025 E5MessageBox.critical(
1022 self.ui, 1026 self.ui,
1023 self.tr("Read project session"), 1027 self.tr("Read Project Session"),
1024 self.tr("Please save the project first.")) 1028 self.tr("Please save the project first."))
1025 return 1029 return
1026 1030
1027 fn1, ext = os.path.splitext(os.path.basename(self.pfile)) 1031 fn1, ext = os.path.splitext(os.path.basename(self.pfile))
1028 fn = os.path.join(self.getProjectManagementDir(), 1032 fn = os.path.join(self.getProjectManagementDir(),
1029 '{0}{1}.e5s'.format(fn1, indicator)) 1033 '{0}{1}.esj'.format(fn1, indicator))
1030 if not os.path.exists(fn): 1034 if os.path.exists(fn):
1035 # try the new JSON based format first
1036 self.__sessionFile.readFile(fn)
1037 else:
1038 # try the old XML based format second
1031 fn = os.path.join(self.getProjectManagementDir(), 1039 fn = os.path.join(self.getProjectManagementDir(),
1032 '{0}{1}.e4s'.format(fn1, indicator)) 1040 '{0}{1}.e5s'.format(fn1, indicator))
1033 1041 if os.path.exists(fn):
1034 f = QFile(fn) 1042 f = QFile(fn)
1035 if f.open(QIODevice.ReadOnly): 1043 if f.open(QIODevice.ReadOnly):
1036 from E5XML.SessionReader import SessionReader 1044 from E5XML.SessionReader import SessionReader
1037 reader = SessionReader(f, False) 1045 reader = SessionReader(f, False)
1038 reader.readXML(quiet=quiet) 1046 reader.readXML(quiet=quiet)
1039 f.close() 1047 f.close()
1040 else: 1048 else:
1041 if not quiet: 1049 if not quiet:
1042 E5MessageBox.critical( 1050 E5MessageBox.critical(
1043 self.ui, 1051 self.ui,
1044 self.tr("Read project session"), 1052 self.tr("Read project session"),
1045 self.tr( 1053 self.tr(
1046 "<p>The project session file <b>{0}</b> could not be" 1054 "<p>The project session file <b>{0}</b> could"
1047 " read.</p>").format(fn)) 1055 " not be read.</p>").format(fn))
1048 1056
1049 @pyqtSlot() 1057 @pyqtSlot()
1050 def __writeSession(self, quiet=False, indicator=""): 1058 def __writeSession(self, quiet=False, indicator=""):
1051 """ 1059 """
1052 Private method to write the session data to an XML file (.e5s). 1060 Private method to write the session data to an XML file (.esj).
1053 1061
1054 @param quiet flag indicating quiet operations. 1062 @param quiet flag indicating quiet operations.
1055 If this flag is true, no errors are reported. 1063 If this flag is true, no errors are reported.
1056 @param indicator indicator string (string) 1064 @param indicator indicator string (string)
1057 """ 1065 """
1058 # TODO: write project session 1066 # TODO: write project session
1059 if self.pfile is None: 1067 if self.pfile is None:
1060 if not quiet: 1068 if not quiet:
1061 E5MessageBox.critical( 1069 E5MessageBox.critical(
1062 self.ui, 1070 self.ui,
1063 self.tr("Save project session"), 1071 self.tr("Save Project Session"),
1064 self.tr("Please save the project first.")) 1072 self.tr("Please save the project first."))
1065 return 1073 return
1066 1074
1067 fn, ext = os.path.splitext(os.path.basename(self.pfile)) 1075 fn, ext = os.path.splitext(os.path.basename(self.pfile))
1068 fn = os.path.join(self.getProjectManagementDir(), 1076 fn = os.path.join(self.getProjectManagementDir(),
1069 '{0}{1}.e5s'.format(fn, indicator)) 1077 '{0}{1}.esj'.format(fn, indicator))
1070 1078
1071 f = QFile(fn) 1079 self.__sessionFile.writeFile(fn)
1072 if f.open(QIODevice.WriteOnly): 1080
1073 from E5XML.SessionWriter import SessionWriter
1074 SessionWriter(
1075 f, os.path.splitext(os.path.basename(fn))[0]).writeXML()
1076 f.close()
1077 else:
1078 if not quiet:
1079 E5MessageBox.critical(
1080 self.ui,
1081 self.tr("Save project session"),
1082 self.tr(
1083 "<p>The project session file <b>{0}</b> could not be"
1084 " written.</p>").format(fn))
1085
1086 def __deleteSession(self): 1081 def __deleteSession(self):
1087 """ 1082 """
1088 Private method to delete the session file. 1083 Private method to delete the session file.
1089 """ 1084 """
1090 if self.pfile is None: 1085 if self.pfile is None:
1204 self.ui, 1199 self.ui,
1205 self.tr("Read Debugger Properties"), 1200 self.tr("Read Debugger Properties"),
1206 self.tr("Please save the project first.")) 1201 self.tr("Please save the project first."))
1207 return 1202 return
1208 1203
1209 fn, ext = os.path.splitext(os.path.basename(self.pfile)) 1204 fn1, ext = os.path.splitext(os.path.basename(self.pfile))
1210 fn = os.path.join(self.getProjectManagementDir(), '{0}.edj'.format(fn)) 1205 fn = os.path.join(self.getProjectManagementDir(),
1206 '{0}.edj'.format(fn1))
1211 if os.path.exists(fn): 1207 if os.path.exists(fn):
1212 # try the new JSON based format first 1208 # try the new JSON based format first
1213 self.__debuggerPropertiesFile.readFile(fn) 1209 self.__debuggerPropertiesFile.readFile(fn)
1214 else: 1210 else:
1215 # try the old XML based format second 1211 # try the old XML based format second
1216 fn, ext = os.path.splitext(os.path.basename(self.pfile))
1217 fn = os.path.join(self.getProjectManagementDir(), 1212 fn = os.path.join(self.getProjectManagementDir(),
1218 '{0}.e4d'.format(fn)) 1213 '{0}.e4d'.format(fn1))
1219 1214
1220 f = QFile(fn) 1215 f = QFile(fn)
1221 if f.open(QIODevice.ReadOnly): 1216 if f.open(QIODevice.ReadOnly):
1222 from E5XML.DebuggerPropertiesReader import ( 1217 from E5XML.DebuggerPropertiesReader import (
1223 DebuggerPropertiesReader 1218 DebuggerPropertiesReader
1342 else: 1337 else:
1343 return self.debugProperties[key] 1338 return self.debugProperties[key]
1344 1339
1345 def setDbgInfo(self, venvName, argv, wd, env, excReporting, excList, 1340 def setDbgInfo(self, venvName, argv, wd, env, excReporting, excList,
1346 excIgnoreList, autoClearShell, tracePython=None, 1341 excIgnoreList, autoClearShell, tracePython=None,
1347 autoContinue=None): 1342 autoContinue=None, enableMultiprocess=None,
1343 multiprocessNoDebug=None):
1348 """ 1344 """
1349 Public method to set the debugging information. 1345 Public method to set the debugging information.
1350 1346
1351 @param venvName name of the virtual environment used 1347 @param venvName name of the virtual environment used
1352 @type str 1348 @type str
1369 traced as well 1365 traced as well
1370 @type bool 1366 @type bool
1371 @param autoContinue flag indicating, that the debugger should not 1367 @param autoContinue flag indicating, that the debugger should not
1372 stop at the first executable line 1368 stop at the first executable line
1373 @type bool 1369 @type bool
1370 @param enableMultiprocess flag indicating, that the debugger should
1371 run in multi process mode
1372 @type bool
1373 @param multiprocessNoDebug list of programs not to be debugged in
1374 multi process mode
1375 @type str
1374 """ 1376 """
1375 self.dbgVirtualEnv = venvName 1377 self.dbgVirtualEnv = venvName
1376 self.dbgCmdline = argv 1378 self.dbgCmdline = argv
1377 self.dbgWd = wd 1379 self.dbgWd = wd
1378 self.dbgEnv = env 1380 self.dbgEnv = env
1382 self.dbgAutoClearShell = autoClearShell 1384 self.dbgAutoClearShell = autoClearShell
1383 if tracePython is not None: 1385 if tracePython is not None:
1384 self.dbgTracePython = tracePython 1386 self.dbgTracePython = tracePython
1385 if autoContinue is not None: 1387 if autoContinue is not None:
1386 self.dbgAutoContinue = autoContinue 1388 self.dbgAutoContinue = autoContinue
1389 if enableMultiprocess is not None:
1390 self.dbgEnableMultiprocess = enableMultiprocess
1391 if multiprocessNoDebug is not None:
1392 self.dbgMultiprocessNoDebug = multiprocessNoDebug
1387 1393
1388 def getTranslationPattern(self): 1394 def getTranslationPattern(self):
1389 """ 1395 """
1390 Public method to get the translation pattern. 1396 Public method to get the translation pattern.
1391 1397

eric ide

mercurial