PluginManager/PluginRepositoryDialog.py

changeset 5739
a870f5f03baa
parent 5588
6ba512d9f46a
child 5755
83fe98028532
--- a/PluginManager/PluginRepositoryDialog.py	Sat May 13 18:19:06 2017 +0200
+++ b/PluginManager/PluginRepositoryDialog.py	Mon May 15 18:36:49 2017 +0200
@@ -16,7 +16,7 @@
 import glob
 
 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QFile, QIODevice, QUrl, \
-    QProcess, QPoint
+    QProcess, QPoint, QCoreApplication
 from PyQt5.QtWidgets import QWidget, QDialogButtonBox, QAbstractButton, \
     QTreeWidgetItem, QDialog, QVBoxLayout, QMenu
 from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest, \
@@ -749,39 +749,7 @@
         """
         Private slot to cleanup the plug-in downloads area.
         """
-        downloadPath = Preferences.getPluginManager("DownloadPath")
-        downloads = {}  # plug-in name as key, file name as value
-        
-        # step 1: extract plug-ins and downloaded files
-        for pluginFile in os.listdir(downloadPath):
-            if not os.path.isfile(os.path.join(downloadPath, pluginFile)):
-                continue
-            
-            pluginName = pluginFile.rsplit("-", 1)[0]
-            if pluginName not in downloads:
-                downloads[pluginName] = []
-            downloads[pluginName].append(pluginFile)
-        
-        # step 2: delete old entries
-        for pluginName in downloads:
-            downloads[pluginName].sort()
-        
-            if pluginName in self.__hiddenPlugins and \
-                    not Preferences.getPluginManager("KeepHidden"):
-                removeFiles = downloads[pluginName]
-            else:
-                removeFiles = downloads[pluginName][
-                    :-Preferences.getPluginManager("KeepGenerations")]
-            for removeFile in removeFiles:
-                try:
-                    os.remove(os.path.join(downloadPath, removeFile))
-                except (IOError, OSError) as err:
-                    E5MessageBox.critical(
-                        self,
-                        self.tr("Cleanup of Plugin Downloads"),
-                        self.tr("""<p>The plugin download <b>{0}</b> could"""
-                                """ not be deleted.</p><p>Reason: {1}</p>""")
-                        .format(removeFile, str(err)))
+        PluginRepositoryDownloadCleanup()
 
 
 class PluginRepositoryDialog(QDialog):
@@ -873,3 +841,51 @@
                 self.tr('OK'))
         
         self.close()
+
+
+def PluginRepositoryDownloadCleanup(quiet=False):
+    """
+    Module function to clean up the plug-in downloads area.
+    
+    @param quiet flag indicating quiet operations
+    @type bool
+    """
+    downloadPath = Preferences.getPluginManager("DownloadPath")
+    downloads = {}  # plug-in name as key, file name as value
+    
+    # step 1: extract plug-ins and downloaded files
+    for pluginFile in os.listdir(downloadPath):
+        if not os.path.isfile(os.path.join(downloadPath, pluginFile)):
+            continue
+        
+        pluginName = pluginFile.rsplit("-", 1)[0]
+        if pluginName not in downloads:
+            downloads[pluginName] = []
+        downloads[pluginName].append(pluginFile)
+    
+    # step 2: delete old entries
+    hiddenPlugins = Preferences.getPluginManager("HiddenPlugins")
+    for pluginName in downloads:
+        downloads[pluginName].sort()
+    
+        if pluginName in hiddenPlugins and \
+                not Preferences.getPluginManager("KeepHidden"):
+            removeFiles = downloads[pluginName]
+        else:
+            removeFiles = downloads[pluginName][
+                :-Preferences.getPluginManager("KeepGenerations")]
+        for removeFile in removeFiles:
+            try:
+                os.remove(os.path.join(downloadPath, removeFile))
+            except (IOError, OSError) as err:
+                if not quiet:
+                    E5MessageBox.critical(
+                        None,
+                        QCoreApplication.translate(
+                            "PluginRepositoryWidget",
+                            "Cleanup of Plugin Downloads"),
+                        QCoreApplication.translate(
+                            "PluginRepositoryWidget",
+                            """<p>The plugin download <b>{0}</b> could"""
+                            """ not be deleted.</p><p>Reason: {1}</p>""")
+                        .format(removeFile, str(err)))

eric ide

mercurial