Project/Project.py

changeset 5244
54a0f215a6f0
parent 5232
496d4857f690
child 5254
c89ecaa0eda3
equal deleted inserted replaced
5243:f6346f4b46c2 5244:54a0f215a6f0
28 QApplication, QMenu, QAction 28 QApplication, QMenu, QAction
29 from PyQt5.Qsci import QsciScintilla 29 from PyQt5.Qsci import QsciScintilla
30 30
31 from E5Gui.E5Application import e5App 31 from E5Gui.E5Application import e5App
32 from E5Gui import E5FileDialog, E5MessageBox 32 from E5Gui import E5FileDialog, E5MessageBox
33 from E5Gui.E5ListSelectionDialog import E5ListSelectionDialog
34 from E5Gui.E5ProgressDialog import E5ProgressDialog
33 35
34 from Globals import recentNameProject 36 from Globals import recentNameProject
35 37
36 import UI.PixmapCache 38 import UI.PixmapCache
37 39
3832 )) 3834 ))
3833 self.pluginPkgListAct.triggered.connect(self.__pluginCreatePkgList) 3835 self.pluginPkgListAct.triggered.connect(self.__pluginCreatePkgList)
3834 self.actions.append(self.pluginPkgListAct) 3836 self.actions.append(self.pluginPkgListAct)
3835 3837
3836 self.pluginArchiveAct = E5Action( 3838 self.pluginArchiveAct = E5Action(
3837 self.tr('Create Plugin Archive'), 3839 self.tr('Create Plugin Archives'),
3838 UI.PixmapCache.getIcon("pluginArchive.png"), 3840 UI.PixmapCache.getIcon("pluginArchive.png"),
3839 self.tr('Create Plugin &Archive'), 0, 0, 3841 self.tr('Create Plugin &Archives'), 0, 0,
3840 self.pluginGrp, 'project_plugin_archive') 3842 self.pluginGrp, 'project_plugin_archive')
3841 self.pluginArchiveAct.setStatusTip( 3843 self.pluginArchiveAct.setStatusTip(
3842 self.tr('Create an eric6 plugin archive file.')) 3844 self.tr('Create eric6 plugin archive files.'))
3843 self.pluginArchiveAct.setWhatsThis(self.tr( 3845 self.pluginArchiveAct.setWhatsThis(self.tr(
3844 """<b>Create Plugin Archive</b>""" 3846 """<b>Create Plugin Archives</b>"""
3845 """<p>This creates an eric6 plugin archive file using the list""" 3847 """<p>This creates eric6 plugin archive files using the list"""
3846 """ of files given in the PKGLIST file. The archive name is""" 3848 """ of files given in a PKGLIST* file. The archive name is"""
3847 """ built from the main script name.</p>""" 3849 """ built from the main script name if not designated in"""
3850 """ the package list file.</p>"""
3848 )) 3851 ))
3849 self.pluginArchiveAct.triggered.connect(self.__pluginCreateArchive) 3852 self.pluginArchiveAct.triggered.connect(self.__pluginCreateArchives)
3850 self.actions.append(self.pluginArchiveAct) 3853 self.actions.append(self.pluginArchiveAct)
3851 3854
3852 self.pluginSArchiveAct = E5Action( 3855 self.pluginSArchiveAct = E5Action(
3853 self.tr('Create Plugin Archive (Snapshot)'), 3856 self.tr('Create Plugin Archives (Snapshot)'),
3854 UI.PixmapCache.getIcon("pluginArchiveSnapshot.png"), 3857 UI.PixmapCache.getIcon("pluginArchiveSnapshot.png"),
3855 self.tr('Create Plugin Archive (&Snapshot)'), 0, 0, 3858 self.tr('Create Plugin Archives (&Snapshot)'), 0, 0,
3856 self.pluginGrp, 'project_plugin_sarchive') 3859 self.pluginGrp, 'project_plugin_sarchive')
3857 self.pluginSArchiveAct.setStatusTip(self.tr( 3860 self.pluginSArchiveAct.setStatusTip(self.tr(
3858 'Create an eric6 plugin archive file (snapshot release).')) 3861 'Create eric6 plugin archive files (snapshot releases).'))
3859 self.pluginSArchiveAct.setWhatsThis(self.tr( 3862 self.pluginSArchiveAct.setWhatsThis(self.tr(
3860 """<b>Create Plugin Archive (Snapshot)</b>""" 3863 """<b>Create Plugin Archives (Snapshot)</b>"""
3861 """<p>This creates an eric6 plugin archive file using the list""" 3864 """<p>This creates eric6 plugin archive files using the list"""
3862 """ of files given in the PKGLIST file. The archive name is""" 3865 """ of files given in the PKGLIST* file. The archive name is"""
3863 """ built from the main script name. The version entry of the""" 3866 """ built from the main script name if not designated in"""
3864 """ main script is modified to reflect a snapshot release.</p>""" 3867 """ the package list file. The version entry of the main script"""
3868 """ is modified to reflect a snapshot release.</p>"""
3865 )) 3869 ))
3866 self.pluginSArchiveAct.triggered.connect( 3870 self.pluginSArchiveAct.triggered.connect(
3867 self.__pluginCreateSnapshotArchive) 3871 self.__pluginCreateSnapshotArchives)
3868 self.actions.append(self.pluginSArchiveAct) 3872 self.actions.append(self.pluginSArchiveAct)
3869 3873
3870 self.closeAct.setEnabled(False) 3874 self.closeAct.setEnabled(False)
3871 self.saveAct.setEnabled(False) 3875 self.saveAct.setEnabled(False)
3872 self.saveasAct.setEnabled(False) 3876 self.saveasAct.setEnabled(False)
4768 4772
4769 if "PKGLIST" not in self.pdata["OTHERS"]: 4773 if "PKGLIST" not in self.pdata["OTHERS"]:
4770 self.appendFile("PKGLIST") 4774 self.appendFile("PKGLIST")
4771 4775
4772 @pyqtSlot() 4776 @pyqtSlot()
4773 def __pluginCreateArchive(self, snapshot=False): 4777 def __pluginCreateArchives(self, snapshot=False):
4774 """ 4778 """
4775 Private slot to create an eric6 plugin archive. 4779 Private slot to create eric6 plugin archives.
4776 4780
4777 @param snapshot flag indicating a snapshot archive (boolean) 4781 @param snapshot flag indicating snapshot archives (boolean)
4778 """ 4782 """
4779 pkglists = [os.path.basename(f) for f in
4780 glob.glob(os.path.join(self.ppath, "PKGLIST*"))]
4781 if len(pkglists) == 1:
4782 pkglist = os.path.join(self.ppath, pkglists[0])
4783 elif len(pkglists) > 1:
4784 pkglist, ok = QInputDialog.getItem(
4785 None,
4786 self.tr("Create Plugin Archive"),
4787 self.tr("Select a package list file:"),
4788 sorted(pkglists),
4789 0, False)
4790 if not ok or not pkglist:
4791 E5MessageBox.critical(
4792 self.ui,
4793 self.tr("Create Plugin Archive"),
4794 self.tr("""<p>No package list file selected. """
4795 """Aborting...</p>"""))
4796 return
4797 else:
4798 pkglist = os.path.join(self.ppath, pkglist)
4799 else:
4800 E5MessageBox.critical(
4801 self.ui,
4802 self.tr("Create Plugin Archive"),
4803 self.tr("""<p>The file <b>PKGLIST</b> does not exist. """
4804 """Aborting...</p>"""))
4805 return
4806
4807 if not self.pdata["MAINSCRIPT"]: 4783 if not self.pdata["MAINSCRIPT"]:
4808 E5MessageBox.critical( 4784 E5MessageBox.critical(
4809 self.ui, 4785 self.ui,
4810 self.tr("Create Plugin Archive"), 4786 self.tr("Create Plugin Archive"),
4811 self.tr( 4787 self.tr(
4812 """The project does not have a main script defined. """ 4788 """The project does not have a main script defined. """
4813 """Aborting...""")) 4789 """Aborting..."""))
4814 return 4790 return
4815 4791
4816 try: 4792 selectedLists = []
4817 pkglistFile = open(pkglist, "r", encoding="utf-8") 4793 pkglists = [os.path.basename(f) for f in
4818 names = pkglistFile.read() 4794 glob.glob(os.path.join(self.ppath, "PKGLIST*"))]
4819 pkglistFile.close() 4795 if len(pkglists) == 1:
4820 except IOError as why: 4796 selectedLists = [os.path.join(self.ppath, pkglists[0])]
4797 elif len(pkglists) > 1:
4798 dlg = E5ListSelectionDialog(
4799 sorted(pkglists), title=self.tr("Create Plugin Archive"),
4800 message=self.tr("Select package lists:"))
4801 if dlg.exec_() == QDialog.Accepted:
4802 selectedLists = [os.path.join(self.ppath, s)
4803 for s in dlg.getSelection()]
4804 else:
4805 return
4806
4807 if not selectedLists:
4821 E5MessageBox.critical( 4808 E5MessageBox.critical(
4822 self.ui, 4809 self.ui,
4823 self.tr("Create Plugin Archive"), 4810 self.tr("Create Plugin Archive"),
4824 self.tr( 4811 self.tr("""<p>No package list files (PKGLIST*) available or"""
4825 """<p>The file <b>PKGLIST</b> could not be read.</p>""" 4812 """ selected. Aborting...</p>"""))
4826 """<p>Reason: {0}</p>""").format(str(why)))
4827 return 4813 return
4828 4814
4829 lines = names.splitlines() 4815 progress = E5ProgressDialog(
4830 archiveName = "" 4816 self.tr("Creating plugin archives..."), self.tr("Abort"),
4831 names = [] 4817 0, len(selectedLists), self.tr("%v/%m Archives"))
4832 for line in lines: 4818 progress.setMinimumDuration(0)
4833 if line.startswith(";"): 4819 progress.setWindowTitle(self.tr("Create Plugin Archives"))
4834 # it's a comment possibly containing a directive 4820 count = 0
4835 # supported directives are: 4821 errors = 0
4836 # - archive_name= defines the name of the archive 4822 for pkglist in selectedLists:
4837 if line[1:].strip().startswith("archive_name="): 4823 progress.setValue(count)
4838 archiveName = line[1:].split("=")[1] 4824 if progress.wasCanceled():
4825 break
4826
4827 try:
4828 pkglistFile = open(pkglist, "r", encoding="utf-8")
4829 names = pkglistFile.read()
4830 pkglistFile.close()
4831 except IOError as why:
4832 E5MessageBox.critical(
4833 self.ui,
4834 self.tr("Create Plugin Archive"),
4835 self.tr(
4836 """<p>The file <b>{0}</b> could not be read.</p>"""
4837 """<p>Reason: {1}</p>""").format(
4838 os.path.basename(pkglist), str(why)))
4839 errors += 1
4840 count += 1
4841 continue
4842
4843 lines = names.splitlines()
4844 archiveName = ""
4845 names = []
4846 for line in lines:
4847 if line.startswith(";"):
4848 # it's a comment possibly containing a directive
4849 # supported directives are:
4850 # - archive_name= defines the name of the archive
4851 if line[1:].strip().startswith("archive_name="):
4852 archiveName = line[1:].split("=")[1]
4853 else:
4854 names.append(line)
4855 names = sorted(names)
4856 if archiveName:
4857 archive = os.path.join(self.ppath, archiveName)
4839 else: 4858 else:
4840 names.append(line) 4859 archive = os.path.join(
4841 names = sorted(names) 4860 self.ppath,
4842 if archiveName: 4861 self.pdata["MAINSCRIPT"].replace(".py", ".zip"))
4843 archive = os.path.join(self.ppath, archiveName) 4862 try:
4863 archiveFile = zipfile.ZipFile(archive, "w")
4864 except IOError as why:
4865 E5MessageBox.critical(
4866 self.ui,
4867 self.tr("Create Plugin Archive"),
4868 self.tr(
4869 """<p>The eric6 plugin archive file <b>{0}</b>"""
4870 """ could not be created.</p>"""
4871 """<p>Reason: {1}</p>""").format(archive, str(why)))
4872 errors += 1
4873 count += 1
4874 continue
4875
4876 for name in names:
4877 if name:
4878 try:
4879 self.__createZipDirEntries(
4880 os.path.split(name)[0], archiveFile)
4881 if snapshot and name == self.pdata["MAINSCRIPT"]:
4882 snapshotSource, version = \
4883 self.__createSnapshotSource(
4884 os.path.join(self.ppath,
4885 self.pdata["MAINSCRIPT"]))
4886 archiveFile.writestr(name, snapshotSource)
4887 else:
4888 archiveFile.write(os.path.join(self.ppath, name),
4889 name)
4890 if name == self.pdata["MAINSCRIPT"]:
4891 version = self.__pluginExtractVersion(
4892 os.path.join(self.ppath,
4893 self.pdata["MAINSCRIPT"]))
4894 except OSError as why:
4895 E5MessageBox.critical(
4896 self.ui,
4897 self.tr("Create Plugin Archive"),
4898 self.tr(
4899 """<p>The file <b>{0}</b> could not be"""
4900 """ stored in the archive. Ignoring it.</p>"""
4901 """<p>Reason: {1}</p>""")
4902 .format(os.path.join(self.ppath, name), str(why)))
4903 archiveFile.writestr("VERSION", version.encode("utf-8"))
4904 archiveFile.close()
4905
4906 if archive not in self.pdata["OTHERS"]:
4907 self.appendFile(archive)
4908
4909 count += 1
4910
4911 progress.setValue(len(selectedLists))
4912
4913 if errors:
4914 message = self.tr("<p>The eric6 plugin archive files were "
4915 "created with some errors.</p>")
4844 else: 4916 else:
4845 archive = os.path.join( 4917 message = self.tr("<p>The eric6 plugin archive files were "
4846 self.ppath, self.pdata["MAINSCRIPT"].replace(".py", ".zip")) 4918 "created successfully.</p>")
4847 try:
4848 archiveFile = zipfile.ZipFile(archive, "w")
4849 except IOError as why:
4850 E5MessageBox.critical(
4851 self.ui,
4852 self.tr("Create Plugin Archive"),
4853 self.tr(
4854 """<p>The eric6 plugin archive file <b>{0}</b> could """
4855 """not be created.</p>"""
4856 """<p>Reason: {1}</p>""").format(archive, str(why)))
4857 return
4858
4859 for name in names:
4860 if name:
4861 try:
4862 self.__createZipDirEntries(
4863 os.path.split(name)[0], archiveFile)
4864 if snapshot and name == self.pdata["MAINSCRIPT"]:
4865 snapshotSource, version = self.__createSnapshotSource(
4866 os.path.join(self.ppath,
4867 self.pdata["MAINSCRIPT"]))
4868 archiveFile.writestr(name, snapshotSource)
4869 else:
4870 archiveFile.write(os.path.join(self.ppath, name), name)
4871 if name == self.pdata["MAINSCRIPT"]:
4872 version = self.__pluginExtractVersion(
4873 os.path.join(self.ppath,
4874 self.pdata["MAINSCRIPT"]))
4875 except OSError as why:
4876 E5MessageBox.critical(
4877 self.ui,
4878 self.tr("Create Plugin Archive"),
4879 self.tr(
4880 """<p>The file <b>{0}</b> could not be stored """
4881 """in the archive. Ignoring it.</p>"""
4882 """<p>Reason: {1}</p>""")
4883 .format(os.path.join(self.ppath, name), str(why)))
4884 archiveFile.writestr("VERSION", version.encode("utf-8"))
4885 archiveFile.close()
4886
4887 if archive not in self.pdata["OTHERS"]:
4888 self.appendFile(archive)
4889
4890 if self.ui.notificationsEnabled(): 4919 if self.ui.notificationsEnabled():
4891 self.ui.showNotification( 4920 self.ui.showNotification(
4892 UI.PixmapCache.getPixmap("pluginArchive48.png"), 4921 UI.PixmapCache.getPixmap("pluginArchive48.png"),
4893 self.tr("Create Plugin Archive"), 4922 self.tr("Create Plugin Archive"),
4894 self.tr( 4923 message)
4895 """<p>The eric6 plugin archive file <b>{0}</b> was """
4896 """created successfully.</p>""")
4897 .format(os.path.basename(archive)))
4898 else: 4924 else:
4899 E5MessageBox.information( 4925 E5MessageBox.information(
4900 self.ui, 4926 self.ui,
4901 self.tr("Create Plugin Archive"), 4927 self.tr("Create Plugin Archive"),
4902 self.tr( 4928 message)
4903 """<p>The eric6 plugin archive file <b>{0}</b> was """
4904 """created successfully.</p>""").format(archive))
4905 4929
4906 def __pluginCreateSnapshotArchive(self): 4930 def __pluginCreateSnapshotArchives(self):
4907 """ 4931 """
4908 Private slot to create an eric6 plugin archive snapshot release. 4932 Private slot to create eric6 plugin archive snapshot releases.
4909 """ 4933 """
4910 self.__pluginCreateArchive(True) 4934 self.__pluginCreateArchives(True)
4911 4935
4912 def __createZipDirEntries(self, path, zipFile): 4936 def __createZipDirEntries(self, path, zipFile):
4913 """ 4937 """
4914 Private method to create dir entries in the zip file. 4938 Private method to create dir entries in the zip file.
4915 4939

eric ide

mercurial