PluginManager/PluginRepositoryDialog.py

branch
maintenance
changeset 6646
51eefa621de4
parent 6645
ad476851d7e0
equal deleted inserted replaced
6603:77189681b787 6646:51eefa621de4
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 # Copyright (c) 2007 - 2018 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2007 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 6
7 """ 7 """
8 Module implementing a dialog showing the available plugins. 8 Module implementing a dialog showing the available plugins.
655 archivesPattern = archive.rsplit('-', 1)[0] + "-*.zip" 655 archivesPattern = archive.rsplit('-', 1)[0] + "-*.zip"
656 if len(glob.glob(archivesPattern)) == 0: 656 if len(glob.glob(archivesPattern)) == 0:
657 # Check against installed/loaded plug-ins 657 # Check against installed/loaded plug-ins
658 pluginName = filename.rsplit('-', 1)[0] 658 pluginName = filename.rsplit('-', 1)[0]
659 pluginDetails = self.__pluginManager.getPluginDetails(pluginName) 659 pluginDetails = self.__pluginManager.getPluginDetails(pluginName)
660 if pluginDetails is None: 660 if pluginDetails is None or \
661 pluginDetails["moduleName"] != pluginName:
661 return PluginRepositoryWidget.PluginStatusNew 662 return PluginRepositoryWidget.PluginStatusNew
662 pluginVersionTuple = Globals.versionToTuple( 663 pluginVersionTuple = Globals.versionToTuple(
663 pluginDetails["version"])[:3] 664 pluginDetails["version"])[:3]
664 versionTuple = Globals.versionToTuple(version)[:3] 665 versionTuple = Globals.versionToTuple(version)[:3]
665 if pluginVersionTuple < versionTuple: 666 if pluginVersionTuple < versionTuple:
891 Module function to clean up the plug-in downloads area. 892 Module function to clean up the plug-in downloads area.
892 893
893 @param quiet flag indicating quiet operations 894 @param quiet flag indicating quiet operations
894 @type bool 895 @type bool
895 """ 896 """
897 pluginsRegister = [] # list of plug-ins contained in the repository
898
899 def registerPlugin(name, short, description, url, author, version,
900 filename, status):
901 """
902 Method to register a plug-in's data.
903
904 @param name data for the name field (string)
905 @param short data for the short field (string)
906 @param description data for the description field (list of strings)
907 @param url data for the url field (string)
908 @param author data for the author field (string)
909 @param version data for the version field (string)
910 @param filename data for the filename field (string)
911 @param status status of the plugin (string [stable, unstable, unknown])
912 """
913 pluginName = os.path.splitext(url.rsplit("/", 1)[1])[0]
914 if pluginName not in pluginsRegister:
915 pluginsRegister.append(pluginName)
916
896 downloadPath = Preferences.getPluginManager("DownloadPath") 917 downloadPath = Preferences.getPluginManager("DownloadPath")
897 downloads = {} # plug-in name as key, file name as value 918 downloads = {} # plug-in name as key, file name as value
898 919
899 # step 1: extract plug-ins and downloaded files 920 # step 1: extract plug-ins and downloaded files
900 for pluginFile in os.listdir(downloadPath): 921 for pluginFile in os.listdir(downloadPath):
946 QCoreApplication.translate( 967 QCoreApplication.translate(
947 "PluginRepositoryWidget", 968 "PluginRepositoryWidget",
948 """<p>The plugin download <b>{0}</b> could""" 969 """<p>The plugin download <b>{0}</b> could"""
949 """ not be deleted.</p><p>Reason: {1}</p>""") 970 """ not be deleted.</p><p>Reason: {1}</p>""")
950 .format(removeFile, str(err))) 971 .format(removeFile, str(err)))
972
973 # step 3: delete entries of obsolete plug-ins
974 pluginRepositoryFile = os.path.join(Utilities.getConfigDir(),
975 "PluginRepository")
976 if os.path.exists(pluginRepositoryFile):
977 f = QFile(pluginRepositoryFile)
978 if f.open(QIODevice.ReadOnly):
979 from E5XML.PluginRepositoryReader import PluginRepositoryReader
980 reader = PluginRepositoryReader(f, registerPlugin)
981 reader.readXML()
982
983 for pluginName in downloads:
984 if pluginName not in pluginsRegister:
985 removeFiles = [f[0] for f in downloads[pluginName]]
986 for removeFile in removeFiles:
987 try:
988 os.remove(os.path.join(downloadPath, removeFile))
989 except (IOError, OSError) as err:
990 if not quiet:
991 E5MessageBox.critical(
992 None,
993 QCoreApplication.translate(
994 "PluginRepositoryWidget",
995 "Cleanup of Plugin Downloads"),
996 QCoreApplication.translate(
997 "PluginRepositoryWidget",
998 "<p>The plugin download <b>{0}</b>"
999 " could not be deleted.</p>"
1000 "<p>Reason: {1}</p>""")
1001 .format(removeFile, str(err)))

eric ide

mercurial