45 from E5XML.ProjectWriter import ProjectWriter |
45 from E5XML.ProjectWriter import ProjectWriter |
46 from E5XML.UserProjectHandler import UserProjectHandler |
46 from E5XML.UserProjectHandler import UserProjectHandler |
47 from E5XML.UserProjectWriter import UserProjectWriter |
47 from E5XML.UserProjectWriter import UserProjectWriter |
48 from E5XML.SessionHandler import SessionHandler |
48 from E5XML.SessionHandler import SessionHandler |
49 from E5XML.SessionWriter import SessionWriter |
49 from E5XML.SessionWriter import SessionWriter |
50 from E5XML.TasksHandler import TasksHandler |
50 from E5XML.TasksReader import TasksReader |
51 from E5XML.TasksWriter import TasksWriter |
51 from E5XML.TasksWriter import TasksWriter |
52 from E5XML.DebuggerPropertiesHandler import DebuggerPropertiesHandler |
52 from E5XML.DebuggerPropertiesHandler import DebuggerPropertiesHandler |
53 from E5XML.DebuggerPropertiesWriter import DebuggerPropertiesWriter |
53 from E5XML.DebuggerPropertiesWriter import DebuggerPropertiesWriter |
54 |
54 |
55 import VCS |
55 import VCS |
1109 self.trUtf8("Read tasks"), |
1109 self.trUtf8("Read tasks"), |
1110 self.trUtf8("Please save the project first.")) |
1110 self.trUtf8("Please save the project first.")) |
1111 return |
1111 return |
1112 |
1112 |
1113 fn, ext = os.path.splitext(os.path.basename(self.pfile)) |
1113 fn, ext = os.path.splitext(os.path.basename(self.pfile)) |
1114 |
1114 fn = os.path.join(self.getProjectManagementDir(), '{0}.e4t'.format(fn)) |
1115 try: |
1115 if not os.path.exists(fn): |
1116 if ext.lower() in [".e4pz"]: |
1116 return |
1117 fn = os.path.join(self.getProjectManagementDir(), '{0}.e4tz'.format(fn)) |
1117 f = QFile(fn) |
1118 if not os.path.exists(fn): |
1118 if f.open(QIODevice.ReadOnly): |
1119 return |
1119 reader = TasksReader(f, True) |
1120 try: |
1120 reader.readXML() |
1121 import gzip |
1121 else: |
1122 except ImportError: |
|
1123 E5MessageBox.critical(self.ui, |
|
1124 self.trUtf8("Read tasks"), |
|
1125 self.trUtf8("""Compressed tasks files not supported.""" |
|
1126 """ The compression library is missing.""")) |
|
1127 return |
|
1128 g = gzip.open(fn, "rb") |
|
1129 f = io.StringIO(g.read().decode("utf-8")) |
|
1130 g.close() |
|
1131 else: |
|
1132 fn = os.path.join(self.getProjectManagementDir(), '{0}.e4t'.format(fn)) |
|
1133 if not os.path.exists(fn): |
|
1134 return |
|
1135 f = open(fn, "r", encoding = "utf-8") |
|
1136 line = f.readline() |
|
1137 dtdLine = f.readline() |
|
1138 f.close() |
|
1139 except EnvironmentError: |
|
1140 E5MessageBox.critical(self.ui, |
1122 E5MessageBox.critical(self.ui, |
1141 self.trUtf8("Read tasks"), |
1123 self.trUtf8("Read tasks"), |
1142 self.trUtf8("<p>The tasks file <b>{0}</b> could not be read.</p>")\ |
1124 self.trUtf8("<p>The tasks file <b>{0}</b> could not be read.</p>")\ |
1143 .format(fn)) |
1125 .format(fn)) |
1144 return |
|
1145 |
|
1146 # now read the file |
|
1147 if line.startswith('<?xml'): |
|
1148 self.__readXMLTasks(fn, dtdLine.startswith("<!DOCTYPE")) |
|
1149 else: |
|
1150 E5MessageBox.critical(self.ui, |
|
1151 self.trUtf8("Read project session"), |
|
1152 self.trUtf8("<p>The tasks file <b>{0}</b> has an unsupported" |
|
1153 " format.</p>")\ |
|
1154 .format(fn)) |
|
1155 |
|
1156 def __readXMLTasks(self, fn, validating): |
|
1157 """ |
|
1158 Private method to read the project tasks data from an XML file. |
|
1159 |
|
1160 @param fn filename of the project tasks file to be read (string) |
|
1161 @param validating flag indicating a validation of the XML file is |
|
1162 requested (boolean) |
|
1163 """ |
|
1164 if fn.lower().endswith("e4tz"): |
|
1165 # work around for a bug in xmlproc |
|
1166 validating = False |
|
1167 |
|
1168 parser = make_parser(validating) |
|
1169 handler = TasksHandler(1) |
|
1170 er = XMLEntityResolver() |
|
1171 eh = XMLErrorHandler() |
|
1172 |
|
1173 parser.setContentHandler(handler) |
|
1174 parser.setEntityResolver(er) |
|
1175 parser.setErrorHandler(eh) |
|
1176 |
|
1177 try: |
|
1178 if fn.lower().endswith("e4tz"): |
|
1179 try: |
|
1180 import gzip |
|
1181 except ImportError: |
|
1182 E5MessageBox.critical(self.ui, |
|
1183 self.trUtf8("Read tasks"), |
|
1184 self.trUtf8("""Compressed tasks files not supported.""" |
|
1185 """ The compression library is missing.""")) |
|
1186 return |
|
1187 g = gzip.open(fn, "rb") |
|
1188 f = io.StringIO(g.read().decode("utf-8")) |
|
1189 g.close() |
|
1190 else: |
|
1191 f = open(fn, "r", encoding = "utf-8") |
|
1192 try: |
|
1193 try: |
|
1194 parser.parse(f) |
|
1195 except UnicodeEncodeError: |
|
1196 f.seek(0) |
|
1197 buf = io.StringIO(f.read()) |
|
1198 parser.parse(buf) |
|
1199 finally: |
|
1200 f.close() |
|
1201 except IOError: |
|
1202 E5MessageBox.critical(self.ui, |
|
1203 self.trUtf8("Read tasks"), |
|
1204 self.trUtf8("<p>The tasks file <b>{0}</b> could not be read.</p>")\ |
|
1205 .format(fn)) |
|
1206 return |
|
1207 except XMLFatalParseError: |
|
1208 pass |
|
1209 |
|
1210 eh.showParseMessages() |
|
1211 |
1126 |
1212 def __writeTasks(self): |
1127 def __writeTasks(self): |
1213 """ |
1128 """ |
1214 Private method to write the tasks data to an XML file (.e4t). |
1129 Private method to write the tasks data to an XML file (.e4t). |
1215 """ |
1130 """ |