def __populateList(self): """ Private method to populate the list of available plugins. """ self.repositoryList.clear() self.__stableItem = None self.__unstableItem = None self.__unknownItem = None self.__obsoleteItem = None self.__newItems = 0 self.__updateLocalItems = 0 self.__updateRemoteItems = 0 self.downloadProgress.setValue(0) if os.path.exists(self.pluginRepositoryFile): self.__repositoryMissing = False f = QFile(self.pluginRepositoryFile) if f.open(QIODevice.ReadOnly): from E5XML.PluginRepositoryReader import PluginRepositoryReader reader = PluginRepositoryReader(f, self.addEntry) reader.readXML() self.repositoryList.resizeColumnToContents(0) self.repositoryList.resizeColumnToContents(1) self.repositoryList.resizeColumnToContents(2) self.__resortRepositoryList() url = Preferences.getUI("PluginRepositoryUrl6") if url != self.repositoryUrlEdit.text(): self.repositoryUrlEdit.setText(url) E5MessageBox.warning( self, self.tr("Plugins Repository URL Changed"), self.tr( """The URL of the Plugins Repository has""" """ changed. Select the "Update" button to get""" """ the new repository file.""")) else: E5MessageBox.critical( self, self.tr("Read plugins repository file"), self.tr("<p>The plugins repository file <b>{0}</b> " "could not be read. Select Update</p>") .format(self.pluginRepositoryFile)) else: self.__repositoryMissing = True QTreeWidgetItem( self.repositoryList, ["", self.tr( "No plugin repository file available.\nSelect Update.") ]) self.repositoryList.resizeColumnToContents(1) self.newLabel.setText(self.tr("New: <b>{0}</b>") .format(self.__newItems)) self.updateLocalLabel.setText(self.tr("Local Updates: <b>{0}</b>") .format(self.__updateLocalItems)) self.updateRemoteLabel.setText(self.tr("Remote Updates: <b>{0}</b>") .format(self.__updateRemoteItems))
def __downloadRepositoryFileDone(self): """ Private method called after the repository file was downloaded. """ reply = self.sender() if reply in self.__replies: self.__replies.remove(reply) if reply.error() != QNetworkReply.NoError: E5MessageBox.warning( None, self.tr("Error downloading file"), self.tr( """<p>Could not download the requested file""" """ from {0}.</p><p>Error: {1}</p>""" ).format(Preferences.getUI("PluginRepositoryUrl6"), reply.errorString()) ) return ioDevice = QFile(self.pluginRepositoryFile + ".tmp") ioDevice.open(QIODevice.WriteOnly) ioDevice.write(reply.readAll()) ioDevice.close() if QFile.exists(self.pluginRepositoryFile): QFile.remove(self.pluginRepositoryFile) ioDevice.rename(self.pluginRepositoryFile) if os.path.exists(self.pluginRepositoryFile): f = QFile(self.pluginRepositoryFile) if f.open(QIODevice.ReadOnly): # save current URL url = Preferences.getUI("PluginRepositoryUrl6") # read the repository file from E5XML.PluginRepositoryReader import PluginRepositoryReader reader = PluginRepositoryReader(f, self.checkPluginEntry) reader.readXML() if url != Preferences.getUI("PluginRepositoryUrl6"): # redo if it is a redirect self.checkPluginUpdatesAvailable() return if self.__updateAvailable: res = E5MessageBox.information( None, self.tr("New plugin versions available"), self.tr("<p>There are new plug-ins or plug-in" " updates available. Use the plug-in" " repository dialog to get them.</p>"), E5MessageBox.StandardButtons( E5MessageBox.Ignore | E5MessageBox.Open), E5MessageBox.Open) if res == E5MessageBox.Open: self.__ui.showPluginsAvailable()
def __populateList(self): """ Private method to populate the list of available plugins. """ self.repositoryList.clear() self.__stableItem = None self.__unstableItem = None self.__unknownItem = None self.downloadProgress.setValue(0) self.__doneMethod = None if os.path.exists(self.pluginRepositoryFile): self.__repositoryMissing = False f = QFile(self.pluginRepositoryFile) if f.open(QIODevice.ReadOnly): from E5XML.PluginRepositoryReader import PluginRepositoryReader reader = PluginRepositoryReader(f, self.addEntry) reader.readXML() self.repositoryList.resizeColumnToContents(0) self.repositoryList.resizeColumnToContents(1) self.repositoryList.resizeColumnToContents(2) self.__resortRepositoryList() url = Preferences.getUI("PluginRepositoryUrl6") if url != self.repositoryUrlEdit.text(): self.repositoryUrlEdit.setText(url) E5MessageBox.warning( self, self.tr("Plugins Repository URL Changed"), self.tr( """The URL of the Plugins Repository has""" """ changed. Select the "Update" button to get""" """ the new repository file.""")) else: E5MessageBox.critical( self, self.tr("Read plugins repository file"), self.tr("<p>The plugins repository file <b>{0}</b> " "could not be read. Select Update</p>") .format(self.pluginRepositoryFile)) else: self.__repositoryMissing = True QTreeWidgetItem( self.repositoryList, ["", self.tr( "No plugin repository file available.\nSelect Update.") ]) self.repositoryList.resizeColumnToContents(1)
def PluginRepositoryDownloadCleanup(quiet=False): """ Module function to clean up the plug-in downloads area. @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 # 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 try: pluginName, pluginVersion = ( pluginFile.replace(".zip", "").rsplit("-", 1) ) pluginVersionList = re.split("[._-]", pluginVersion) for index in range(len(pluginVersionList)): try: pluginVersionList[index] = int(pluginVersionList[index]) except ValueError: # use default of 0 pluginVersionList[index] = 0 except ValueError: # rsplit() returned just one entry, i.e. file name doesn't contain # version info separated by '-' # => assume version 0.0.0 pluginName = pluginFile.replace(".zip", "") pluginVersionList = [0, 0, 0] if pluginName not in downloads: downloads[pluginName] = [] downloads[pluginName].append((pluginFile, tuple(pluginVersionList))) # step 2: delete old entries hiddenPlugins = Preferences.getPluginManager("HiddenPlugins") for pluginName in downloads: downloads[pluginName].sort(key=lambda x: x[1]) if ( pluginName in hiddenPlugins and not Preferences.getPluginManager("KeepHidden") ): removeFiles = [f[0] for f in downloads[pluginName]] else: removeFiles = [f[0] for f in 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))) # 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)))