Project/Project.py

changeset 5244
54a0f215a6f0
parent 5232
496d4857f690
child 5254
c89ecaa0eda3
--- a/Project/Project.py	Sun Oct 16 12:20:30 2016 +0200
+++ b/Project/Project.py	Sun Oct 16 14:42:46 2016 +0200
@@ -30,6 +30,8 @@
 
 from E5Gui.E5Application import e5App
 from E5Gui import E5FileDialog, E5MessageBox
+from E5Gui.E5ListSelectionDialog import E5ListSelectionDialog
+from E5Gui.E5ProgressDialog import E5ProgressDialog
 
 from Globals import recentNameProject
 
@@ -3834,37 +3836,39 @@
         self.actions.append(self.pluginPkgListAct)
 
         self.pluginArchiveAct = E5Action(
-            self.tr('Create Plugin Archive'),
+            self.tr('Create Plugin Archives'),
             UI.PixmapCache.getIcon("pluginArchive.png"),
-            self.tr('Create Plugin &Archive'), 0, 0,
+            self.tr('Create Plugin &Archives'), 0, 0,
             self.pluginGrp, 'project_plugin_archive')
         self.pluginArchiveAct.setStatusTip(
-            self.tr('Create an eric6 plugin archive file.'))
+            self.tr('Create eric6 plugin archive files.'))
         self.pluginArchiveAct.setWhatsThis(self.tr(
-            """<b>Create Plugin Archive</b>"""
-            """<p>This creates an eric6 plugin archive file using the list"""
-            """ of files given in the PKGLIST file. The archive name is"""
-            """ built from the main script name.</p>"""
+            """<b>Create Plugin Archives</b>"""
+            """<p>This creates eric6 plugin archive files using the list"""
+            """ of files given in a PKGLIST* file. The archive name is"""
+            """ built from the main script name if not designated in"""
+            """ the package list file.</p>"""
         ))
-        self.pluginArchiveAct.triggered.connect(self.__pluginCreateArchive)
+        self.pluginArchiveAct.triggered.connect(self.__pluginCreateArchives)
         self.actions.append(self.pluginArchiveAct)
     
         self.pluginSArchiveAct = E5Action(
-            self.tr('Create Plugin Archive (Snapshot)'),
+            self.tr('Create Plugin Archives (Snapshot)'),
             UI.PixmapCache.getIcon("pluginArchiveSnapshot.png"),
-            self.tr('Create Plugin Archive (&Snapshot)'), 0, 0,
+            self.tr('Create Plugin Archives (&Snapshot)'), 0, 0,
             self.pluginGrp, 'project_plugin_sarchive')
         self.pluginSArchiveAct.setStatusTip(self.tr(
-            'Create an eric6 plugin archive file (snapshot release).'))
+            'Create eric6 plugin archive files (snapshot releases).'))
         self.pluginSArchiveAct.setWhatsThis(self.tr(
-            """<b>Create Plugin Archive (Snapshot)</b>"""
-            """<p>This creates an eric6 plugin archive file using the list"""
-            """ of files given in the PKGLIST file. The archive name is"""
-            """ built from the main script name. The version entry of the"""
-            """ main script is modified to reflect a snapshot release.</p>"""
+            """<b>Create Plugin Archives (Snapshot)</b>"""
+            """<p>This creates eric6 plugin archive files using the list"""
+            """ of files given in the PKGLIST* file. The archive name is"""
+            """ built from the main script name if not designated in"""
+            """ the package list file. The version entry of the main script"""
+            """ is modified to reflect a snapshot release.</p>"""
         ))
         self.pluginSArchiveAct.triggered.connect(
-            self.__pluginCreateSnapshotArchive)
+            self.__pluginCreateSnapshotArchives)
         self.actions.append(self.pluginSArchiveAct)
 
         self.closeAct.setEnabled(False)
@@ -4770,40 +4774,12 @@
             self.appendFile("PKGLIST")
         
     @pyqtSlot()
