eric6/Project/Project.py

branch
jsonfiles
changeset 8011
630a173cb137
parent 8010
7ce2b8bb0d9b
child 8020
eddc8c3d3f9e
equal deleted inserted replaced
8010:7ce2b8bb0d9b 8011:630a173cb137
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 47
48 from Sessions.SessionFile import SessionFile 48 from Sessions.SessionFile import SessionFile
49
50 from Tasks.TasksFile import TasksFile
49 51
50 52
51 class Project(QObject): 53 class Project(QObject):
52 """ 54 """
53 Class implementing the project management functionality. 55 Class implementing the project management functionality.
192 194
193 self.__projectFile = ProjectFile(self) 195 self.__projectFile = ProjectFile(self)
194 self.__userProjectFile = UserProjectFile(self) 196 self.__userProjectFile = UserProjectFile(self)
195 self.__debuggerPropertiesFile = DebuggerPropertiesFile(self) 197 self.__debuggerPropertiesFile = DebuggerPropertiesFile(self)
196 self.__sessionFile = SessionFile(False) 198 self.__sessionFile = SessionFile(False)
199 self.__tasksFile = TasksFile(False)
197 200
198 self.recent = [] 201 self.recent = []
199 self.__loadRecent() 202 self.__loadRecent()
200 203
201 if filename is not None: 204 if filename is not None:
1061 1064
1062 @param quiet flag indicating quiet operations. 1065 @param quiet flag indicating quiet operations.
1063 If this flag is true, no errors are reported. 1066 If this flag is true, no errors are reported.
1064 @param indicator indicator string (string) 1067 @param indicator indicator string (string)
1065 """ 1068 """
1066 # TODO: write project session
1067 if self.pfile is None: 1069 if self.pfile is None:
1068 if not quiet: 1070 if not quiet:
1069 E5MessageBox.critical( 1071 E5MessageBox.critical(
1070 self.ui, 1072 self.ui,
1071 self.tr("Save Project Session"), 1073 self.tr("Save Project Session"),
1105 "<p>The project session file <b>{0}</b> could" 1107 "<p>The project session file <b>{0}</b> could"
1106 " not be deleted.</p>").format(fn)) 1108 " not be deleted.</p>").format(fn))
1107 1109
1108 def __readTasks(self): 1110 def __readTasks(self):
1109 """ 1111 """
1110 Private method to read in the project tasks file (.e6t). 1112 Private method to read in the project tasks file (.etj or .e6t).
1111 """ 1113 """
1112 if self.pfile is None: 1114 if self.pfile is None:
1113 E5MessageBox.critical( 1115 E5MessageBox.critical(
1114 self.ui, 1116 self.ui,
1115 self.tr("Read Tasks"), 1117 self.tr("Read Tasks"),
1116 self.tr("Please save the project first.")) 1118 self.tr("Please save the project first."))
1117 return 1119 return
1118 1120
1119 # TODO: read project tasks
1120 base, ext = os.path.splitext(os.path.basename(self.pfile)) 1121 base, ext = os.path.splitext(os.path.basename(self.pfile))
1121 fn = os.path.join(self.getProjectManagementDir(), 1122 fn = os.path.join(self.getProjectManagementDir(),
1122 '{0}.e6t'.format(base)) 1123 '{0}.etj'.format(base))
1123 if not os.path.exists(fn): 1124 if os.path.exists(fn):
1124 # try again with the old extension 1125 # try new style JSON file first
1126 self.__tasksFile.readFile(fn)
1127 else:
1128 # try old style XML file second
1125 fn = os.path.join(self.getProjectManagementDir(), 1129 fn = os.path.join(self.getProjectManagementDir(),
1126 '{0}.e4t'.format(base)) 1130 '{0}.e6t'.format(base))
1127 if not os.path.exists(fn): 1131 if os.path.exists(fn):
1128 return 1132 f = QFile(fn)
1129 f = QFile(fn) 1133 if f.open(QIODevice.ReadOnly):
1130 if f.open(QIODevice.ReadOnly): 1134 from E5XML.TasksReader import TasksReader
1131 from E5XML.TasksReader import TasksReader 1135 reader = TasksReader(f, True)
1132 reader = TasksReader(f, True) 1136 reader.readXML()
1133 reader.readXML() 1137 f.close()
1134 f.close() 1138 else:
1135 else: 1139 E5MessageBox.critical(
1136 E5MessageBox.critical( 1140 self.ui,
1137 self.ui, 1141 self.tr("Read Tasks"),
1138 self.tr("Read Tasks"), 1142 self.tr(
1139 self.tr( 1143 "<p>The tasks file <b>{0}</b> could not be read."
1140 "<p>The tasks file <b>{0}</b> could not be read.</p>") 1144 "</p>")
1141 .format(fn)) 1145 .format(fn))
1142 1146
1143 def writeTasks(self): 1147 def writeTasks(self):
1144 """ 1148 """
1145 Public method to write the tasks data to an XML file (.e6t). 1149 Public method to write the tasks data to an JSON file (.etj).
1146 """ 1150 """
1147 if self.pfile is None: 1151 if self.pfile is None:
1148 return 1152 return
1149 1153
1150 fn, ext = os.path.splitext(os.path.basename(self.pfile)) 1154 fn, ext = os.path.splitext(os.path.basename(self.pfile))
1151 1155
1152 # TODO: write project tasks 1156 fn = os.path.join(self.getProjectManagementDir(),
1153 fn = os.path.join(self.getProjectManagementDir(), '{0}.e6t'.format(fn)) 1157 '{0}.etj'.format(fn))
1154 f = QFile(fn) 1158 self.__tasksFile.writeFile(fn)
1155 ok = f.open(QIODevice.WriteOnly) 1159
1156 if not ok:
1157 E5MessageBox.critical(
1158 self.ui,
1159 self.tr("Save Tasks"),
1160 self.tr(
1161 "<p>The tasks file <b>{0}</b> could not be written.</p>")
1162 .format(fn))
1163 return
1164
1165 from E5XML.TasksWriter import TasksWriter
1166 TasksWriter(
1167 f, True, os.path.splitext(os.path.basename(fn))[0]).writeXML()
1168 f.close()
1169
1170 def __showContextMenuDebugger(self): 1160 def __showContextMenuDebugger(self):
1171 """ 1161 """
1172 Private slot called before the Debugger menu is shown. 1162 Private slot called before the Debugger menu is shown.
1173 """ 1163 """
1174 enable = True 1164 enable = True

eric ide

mercurial