eric6/Project/Project.py

changeset 8143
2c730d5fd177
parent 8140
61113590d4ab
child 8163
29fb6d420a25
equal deleted inserted replaced
8141:27f636beebad 8143:2c730d5fd177
812 with E5OverrideCursor(): 812 with E5OverrideCursor():
813 res = self.__projectFile.readFile(fn) 813 res = self.__projectFile.readFile(fn)
814 else: 814 else:
815 # old XML based format 815 # old XML based format
816 f = QFile(fn) 816 f = QFile(fn)
817 if f.open(QIODevice.ReadOnly): 817 if f.open(QIODevice.OpenModeFlag.ReadOnly):
818 from E5XML.ProjectReader import ProjectReader 818 from E5XML.ProjectReader import ProjectReader
819 reader = ProjectReader(f, self) 819 reader = ProjectReader(f, self)
820 reader.readXML() 820 reader.readXML()
821 res = not reader.hasError() 821 res = not reader.hasError()
822 f.close() 822 f.close()
823 823
824 # create hash value, if it doesn't have one 824 # create hash value, if it doesn't have one
825 if reader.version.startswith("5.") and not self.pdata["HASH"]: 825 if reader.version.startswith("5.") and not self.pdata["HASH"]:
826 hashStr = str(QCryptographicHash.hash( 826 hashStr = str(QCryptographicHash.hash(
827 QByteArray(self.ppath.encode("utf-8")), 827 QByteArray(self.ppath.encode("utf-8")),
828 QCryptographicHash.Sha1).toHex(), 828 QCryptographicHash.Algorithm.Sha1).toHex(),
829 encoding="utf-8") 829 encoding="utf-8")
830 self.pdata["HASH"] = hashStr 830 self.pdata["HASH"] = hashStr
831 self.setDirty(True) 831 self.setDirty(True)
832 else: 832 else:
833 E5MessageBox.critical( 833 E5MessageBox.critical(
909 self.vcs.vcsGetOtherData()) 909 self.vcs.vcsGetOtherData())
910 910
911 if not self.pdata["HASH"]: 911 if not self.pdata["HASH"]:
912 hashStr = str(QCryptographicHash.hash( 912 hashStr = str(QCryptographicHash.hash(
913 QByteArray(self.ppath.encode("utf-8")), 913 QByteArray(self.ppath.encode("utf-8")),
914 QCryptographicHash.Sha1).toHex(), 914 QCryptographicHash.Algorithm.Sha1).toHex(),
915 encoding="utf-8") 915 encoding="utf-8")
916 self.pdata["HASH"] = hashStr 916 self.pdata["HASH"] = hashStr
917 917
918 if fn is None: 918 if fn is None:
919 fn = self.pfile 919 fn = self.pfile
923 with E5OverrideCursor(): 923 with E5OverrideCursor():
924 res = self.__projectFile.writeFile(fn) 924 res = self.__projectFile.writeFile(fn)
925 else: 925 else:
926 # old XML based format 926 # old XML based format
927 f = QFile(fn) 927 f = QFile(fn)
928 if f.open(QIODevice.WriteOnly): 928 if f.open(QIODevice.OpenModeFlag.WriteOnly):
929 from E5XML.ProjectWriter import ProjectWriter 929 from E5XML.ProjectWriter import ProjectWriter
930 ProjectWriter(f, os.path.splitext( 930 ProjectWriter(f, os.path.splitext(
931 os.path.basename(fn))[0]).writeXML() 931 os.path.basename(fn))[0]).writeXML()
932 res = True 932 res = True
933 else: 933 else:
968 # try the old XML based format second 968 # try the old XML based format second
969 fn = os.path.join(self.getProjectManagementDir(), 969 fn = os.path.join(self.getProjectManagementDir(),
970 '{0}.e4q'.format(fn1)) 970 '{0}.e4q'.format(fn1))
971 if os.path.exists(fn): 971 if os.path.exists(fn):
972 f = QFile(fn) 972 f = QFile(fn)
973 if f.open(QIODevice.ReadOnly): 973 if f.open(QIODevice.OpenModeFlag.ReadOnly):
974 from E5XML.UserProjectReader import UserProjectReader 974 from E5XML.UserProjectReader import UserProjectReader
975 reader = UserProjectReader(f, self) 975 reader = UserProjectReader(f, self)
976 reader.readXML() 976 reader.readXML()
977 f.close() 977 f.close()
978 else: 978 else:
1042 # try the old XML based format second 1042 # try the old XML based format second
1043 fn = os.path.join(self.getProjectManagementDir(), 1043 fn = os.path.join(self.getProjectManagementDir(),
1044 '{0}{1}.e5s'.format(fn1, indicator)) 1044 '{0}{1}.e5s'.format(fn1, indicator))
1045 if os.path.exists(fn): 1045 if os.path.exists(fn):
1046 f = QFile(fn) 1046 f = QFile(fn)
1047 if f.open(QIODevice.ReadOnly): 1047 if f.open(QIODevice.OpenModeFlag.ReadOnly):
1048 from E5XML.SessionReader import SessionReader 1048 from E5XML.SessionReader import SessionReader
1049 reader = SessionReader(f, False) 1049 reader = SessionReader(f, False)
1050 reader.readXML(quiet=quiet) 1050 reader.readXML(quiet=quiet)
1051 f.close() 1051 f.close()
1052 else: 1052 else:
1129 # try old style XML file second 1129 # try old style XML file second
1130 fn = os.path.join(self.getProjectManagementDir(), 1130 fn = os.path.join(self.getProjectManagementDir(),
1131 '{0}.e6t'.format(base)) 1131 '{0}.e6t'.format(base))
1132 if os.path.exists(fn): 1132 if os.path.exists(fn):
1133 f = QFile(fn) 1133 f = QFile(fn)
1134 if f.open(QIODevice.ReadOnly): 1134 if f.open(QIODevice.OpenModeFlag.ReadOnly):
1135 from E5XML.TasksReader import TasksReader 1135 from E5XML.TasksReader import TasksReader
1136 reader = TasksReader(f, True) 1136 reader = TasksReader(f, True)
1137 reader.readXML() 1137 reader.readXML()
1138 f.close() 1138 f.close()
1139 else: 1139 else:
1207 # try the old XML based format second 1207 # try the old XML based format second
1208 fn = os.path.join(self.getProjectManagementDir(), 1208 fn = os.path.join(self.getProjectManagementDir(),
1209 '{0}.e4d'.format(fn1)) 1209 '{0}.e4d'.format(fn1))
1210 1210
1211 f = QFile(fn) 1211 f = QFile(fn)
1212 if f.open(QIODevice.ReadOnly): 1212 if f.open(QIODevice.OpenModeFlag.ReadOnly):
1213 from E5XML.DebuggerPropertiesReader import ( 1213 from E5XML.DebuggerPropertiesReader import (
1214 DebuggerPropertiesReader 1214 DebuggerPropertiesReader
1215 ) 1215 )
1216 reader = DebuggerPropertiesReader(f, self) 1216 reader = DebuggerPropertiesReader(f, self)
1217 reader.readXML(quiet=quiet) 1217 reader.readXML(quiet=quiet)
1313 """ 1313 """
1314 Private slot to display the debugger properties dialog. 1314 Private slot to display the debugger properties dialog.
1315 """ 1315 """
1316 from .DebuggerPropertiesDialog import DebuggerPropertiesDialog 1316 from .DebuggerPropertiesDialog import DebuggerPropertiesDialog
1317 dlg = DebuggerPropertiesDialog(self) 1317 dlg = DebuggerPropertiesDialog(self)
1318 if dlg.exec() == QDialog.Accepted: 1318 if dlg.exec() == QDialog.DialogCode.Accepted:
1319 dlg.storeData() 1319 dlg.storeData()
1320 1320
1321 def getDebugProperty(self, key): 1321 def getDebugProperty(self, key):
1322 """ 1322 """
1323 Public method to retrieve a debugger property. 1323 Public method to retrieve a debugger property.
1416 "You have to specify a translation pattern first.")) 1416 "You have to specify a translation pattern first."))
1417 return 1417 return
1418 1418
1419 from .AddLanguageDialog import AddLanguageDialog 1419 from .AddLanguageDialog import AddLanguageDialog
1420 dlg = AddLanguageDialog(self.parent()) 1420 dlg = AddLanguageDialog(self.parent())
1421 if dlg.exec() == QDialog.Accepted: 1421 if dlg.exec() == QDialog.DialogCode.Accepted:
1422 lang = dlg.getSelectedLanguage() 1422 lang = dlg.getSelectedLanguage()
1423 if self.pdata["PROJECTTYPE"] in [ 1423 if self.pdata["PROJECTTYPE"] in [
1424 "PyQt5", "PyQt5C", "PyQt6", "PyQt6C", "E6Plugin", 1424 "PyQt5", "PyQt5C", "PyQt6", "PyQt6C", "E6Plugin",
1425 "PySide2", "PySide2C", "PySide6", "PySide6C" 1425 "PySide2", "PySide2C", "PySide6", "PySide6C"
1426 ]: 1426 ]:
1661 if startdir is None: 1661 if startdir is None:
1662 startdir = self.ppath 1662 startdir = self.ppath
1663 from .AddFileDialog import AddFileDialog 1663 from .AddFileDialog import AddFileDialog
1664 dlg = AddFileDialog(self, self.parent(), fileTypeFilter, 1664 dlg = AddFileDialog(self, self.parent(), fileTypeFilter,
1665 startdir=startdir) 1665 startdir=startdir)
1666 if dlg.exec() == QDialog.Accepted: 1666 if dlg.exec() == QDialog.DialogCode.Accepted:
1667 fnames, target, isSource = dlg.getData() 1667 fnames, target, isSource = dlg.getData()
1668 if target != '': 1668 if target != '':
1669 for fn in fnames: 1669 for fn in fnames:
1670 targetfile = os.path.join(target, os.path.basename(fn)) 1670 targetfile = os.path.join(target, os.path.basename(fn))
1671 if not Utilities.samepath(os.path.dirname(fn), target): 1671 if not Utilities.samepath(os.path.dirname(fn), target):
1827 if startdir is None: 1827 if startdir is None:
1828 startdir = self.ppath 1828 startdir = self.ppath
1829 from .AddDirectoryDialog import AddDirectoryDialog 1829 from .AddDirectoryDialog import AddDirectoryDialog
1830 dlg = AddDirectoryDialog( 1830 dlg = AddDirectoryDialog(
1831 self, fileTypeFilter, self.parent(), startdir=startdir) 1831 self, fileTypeFilter, self.parent(), startdir=startdir)
1832 if dlg.exec() == QDialog.Accepted: 1832 if dlg.exec() == QDialog.DialogCode.Accepted:
1833 filetype, source, target, recursive = dlg.getData() 1833 filetype, source, target, recursive = dlg.getData()
1834 if target == '': 1834 if target == '':
1835 E5MessageBox.critical( 1835 E5MessageBox.critical(
1836 self.ui, 1836 self.ui,
1837 self.tr("Add directory"), 1837 self.tr("Add directory"),
2325 if not self.checkDirty(): 2325 if not self.checkDirty():
2326 return 2326 return
2327 2327
2328 from .PropertiesDialog import PropertiesDialog 2328 from .PropertiesDialog import PropertiesDialog
2329 dlg = PropertiesDialog(self, True) 2329 dlg = PropertiesDialog(self, True)
2330 if dlg.exec() == QDialog.Accepted: 2330 if dlg.exec() == QDialog.DialogCode.Accepted:
2331 self.closeProject() 2331 self.closeProject()
2332 dlg.storeData() 2332 dlg.storeData()
2333 self.pdata["VCS"] = 'None' 2333 self.pdata["VCS"] = 'None'
2334 self.opened = True 2334 self.opened = True
2335 if not self.pdata["FILETYPES"]: 2335 if not self.pdata["FILETYPES"]:
2362 2362
2363 self.projectAboutToBeCreated.emit() 2363 self.projectAboutToBeCreated.emit()
2364 2364
2365 hashStr = str(QCryptographicHash.hash( 2365 hashStr = str(QCryptographicHash.hash(
2366 QByteArray(self.ppath.encode("utf-8")), 2366 QByteArray(self.ppath.encode("utf-8")),
2367 QCryptographicHash.Sha1).toHex(), 2367 QCryptographicHash.Algorithm.Sha1).toHex(),
2368 encoding="utf-8") 2368 encoding="utf-8")
2369 self.pdata["HASH"] = hashStr 2369 self.pdata["HASH"] = hashStr
2370 2370
2371 if self.pdata["PROGLANGUAGE"] == "MicroPython": 2371 if self.pdata["PROGLANGUAGE"] == "MicroPython":
2372 # change the lexer association for *.py files 2372 # change the lexer association for *.py files
2563 if vcores: 2563 if vcores:
2564 from VCS.CommandOptionsDialog import ( 2564 from VCS.CommandOptionsDialog import (
2565 VcsCommandOptionsDialog 2565 VcsCommandOptionsDialog
2566 ) 2566 )
2567 codlg = VcsCommandOptionsDialog(self.vcs) 2567 codlg = VcsCommandOptionsDialog(self.vcs)
2568 if codlg.exec() == QDialog.Accepted: 2568 if codlg.exec() == QDialog.DialogCode.Accepted:
2569 self.vcs.vcsSetOptions(codlg.getOptions()) 2569 self.vcs.vcsSetOptions(codlg.getOptions())
2570 # add project file to repository 2570 # add project file to repository
2571 if res == 0: 2571 if res == 0:
2572 apres = E5MessageBox.yesNo( 2572 apres = E5MessageBox.yesNo(
2573 self.ui, 2573 self.ui,
2615 else: 2615 else:
2616 self.pdata["VCS"] = 'None' 2616 self.pdata["VCS"] = 'None'
2617 self.vcs = self.initVCS() 2617 self.vcs = self.initVCS()
2618 if self.vcs is not None: 2618 if self.vcs is not None:
2619 vcsdlg = self.vcs.vcsOptionsDialog(self, self.name) 2619 vcsdlg = self.vcs.vcsOptionsDialog(self, self.name)
2620 if vcsdlg.exec() == QDialog.Accepted: 2620 if vcsdlg.exec() == QDialog.DialogCode.Accepted:
2621 vcsDataDict = vcsdlg.getData() 2621 vcsDataDict = vcsdlg.getData()
2622 else: 2622 else:
2623 self.pdata["VCS"] = 'None' 2623 self.pdata["VCS"] = 'None'
2624 self.vcs = self.initVCS() 2624 self.vcs = self.initVCS()
2625 self.setDirty(True) 2625 self.setDirty(True)
2637 if vcores: 2637 if vcores:
2638 from VCS.CommandOptionsDialog import ( 2638 from VCS.CommandOptionsDialog import (
2639 VcsCommandOptionsDialog 2639 VcsCommandOptionsDialog
2640 ) 2640 )
2641 codlg = VcsCommandOptionsDialog(self.vcs) 2641 codlg = VcsCommandOptionsDialog(self.vcs)
2642 if codlg.exec() == QDialog.Accepted: 2642 if codlg.exec() == QDialog.DialogCode.Accepted:
2643 self.vcs.vcsSetOptions(codlg.getOptions()) 2643 self.vcs.vcsSetOptions(codlg.getOptions())
2644 2644
2645 # create the project in the VCS 2645 # create the project in the VCS
2646 self.vcs.vcsSetDataFromDict(vcsDataDict) 2646 self.vcs.vcsSetDataFromDict(vcsDataDict)
2647 self.saveProject() 2647 self.saveProject()
2712 self.tr("Translation Pattern"), 2712 self.tr("Translation Pattern"),
2713 self.tr( 2713 self.tr(
2714 "Enter the path pattern for translation files " 2714 "Enter the path pattern for translation files "
2715 "(use '%language%' in place of the language" 2715 "(use '%language%' in place of the language"
2716 " code):"), 2716 " code):"),
2717 QLineEdit.Normal, 2717 QLineEdit.EchoMode.Normal,
2718 tslist[0]) 2718 tslist[0])
2719 if pattern: 2719 if pattern:
2720 self.pdata["TRANSLATIONPATTERN"] = pattern 2720 self.pdata["TRANSLATIONPATTERN"] = pattern
2721 if self.pdata["TRANSLATIONPATTERN"]: 2721 if self.pdata["TRANSLATIONPATTERN"]:
2722 self.pdata["TRANSLATIONPATTERN"] = self.getRelativePath( 2722 self.pdata["TRANSLATIONPATTERN"] = self.getRelativePath(
2753 """ 2753 """
2754 Private slot to display the properties dialog. 2754 Private slot to display the properties dialog.
2755 """ 2755 """
2756 from .PropertiesDialog import PropertiesDialog 2756 from .PropertiesDialog import PropertiesDialog
2757 dlg = PropertiesDialog(self, False) 2757 dlg = PropertiesDialog(self, False)
2758 if dlg.exec() == QDialog.Accepted: 2758 if dlg.exec() == QDialog.DialogCode.Accepted:
2759 projectType = self.pdata["PROJECTTYPE"] 2759 projectType = self.pdata["PROJECTTYPE"]
2760 dlg.storeData() 2760 dlg.storeData()
2761 self.setDirty(True) 2761 self.setDirty(True)
2762 if self.pdata["MAINSCRIPT"]: 2762 if self.pdata["MAINSCRIPT"]:
2763 if not os.path.isabs(self.pdata["MAINSCRIPT"]): 2763 if not os.path.isabs(self.pdata["MAINSCRIPT"]):
2828 vcsSystem = self.pdata["VCS"] or None 2828 vcsSystem = self.pdata["VCS"] or None
2829 vcsSystemOverride = self.pudata["VCSOVERRIDE"] or None 2829 vcsSystemOverride = self.pudata["VCSOVERRIDE"] or None
2830 2830
2831 from .UserPropertiesDialog import UserPropertiesDialog 2831 from .UserPropertiesDialog import UserPropertiesDialog
2832 dlg = UserPropertiesDialog(self) 2832 dlg = UserPropertiesDialog(self)
2833 if dlg.exec() == QDialog.Accepted: 2833 if dlg.exec() == QDialog.DialogCode.Accepted:
2834 dlg.storeData() 2834 dlg.storeData()
2835 2835
2836 if ( 2836 if (
2837 (self.pdata["VCS"] and 2837 (self.pdata["VCS"] and
2838 self.pdata["VCS"] != vcsSystem) or 2838 self.pdata["VCS"] != vcsSystem) or
2873 """ 2873 """
2874 Private slot to display the filetype association dialog. 2874 Private slot to display the filetype association dialog.
2875 """ 2875 """
2876 from .FiletypeAssociationDialog import FiletypeAssociationDialog 2876 from .FiletypeAssociationDialog import FiletypeAssociationDialog
2877 dlg = FiletypeAssociationDialog(self) 2877 dlg = FiletypeAssociationDialog(self)
2878 if dlg.exec() == QDialog.Accepted: 2878 if dlg.exec() == QDialog.DialogCode.Accepted:
2879 dlg.transferData() 2879 dlg.transferData()
2880 self.setDirty(True) 2880 self.setDirty(True)
2881 self.__reorganizeFiles() 2881 self.__reorganizeFiles()
2882 2882
2883 def getFiletypeAssociations(self, associationType): 2883 def getFiletypeAssociations(self, associationType):
2899 """ 2899 """
2900 Private slot to display the lexer association dialog. 2900 Private slot to display the lexer association dialog.
2901 """ 2901 """
2902 from .LexerAssociationDialog import LexerAssociationDialog 2902 from .LexerAssociationDialog import LexerAssociationDialog
2903 dlg = LexerAssociationDialog(self) 2903 dlg = LexerAssociationDialog(self)
2904 if dlg.exec() == QDialog.Accepted: 2904 if dlg.exec() == QDialog.DialogCode.Accepted:
2905 dlg.transferData() 2905 dlg.transferData()
2906 self.setDirty(True) 2906 self.setDirty(True)
2907 self.lexerAssociationsChanged.emit() 2907 self.lexerAssociationsChanged.emit()
2908 2908
2909 def getEditorLexerAssoc(self, filename): 2909 def getEditorLexerAssoc(self, filename):
3692 """ 3692 """
3693 if self.pdata["EOL"] >= 0: 3693 if self.pdata["EOL"] >= 0:
3694 return self.eols[self.pdata["EOL"]] 3694 return self.eols[self.pdata["EOL"]]
3695 else: 3695 else:
3696 eolMode = Preferences.getEditor("EOLMode") 3696 eolMode = Preferences.getEditor("EOLMode")
3697 if eolMode == QsciScintilla.EolWindows: 3697 if eolMode == QsciScintilla.EolMode.EolWindows:
3698 eol = '\r\n' 3698 eol = '\r\n'
3699 elif eolMode == QsciScintilla.EolUnix: 3699 elif eolMode == QsciScintilla.EolMode.EolUnix:
3700 eol = '\n' 3700 eol = '\n'
3701 elif eolMode == QsciScintilla.EolMac: 3701 elif eolMode == QsciScintilla.EolMode.EolMac:
3702 eol = '\r' 3702 eol = '\r'
3703 else: 3703 else:
3704 eol = os.linesep 3704 eol = os.linesep
3705 return eol 3705 return eol
3706 3706
5380 elif len(pkglists) > 1: 5380 elif len(pkglists) > 1:
5381 dlg = E5ListSelectionDialog( 5381 dlg = E5ListSelectionDialog(
5382 sorted(pkglists), title=self.tr("Create Plugin Archive"), 5382 sorted(pkglists), title=self.tr("Create Plugin Archive"),
5383 message=self.tr("Select package lists:"), 5383 message=self.tr("Select package lists:"),
5384 checkBoxSelection=True) 5384 checkBoxSelection=True)
5385 if dlg.exec() == QDialog.Accepted: 5385 if dlg.exec() == QDialog.DialogCode.Accepted:
5386 selectedLists = [os.path.join(self.ppath, s) 5386 selectedLists = [os.path.join(self.ppath, s)
5387 for s in dlg.getSelection()] 5387 for s in dlg.getSelection()]
5388 else: 5388 else:
5389 return 5389 return
5390 5390
5772 @type bool 5772 @type bool
5773 @param interactive flag indicating an interactive invocation (i.e. 5773 @param interactive flag indicating an interactive invocation (i.e.
5774 through a menu action) 5774 through a menu action)
5775 @type bool 5775 @type bool
5776 """ 5776 """
5777 if exitStatus == QProcess.CrashExit: 5777 if exitStatus == QProcess.ExitStatus.CrashExit:
5778 E5MessageBox.critical( 5778 E5MessageBox.critical(
5779 self.ui, 5779 self.ui,
5780 self.tr("Execute Make"), 5780 self.tr("Execute Make"),
5781 self.tr("""The make process crashed.""")) 5781 self.tr("""The make process crashed."""))
5782 else: 5782 else:

eric ide

mercurial