-    def __pluginCreateArchive(self, snapshot=False):
-        """
-        Private slot to create an eric6 plugin archive.
-        
-        @param snapshot flag indicating a snapshot archive (boolean)
-        """
-        pkglists = [os.path.basename(f) for f in
-                    glob.glob(os.path.join(self.ppath, "PKGLIST*"))]
-        if len(pkglists) == 1:
-            pkglist = os.path.join(self.ppath, pkglists[0])
-        elif len(pkglists) > 1:
-            pkglist, ok = QInputDialog.getItem(
-                None,
-                self.tr("Create Plugin Archive"),
-                self.tr("Select a package list file:"),
-                sorted(pkglists),
-                0, False)
-            if not ok or not pkglist:
-                E5MessageBox.critical(
-                    self.ui,
-                    self.tr("Create Plugin Archive"),
-                    self.tr("""<p>No package list file selected. """
-                            """Aborting...</p>"""))
-                return
-            else:
-                pkglist = os.path.join(self.ppath, pkglist)
-        else:
-            E5MessageBox.critical(
-                self.ui,
-                self.tr("Create Plugin Archive"),
-                self.tr("""<p>The file <b>PKGLIST</b> does not exist. """
-                        """Aborting...</p>"""))
-            return
-        
+    def __pluginCreateArchives(self, snapshot=False):
+        """
+        Private slot to create eric6 plugin archives.
+        
+        @param snapshot flag indicating snapshot archives (boolean)
+        """
         if not self.pdata["MAINSCRIPT"]:
             E5MessageBox.critical(
                 self.ui,
@@ -4813,101 +4789,149 @@
                     """Aborting..."""))
             return
         
-        try:
-            pkglistFile = open(pkglist, "r", encoding="utf-8")
-            names = pkglistFile.read()
-            pkglistFile.close()
-        except IOError as why:
-            E5MessageBox.critical(
-                self.ui,
-                self.tr("Create Plugin Archive"),
-                self.tr(
-                    """<p>The file <b>PKGLIST</b> could not be read.</p>"""
-                    """<p>Reason: {0}</p>""").format(str(why)))
-            return
-        
-        lines = names.splitlines()
-        archiveName = ""
-        names = []
-        for line in lines:
-            if line.startswith(";"):
-                # it's a comment possibly containing a directive
-                # supported directives are:
-                # - archive_name= defines the name of the archive
-                if line[1:].strip().startswith("archive_name="):
-                    archiveName = line[1:].split("=")[1]
+        selectedLists = []
+        pkglists = [os.path.basename(f) for f in
+                    glob.glob(os.path.join(self.ppath, "PKGLIST*"))]
+        if len(pkglists) == 1:
+            selectedLists = [os.path.join(self.ppath, pkglists[0])]
+        elif len(pkglists) > 1:
+            dlg = E5ListSelectionDialog(
+                sorted(pkglists), title=self.tr("Create Plugin Archive"),
+                message=self.tr("Select package lists:"))
+            if dlg.exec_() == QDialog.Accepted:
+                selectedLists = [os.path.join(self.ppath, s)
+                                 for s in dlg.getSelection()]
             else:
-                names.append(line)
-        names = sorted(names)
-        if archiveName:
-            archive = os.path.join(self.ppath, archiveName)
-        else:
-            archive = os.path.join(
-                self.ppath, self.pdata["MAINSCRIPT"].replace(".py", ".zip"))
-        try:
-            archiveFile = zipfile.ZipFile(archive, "w")
-        except IOError as why:
+                return
+        
+        if not selectedLists:
             E5MessageBox.critical(
                 self.ui,
                 self.tr("Create Plugin Archive"),
-                self.tr(
-                    """<p>The eric6 plugin archive file <b>{0}</b> could """
-                    """not be created.</p>"""
-                    """<p>Reason: {1}</p>""").format(archive, str(why)))
+                self.tr("""<p>No package list files (PKGLIST*) available or"""
+                        """ selected. Aborting...</p>"""))
             return
         
