783 self.pdata[index].remove(file) |
792 self.pdata[index].remove(file) |
784 self.setDirty(True) |
793 self.setDirty(True) |
785 |
794 |
786 def __readProject(self, fn): |
795 def __readProject(self, fn): |
787 """ |
796 """ |
788 Private method to read in a project (.e4p) file. |
797 Private method to read in a project (.epj or .e4p) file. |
789 |
798 |
790 @param fn filename of the project file to be read (string) |
799 @param fn filename of the project file to be read (string) |
791 @return flag indicating success |
800 @return flag indicating success |
792 """ |
801 """ |
793 f = QFile(fn) |
802 if os.path.splitext(fn)[1] == ".epj": |
794 if f.open(QIODevice.ReadOnly): |
803 # new JSON based format |
795 from E5XML.ProjectReader import ProjectReader |
804 with E5OverrideCursor(): |
796 reader = ProjectReader(f, self) |
805 res = self.__projectFile.readFile(fn) |
797 reader.readXML() |
|
798 res = not reader.hasError() |
|
799 f.close() |
|
800 else: |
806 else: |
801 E5MessageBox.critical( |
807 # old XML based format |
802 self.ui, |
808 f = QFile(fn) |
803 self.tr("Read project file"), |
809 if f.open(QIODevice.ReadOnly): |
804 self.tr( |
810 from E5XML.ProjectReader import ProjectReader |
805 "<p>The project file <b>{0}</b> could not be read.</p>") |
811 reader = ProjectReader(f, self) |
806 .format(fn)) |
812 reader.readXML() |
807 return False |
813 res = not reader.hasError() |
808 |
814 f.close() |
809 self.pfile = os.path.abspath(fn) |
815 |
810 self.ppath = os.path.abspath(os.path.dirname(fn)) |
816 # create hash value, if it doesn't have one |
811 |
817 if reader.version.startswith("5.") and not self.pdata["HASH"]: |
812 # insert filename into list of recently opened projects |
818 hashStr = str(QCryptographicHash.hash( |
813 self.__syncRecent() |
819 QByteArray(self.ppath.encode("utf-8")), |
|
820 QCryptographicHash.Sha1).toHex(), |
|
821 encoding="utf-8") |
|
822 self.pdata["HASH"] = hashStr |
|
823 self.setDirty(True) |
|
824 else: |
|
825 E5MessageBox.critical( |
|
826 self.ui, |
|
827 self.tr("Read Project File"), |
|
828 self.tr( |
|
829 "<p>The project file <b>{0}</b> could not be read." |
|
830 "</p>") |
|
831 .format(fn)) |
|
832 res = False |
814 |
833 |
815 if res: |
834 if res: |
|
835 self.pfile = os.path.abspath(fn) |
|
836 self.ppath = os.path.abspath(os.path.dirname(fn)) |
|
837 |
|
838 # insert filename into list of recently opened projects |
|
839 self.__syncRecent() |
|
840 |
816 if self.pdata["TRANSLATIONPATTERN"]: |
841 if self.pdata["TRANSLATIONPATTERN"]: |
817 self.translationsRoot = self.pdata["TRANSLATIONPATTERN"].split( |
842 self.translationsRoot = self.pdata["TRANSLATIONPATTERN"].split( |
818 "%language%")[0] |
843 "%language%")[0] |
819 elif self.pdata["MAINSCRIPT"]: |
844 elif self.pdata["MAINSCRIPT"]: |
820 self.translationsRoot = os.path.splitext( |
845 self.translationsRoot = os.path.splitext( |
892 self.pdata["HASH"] = hashStr |
908 self.pdata["HASH"] = hashStr |
893 |
909 |
894 if fn is None: |
910 if fn is None: |
895 fn = self.pfile |
911 fn = self.pfile |
896 |
912 |
897 f = QFile(fn) |
913 if os.path.splitext(fn)[1] == ".epj": |
898 if f.open(QIODevice.WriteOnly): |
914 # new JSON based format |
899 from E5XML.ProjectWriter import ProjectWriter |
915 with E5OverrideCursor(): |
900 ProjectWriter(f, os.path.splitext( |
916 res = self.__projectFile.writeFile(fn) |
901 os.path.basename(fn))[0]).writeXML() |
|
902 res = True |
|
903 else: |
917 else: |
904 E5MessageBox.critical( |
918 # old XML based format |
905 self.ui, |
919 f = QFile(fn) |
906 self.tr("Save project file"), |
920 if f.open(QIODevice.WriteOnly): |
907 self.tr( |
921 from E5XML.ProjectWriter import ProjectWriter |
908 "<p>The project file <b>{0}</b> could not be" |
922 ProjectWriter(f, os.path.splitext( |
909 " written.</p>").format(fn)) |
923 os.path.basename(fn))[0]).writeXML() |
910 res = False |
924 res = True |
|
925 else: |
|
926 E5MessageBox.critical( |
|
927 self.ui, |
|
928 self.tr("Save Project File"), |
|
929 self.tr( |
|
930 "<p>The project file <b>{0}</b> could not be" |
|
931 " written.</p>").format(fn)) |
|
932 res = False |
911 |
933 |
912 if res: |
934 if res: |
913 self.pfile = os.path.abspath(fn) |
935 self.pfile = os.path.abspath(fn) |
914 self.ppath = os.path.abspath(os.path.dirname(fn)) |
936 self.ppath = os.path.abspath(os.path.dirname(fn)) |
915 self.name = os.path.splitext(os.path.basename(fn))[0] |
937 self.name = os.path.splitext(os.path.basename(fn))[0] |
920 |
942 |
921 return res |
943 return res |
922 |
944 |
923 def __readUserProperties(self): |
945 def __readUserProperties(self): |
924 """ |
946 """ |
925 Private method to read in the user specific project file (.e4q). |
947 Private method to read in the user specific project file (.eqj or |
|
948 .e4q). |
926 """ |
949 """ |
927 if self.pfile is None: |
950 if self.pfile is None: |
928 return |
951 return |
929 |
952 |
930 fn, ext = os.path.splitext(os.path.basename(self.pfile)) |
953 fn, ext = os.path.splitext(os.path.basename(self.pfile)) |
931 fn = os.path.join(self.getProjectManagementDir(), '{0}.e4q'.format(fn)) |
954 fn = os.path.join(self.getProjectManagementDir(), '{0}.eqj'.format(fn)) |
932 if os.path.exists(fn): |
955 if os.path.exists(fn): |
933 f = QFile(fn) |
956 # try the new JSON based format first |
934 if f.open(QIODevice.ReadOnly): |
957 self.__userProjectFile.readFile(fn) |
935 from E5XML.UserProjectReader import UserProjectReader |
958 else: |
936 reader = UserProjectReader(f, self) |
959 # try the old XML based format second |
937 reader.readXML() |
960 fn = os.path.join(self.getProjectManagementDir(), |
938 f.close() |
961 '{0}.e4q'.format(fn)) |
939 else: |
962 if os.path.exists(fn): |
940 E5MessageBox.critical( |
963 f = QFile(fn) |
941 self.ui, |
964 if f.open(QIODevice.ReadOnly): |
942 self.tr("Read user project properties"), |
965 from E5XML.UserProjectReader import UserProjectReader |
943 self.tr( |
966 reader = UserProjectReader(f, self) |
944 "<p>The user specific project properties file" |
967 reader.readXML() |
945 " <b>{0}</b> could not be read.</p>").format(fn)) |
968 f.close() |
|
969 else: |
|
970 E5MessageBox.critical( |
|
971 self.ui, |
|
972 self.tr("Read User Project Properties"), |
|
973 self.tr( |
|
974 "<p>The user specific project properties file" |
|
975 " <b>{0}</b> could not be read.</p>").format(fn)) |
946 |
976 |
947 def __writeUserProperties(self): |
977 def __writeUserProperties(self): |
948 """ |
978 """ |
949 Private method to write the project data to an XML file. |
979 Private method to write the user specific project data to a JSON file. |
950 """ |
980 """ |
951 if self.pfile is None: |
981 if self.pfile is None: |
952 return |
982 return |
953 |
983 |
954 fn, ext = os.path.splitext(os.path.basename(self.pfile)) |
984 fn, ext = os.path.splitext(os.path.basename(self.pfile)) |
955 fn = os.path.join(self.getProjectManagementDir(), '{0}.e4q'.format(fn)) |
985 fn = os.path.join(self.getProjectManagementDir(), '{0}.eqj'.format(fn)) |
956 |
986 |
957 f = QFile(fn) |
987 with E5OverrideCursor(): |
958 if f.open(QIODevice.WriteOnly): |
988 self.__userProjectFile.writeFile(fn) |
959 from E5XML.UserProjectWriter import UserProjectWriter |
989 |
960 UserProjectWriter( |
|
961 f, os.path.splitext(os.path.basename(fn))[0]).writeXML() |
|
962 f.close() |
|
963 else: |
|
964 E5MessageBox.critical( |
|
965 self.ui, |
|
966 self.tr("Save user project properties"), |
|
967 self.tr( |
|
968 "<p>The user specific project properties file <b>{0}</b>" |
|
969 " could not be written.</p>").format(fn)) |
|
970 |
|
971 def __showContextMenuSession(self): |
990 def __showContextMenuSession(self): |
972 """ |
991 """ |
973 Private slot called before the Session menu is shown. |
992 Private slot called before the Session menu is shown. |
974 """ |
993 """ |
975 enable = True |
994 enable = True |
1067 Private method to delete the session file. |
1088 Private method to delete the session file. |
1068 """ |
1089 """ |
1069 if self.pfile is None: |
1090 if self.pfile is None: |
1070 E5MessageBox.critical( |
1091 E5MessageBox.critical( |
1071 self.ui, |
1092 self.ui, |
1072 self.tr("Delete project session"), |
1093 self.tr("Delete Project Session"), |
1073 self.tr("Please save the project first.")) |
1094 self.tr("Please save the project first.")) |
1074 return |
1095 return |
1075 |
1096 |
1076 fname, ext = os.path.splitext(os.path.basename(self.pfile)) |
1097 fname, ext = os.path.splitext(os.path.basename(self.pfile)) |
1077 |
1098 |
1078 for fn in [ |
1099 for ext in (".esj", ".e5s", ".e4s"): |
1079 os.path.join( |
1100 fn = os.path.join( |
1080 self.getProjectManagementDir(), "{0}.e5s".format(fname)), |
1101 self.getProjectManagementDir(), "{0}{1}".format(fname, ext)), |
1081 os.path.join( |
|
1082 self.getProjectManagementDir(), "{0}.e4s".format(fname))]: |
|
1083 if os.path.exists(fn): |
1102 if os.path.exists(fn): |
1084 try: |
1103 try: |
1085 os.remove(fn) |
1104 os.remove(fn) |
1086 except OSError: |
1105 except OSError: |
1087 E5MessageBox.critical( |
1106 E5MessageBox.critical( |
1088 self.ui, |
1107 self.ui, |
1089 self.tr("Delete project session"), |
1108 self.tr("Delete Project Session"), |
1090 self.tr( |
1109 self.tr( |
1091 "<p>The project session file <b>{0}</b> could" |
1110 "<p>The project session file <b>{0}</b> could" |
1092 " not be deleted.</p>").format(fn)) |
1111 " not be deleted.</p>").format(fn)) |
1093 |
1112 |
1094 def __readTasks(self): |
1113 def __readTasks(self): |
1169 QAction, "project_debugger_properties_delete").setEnabled(enable) |
1190 QAction, "project_debugger_properties_delete").setEnabled(enable) |
1170 |
1191 |
1171 @pyqtSlot() |
1192 @pyqtSlot() |
1172 def __readDebugProperties(self, quiet=False): |
1193 def __readDebugProperties(self, quiet=False): |
1173 """ |
1194 """ |
1174 Private method to read in the project debugger properties file (.e4d). |
1195 Private method to read in the project debugger properties file |
|
1196 (.edj or .e4d). |
1175 |
1197 |
1176 @param quiet flag indicating quiet operations. |
1198 @param quiet flag indicating quiet operations. |
1177 If this flag is true, no errors are reported. |
1199 If this flag is true, no errors are reported. |
1178 """ |
1200 """ |
1179 if self.pfile is None: |
1201 if self.pfile is None: |
1180 if not quiet: |
1202 if not quiet: |
1181 E5MessageBox.critical( |
1203 E5MessageBox.critical( |
1182 self.ui, |
1204 self.ui, |
1183 self.tr("Read debugger properties"), |
1205 self.tr("Read Debugger Properties"), |
1184 self.tr("Please save the project first.")) |
1206 self.tr("Please save the project first.")) |
1185 return |
1207 return |
|
1208 |
|
1209 fn, ext = os.path.splitext(os.path.basename(self.pfile)) |
|
1210 fn = os.path.join(self.getProjectManagementDir(), '{0}.edj'.format(fn)) |
|
1211 if os.path.exists(fn): |
|
1212 # try the new JSON based format first |
|
1213 self.__debuggerPropertiesFile.readFile(fn) |
|
1214 else: |
|
1215 # 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(), |
|
1218 '{0}.e4d'.format(fn)) |
1186 |
1219 |
1187 fn, ext = os.path.splitext(os.path.basename(self.pfile)) |
1220 f = QFile(fn) |
1188 fn = os.path.join(self.getProjectManagementDir(), '{0}.e4d'.format(fn)) |
1221 if f.open(QIODevice.ReadOnly): |
1189 |
1222 from E5XML.DebuggerPropertiesReader import ( |
1190 f = QFile(fn) |
1223 DebuggerPropertiesReader |
1191 if f.open(QIODevice.ReadOnly): |
1224 ) |
1192 from E5XML.DebuggerPropertiesReader import DebuggerPropertiesReader |
1225 reader = DebuggerPropertiesReader(f, self) |
1193 reader = DebuggerPropertiesReader(f, self) |
1226 reader.readXML(quiet=quiet) |
1194 reader.readXML(quiet=quiet) |
1227 f.close() |
1195 f.close() |
1228 self.debugPropertiesLoaded = True |
1196 self.debugPropertiesLoaded = True |
1229 self.debugPropertiesChanged = False |
1197 self.debugPropertiesChanged = False |
1230 else: |
1198 else: |
1231 if not quiet: |
1199 if not quiet: |
1232 E5MessageBox.critical( |
1200 E5MessageBox.critical( |
1233 self.ui, |
1201 self.ui, |
1234 self.tr("Read Debugger Properties"), |
1202 self.tr("Read debugger properties"), |
1235 self.tr( |
1203 self.tr( |
1236 "<p>The project debugger properties file" |
1204 "<p>The project debugger properties file <b>{0}</b>" |
1237 " <b>{0}</b> could not be read.</p>").format(fn)) |
1205 " could not be read.</p>").format(fn)) |
1238 |
1206 |
|
1207 @pyqtSlot() |
1239 @pyqtSlot() |
1208 def __writeDebugProperties(self, quiet=False): |
1240 def __writeDebugProperties(self, quiet=False): |
1209 """ |
1241 """ |
1210 Private method to write the project debugger properties file (.e4d). |
1242 Private method to write the project debugger properties file (.edj). |
1211 |
1243 |
1212 @param quiet flag indicating quiet operations. |
1244 @param quiet flag indicating quiet operations. |
1213 If this flag is true, no errors are reported. |
1245 If this flag is true, no errors are reported. |
1214 """ |
1246 """ |
1215 if self.pfile is None: |
1247 if self.pfile is None: |
1216 if not quiet: |
1248 if not quiet: |
1217 E5MessageBox.critical( |
1249 E5MessageBox.critical( |
1218 self.ui, |
1250 self.ui, |
1219 self.tr("Save debugger properties"), |
1251 self.tr("Save Debugger Properties"), |
1220 self.tr("Please save the project first.")) |
1252 self.tr("Please save the project first.")) |
1221 return |
1253 return |
1222 |
1254 |
1223 fn, ext = os.path.splitext(os.path.basename(self.pfile)) |
1255 fn, ext = os.path.splitext(os.path.basename(self.pfile)) |
1224 fn = os.path.join(self.getProjectManagementDir(), '{0}.e4d'.format(fn)) |
1256 fn = os.path.join(self.getProjectManagementDir(), '{0}.edj'.format(fn)) |
1225 |
1257 |
1226 f = QFile(fn) |
1258 with E5OverrideCursor(): |
1227 if f.open(QIODevice.WriteOnly): |
1259 self.__debuggerPropertiesFile.writeFile(fn) |
1228 from E5XML.DebuggerPropertiesWriter import DebuggerPropertiesWriter |
1260 |
1229 DebuggerPropertiesWriter( |
|
1230 f, os.path.splitext(os.path.basename(fn))[0]).writeXML() |
|
1231 f.close() |
|
1232 self.debugPropertiesChanged = False |
|
1233 else: |
|
1234 if not quiet: |
|
1235 E5MessageBox.critical( |
|
1236 self.ui, |
|
1237 self.tr("Save debugger properties"), |
|
1238 self.tr( |
|
1239 "<p>The project debugger properties file <b>{0}</b>" |
|
1240 " could not be written.</p>").format(fn)) |
|
1241 |
|
1242 def __deleteDebugProperties(self): |
1261 def __deleteDebugProperties(self): |
1243 """ |
1262 """ |
1244 Private method to delete the project debugger properties file (.e4d). |
1263 Private method to delete the project debugger properties file |
|
1264 (.edj or .e4d). |
1245 """ |
1265 """ |
1246 if self.pfile is None: |
1266 if self.pfile is None: |
1247 E5MessageBox.critical( |
1267 E5MessageBox.critical( |
1248 self.ui, |
1268 self.ui, |
1249 self.tr("Delete debugger properties"), |
1269 self.tr("Delete Debugger Properties"), |
1250 self.tr("Please save the project first.")) |
1270 self.tr("Please save the project first.")) |
1251 return |
1271 return |
1252 |
1272 |
1253 fname, ext = os.path.splitext(os.path.basename(self.pfile)) |
1273 fname, ext = os.path.splitext(os.path.basename(self.pfile)) |
1254 |
1274 |
1255 for fn in [os.path.join(self.getProjectManagementDir(), |
1275 for ext in (".edj", ".e4d"): |
1256 "{0}.e4d".format(fname))]: |
1276 fn = os.path.join(self.getProjectManagementDir(), |
|
1277 "{0}{1}".format(fname, ext)) |
1257 if os.path.exists(fn): |
1278 if os.path.exists(fn): |
1258 try: |
1279 try: |
1259 os.remove(fn) |
1280 os.remove(fn) |
1260 except OSError: |
1281 except OSError: |
1261 E5MessageBox.critical( |
1282 E5MessageBox.critical( |
1262 self.ui, |
1283 self.ui, |
1263 self.tr("Delete debugger properties"), |
1284 self.tr("Delete Debugger Properties"), |
1264 self.tr( |
1285 self.tr( |
1265 "<p>The project debugger properties file" |
1286 "<p>The project debugger properties file" |
1266 " <b>{0}</b> could not be deleted.</p>") |
1287 " <b>{0}</b> could not be deleted.</p>") |
1267 .format(fn)) |
1288 .format(fn)) |
1268 |
1289 |