PluginManager/PluginRepositoryDialog.py

branch
maintenance
changeset 5982
af0d2f9dfa21
parent 5868
c1a98c164cd3
child 6023
c6dabc972560
equal deleted inserted replaced
5981:2f2c988c359e 5982:af0d2f9dfa21
12 12
13 import sys 13 import sys
14 import os 14 import os
15 import zipfile 15 import zipfile
16 import glob 16 import glob
17 import re
17 18
18 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QFile, QIODevice, QUrl, \ 19 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QFile, QIODevice, QUrl, \
19 QProcess, QPoint, QCoreApplication 20 QProcess, QPoint, QCoreApplication
20 from PyQt5.QtWidgets import QWidget, QDialogButtonBox, QAbstractButton, \ 21 from PyQt5.QtWidgets import QWidget, QDialogButtonBox, QAbstractButton, \
21 QTreeWidgetItem, QDialog, QVBoxLayout, QMenu 22 QTreeWidgetItem, QDialog, QVBoxLayout, QMenu
875 # step 1: extract plug-ins and downloaded files 876 # step 1: extract plug-ins and downloaded files
876 for pluginFile in os.listdir(downloadPath): 877 for pluginFile in os.listdir(downloadPath):
877 if not os.path.isfile(os.path.join(downloadPath, pluginFile)): 878 if not os.path.isfile(os.path.join(downloadPath, pluginFile)):
878 continue 879 continue
879 880
880 pluginName = pluginFile.rsplit("-", 1)[0] 881 pluginName, pluginVersion = \
882 pluginFile.replace(".zip", "").rsplit("-", 1)
883 pluginVersionList = re.split("[._-]", pluginVersion)
884 for index in range(len(pluginVersionList)):
885 try:
886 pluginVersionList[index] = int(pluginVersionList[index])
887 except ValueError:
888 # use default of 0
889 pluginVersionList[index] = 0
890
881 if pluginName not in downloads: 891 if pluginName not in downloads:
882 downloads[pluginName] = [] 892 downloads[pluginName] = []
883 downloads[pluginName].append(pluginFile) 893 downloads[pluginName].append((pluginFile, tuple(pluginVersionList)))
884 894
885 # step 2: delete old entries 895 # step 2: delete old entries
886 hiddenPlugins = Preferences.getPluginManager("HiddenPlugins") 896 hiddenPlugins = Preferences.getPluginManager("HiddenPlugins")
887 for pluginName in downloads: 897 for pluginName in downloads:
888 downloads[pluginName].sort() 898 downloads[pluginName].sort(key=lambda x: x[1])
889 899
890 if pluginName in hiddenPlugins and \ 900 if pluginName in hiddenPlugins and \
891 not Preferences.getPluginManager("KeepHidden"): 901 not Preferences.getPluginManager("KeepHidden"):
892 removeFiles = downloads[pluginName] 902 removeFiles = downloads[pluginName][0]
893 else: 903 else:
894 removeFiles = downloads[pluginName][ 904 removeFiles = [f[0] for f in downloads[pluginName][
895 :-Preferences.getPluginManager("KeepGenerations")] 905 :-Preferences.getPluginManager("KeepGenerations")]]
896 for removeFile in removeFiles: 906 for removeFile in removeFiles:
897 try: 907 try:
898 os.remove(os.path.join(downloadPath, removeFile)) 908 os.remove(os.path.join(downloadPath, removeFile))
899 except (IOError, OSError) as err: 909 except (IOError, OSError) as err:
900 if not quiet: 910 if not quiet:

eric ide

mercurial