PluginManager/PluginRepositoryDialog.py

branch
maintenance
changeset 6646
51eefa621de4
parent 6645
ad476851d7e0
--- a/PluginManager/PluginRepositoryDialog.py	Sat Dec 01 11:45:24 2018 +0100
+++ b/PluginManager/PluginRepositoryDialog.py	Thu Jan 10 14:22:59 2019 +0100
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 
-# Copyright (c) 2007 - 2018 Detlev Offenbach <detlev@die-offenbachs.de>
+# Copyright (c) 2007 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
 #
 
 
@@ -657,7 +657,8 @@
             # Check against installed/loaded plug-ins
             pluginName = filename.rsplit('-', 1)[0]
             pluginDetails = self.__pluginManager.getPluginDetails(pluginName)
-            if pluginDetails is None:
+            if pluginDetails is None or \
+                    pluginDetails["moduleName"] != pluginName:
                 return PluginRepositoryWidget.PluginStatusNew
             pluginVersionTuple = Globals.versionToTuple(
                 pluginDetails["version"])[:3]
@@ -893,6 +894,26 @@
     @param quiet flag indicating quiet operations
     @type bool
     """
+    pluginsRegister = []    # list of plug-ins contained in the repository
+    
+    def registerPlugin(name, short, description, url, author, version,
+                       filename, status):
+        """
+        Method to register a plug-in's data.
+        
+        @param name data for the name field (string)
+        @param short data for the short field (string)
+        @param description data for the description field (list of strings)
+        @param url data for the url field (string)
+        @param author data for the author field (string)
+        @param version data for the version field (string)
+        @param filename data for the filename field (string)
+        @param status status of the plugin (string [stable, unstable, unknown])
+        """
+        pluginName = os.path.splitext(url.rsplit("/", 1)[1])[0]
+        if pluginName not in pluginsRegister:
+            pluginsRegister.append(pluginName)
+    
     downloadPath = Preferences.getPluginManager("DownloadPath")
     downloads = {}  # plug-in name as key, file name as value
     
@@ -948,3 +969,33 @@
                             """<p>The plugin download <b>{0}</b> could"""
                             """ not be deleted.</p><p>Reason: {1}</p>""")
                         .format(removeFile, str(err)))
+    
+    # step 3: delete entries of obsolete plug-ins
+    pluginRepositoryFile = os.path.join(Utilities.getConfigDir(),
+                                        "PluginRepository")
+    if os.path.exists(pluginRepositoryFile):
+        f = QFile(pluginRepositoryFile)
+        if f.open(QIODevice.ReadOnly):
+            from E5XML.PluginRepositoryReader import PluginRepositoryReader
+            reader = PluginRepositoryReader(f, registerPlugin)
+            reader.readXML()
+            
+            for pluginName in downloads:
+                if pluginName not in pluginsRegister:
+                    removeFiles = [f[0] for f in downloads[pluginName]]
+                    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