-        for name in names:
-            if name:
-                try:
-                    self.__createZipDirEntries(
-                        os.path.split(name)[0], archiveFile)
-                    if snapshot and name == self.pdata["MAINSCRIPT"]:
-                        snapshotSource, version = self.__createSnapshotSource(
-                            os.path.join(self.ppath,
-                                         self.pdata["MAINSCRIPT"]))
-                        archiveFile.writestr(name, snapshotSource)
-                    else:
-                        archiveFile.write(os.path.join(self.ppath, name), name)
-                        if name == self.pdata["MAINSCRIPT"]:
-                            version = self.__pluginExtractVersion(
-                                os.path.join(self.ppath,
-                                             self.pdata["MAINSCRIPT"]))
-                except OSError as why:
-                    E5MessageBox.critical(
-                        self.ui,
-                        self.tr("Create Plugin Archive"),
-                        self.tr(
-                            """<p>The file <b>{0}</b> could not be stored """
-                            """in the archive. Ignoring it.</p>"""
-                            """<p>Reason: {1}</p>""")
-                        .format(os.path.join(self.ppath, name), str(why)))
-        archiveFile.writestr("VERSION", version.encode("utf-8"))
-        archiveFile.close()
-        
-        if archive not in self.pdata["OTHERS"]:
-            self.appendFile(archive)
-        
+        progress = E5ProgressDialog(
+            self.tr("Creating plugin archives..."), self.tr("Abort"),
+            0, len(selectedLists), self.tr("%v/%m Archives"))
+        progress.setMinimumDuration(0)
+        progress.setWindowTitle(self.tr("Create Plugin Archives"))
+        count = 0
+        errors = 0
+        for pkglist in selectedLists:
+            progress.setValue(count)
+            if progress.wasCanceled():
+                break
+            
+            try:
+                pkglistFile = open(pkglist, "r", encoding="utf-8")
+                names = pkglistFile.read()
+                pkglistFile.close()
+            except IOError as why:
+                E5MessageBox.critical(
+                    self.ui,
+                    self.tr("Create Plugin Archive"),
+                    self.tr(
+                        """<p>The file <b>{0}</b> could not be read.</p>"""
+                        """<p>Reason: {1}</p>""").format(
+                        os.path.basename(pkglist), str(why)))
+                errors += 1
+                count += 1
+                continue
+            
+            lines = names.splitlines()
+            archiveName = ""
+            names = []
+            for line in lines:
+                if line.startswith(";"):
+                    # it's a comment possibly containing a directive
+                    # supported directives are:
+                    # - archive_name= defines the name of the archive
+                    if line[1:].strip().startswith("archive_name="):
+                        archiveName = line[1:].split("=")[1]
+                else:
+                    names.append(line)
+            names = sorted(names)
+            if archiveName:
+                archive = os.path.join(self.ppath, archiveName)
+            else:
+                archive = os.path.join(
+                    self.ppath,
+                    self.pdata["MAINSCRIPT"].replace(".py", ".zip"))
+            try:
+                archiveFile = zipfile.ZipFile(archive, "w")
+            except IOError as why:
+                E5MessageBox.critical(
+                    self.ui,
+                    self.tr("Create Plugin Archive"),
+                    self.tr(
+                        """<p>The eric6 plugin archive file <b>{0}</b>"""
+                        """ could not be created.</p>"""
+                        """<p>Reason: {1}</p>""").format(archive, str(why)))
+                errors += 1
+                count += 1
+                continue
+            
+            for name in names:
+                if name:
+                    try:
+                        self.__createZipDirEntries(
+                            os.path.split(name)[0], archiveFile)
+                        if snapshot and name == self.pdata["MAINSCRIPT"]:
+                            snapshotSource, version = \
+                                self.__createSnapshotSource(
+                                    os.path.join(self.ppath,
+                                                 self.pdata["MAINSCRIPT"]))
+                            archiveFile.writestr(name, snapshotSource)
+                        else:
+                            archiveFile.write(os.path.join(self.ppath, name),
+                                              name)
+                            if name == self.pdata["MAINSCRIPT"]:
+                                version = self.__pluginExtractVersion(
+                                    os.path.join(self.ppath,
+                                                 self.pdata["MAINSCRIPT"]))
+                    except OSError as why:
+                        E5MessageBox.critical(
+                            self.ui,
+                            self.tr("Create Plugin Archive"),
+                            self.tr(
+                                """<p>The file <b>{0}</b> could not be"""
+                                """ stored in the archive. Ignoring it.</p>"""
+                                """<p>Reason: {1}</p>""")
+                            .format(os.path.join(self.ppath, name), str(why)))
+            archiveFile.writestr("VERSION", version.encode("utf-8"))
+            archiveFile.close()
+            
+            if archive not in self.pdata["OTHERS"]:
+                self.appendFile(archive)
+            
+            count += 1
+        
+        progress.setValue(len(selectedLists))
+        
+        if errors:
+            message = self.tr("<p>The eric6 plugin archive files were "
+                              "created with some errors.</p>")
+        else:
+            message = self.tr("<p>The eric6 plugin archive files were "
+                              "created successfully.</p>")
         if self.ui.notificationsEnabled():
             self.ui.showNotification(
                 UI.PixmapCache.getPixmap("pluginArchive48.png"),
                 self.tr("Create Plugin Archive"),
-                self.tr(
-                    """<p>The eric6 plugin archive file <b>{0}</b> was """
-                    """created successfully.</p>""")
-                .format(os.path.basename(archive)))
+                message)
         else:
             E5MessageBox.information(
                 self.ui,
                 self.tr("Create Plugin Archive"),
-                self.tr(
-                    """<p>The eric6 plugin archive file <b>{0}</b> was """
-                    """created successfully.</p>""").format(archive))
+                message)
     
-    def __pluginCreateSnapshotArchive(self):
-        """
-        Private slot to create an eric6 plugin archive snapshot release.
-        """
-        self.__pluginCreateArchive(True)
+    def __pluginCreateSnapshotArchives(self):
+        """
+        Private slot to create eric6 plugin archive snapshot releases.
+        """
+        self.__pluginCreateArchives(True)
     
     def __createZipDirEntries(self, path, zipFile):
         """

eric ide

mercurial