src/eric7/PluginManager/PluginRepositoryDialog.py

branch
eric7
changeset 9646
ab5678db972f
parent 9645
31aaa11672d3
child 9653
e67609152c5e
equal deleted inserted replaced
9645:31aaa11672d3 9646:ab5678db972f
1080 pluginName = os.path.splitext(url.rsplit("/", 1)[1])[0] 1080 pluginName = os.path.splitext(url.rsplit("/", 1)[1])[0]
1081 if pluginName not in pluginsRegister: 1081 if pluginName not in pluginsRegister:
1082 pluginsRegister.append(pluginName) 1082 pluginsRegister.append(pluginName)
1083 1083
1084 downloadPath = Preferences.getPluginManager("DownloadPath") 1084 downloadPath = Preferences.getPluginManager("DownloadPath")
1085 downloads = {} # plug-in name as key, file name as value 1085 downloads = {} # plug-in name as key, file name and version as value
1086 1086
1087 # TODO: replace os.listdir() with os.scandir()
1088 # step 1: extract plug-ins and downloaded files 1087 # step 1: extract plug-ins and downloaded files
1089 for pluginFile in os.listdir(downloadPath): 1088 with os.scandir(downloadPath) as dirEntriesIterator:
1090 if not os.path.isfile(os.path.join(downloadPath, pluginFile)): 1089 for pluginFile in dirEntriesIterator:
1091 continue 1090 if not pluginFile.is_file():
1092 1091 continue
1093 try: 1092
1094 pluginName, pluginVersion = pluginFile.replace(".zip", "").rsplit("-", 1) 1093 try:
1095 pluginVersionList = re.split("[._-]", pluginVersion) 1094 pluginName, pluginVersion = pluginFile.name.replace(".zip", "").rsplit(
1096 for index in range(len(pluginVersionList)): 1095 "-", 1
1097 try: 1096 )
1098 pluginVersionList[index] = int(pluginVersionList[index]) 1097 pluginVersionList = re.split("[._-]", pluginVersion)
1099 except ValueError: 1098 for index in range(len(pluginVersionList)):
1100 # use default of 0 1099 try:
1101 pluginVersionList[index] = 0 1100 pluginVersionList[index] = int(pluginVersionList[index])
1102 except ValueError: 1101 except ValueError:
1103 # rsplit() returned just one entry, i.e. file name doesn't contain 1102 # use default of 0
1104 # version info separated by '-' 1103 pluginVersionList[index] = 0
1105 # => assume version 0.0.0 1104 except ValueError:
1106 pluginName = pluginFile.replace(".zip", "") 1105 # rsplit() returned just one entry, i.e. file name doesn't contain
1107 pluginVersionList = [0, 0, 0] 1106 # version info separated by '-'
1108 1107 # => assume version 0.0.0
1109 if pluginName not in downloads: 1108 pluginName = pluginFile.replace(".zip", "")
1110 downloads[pluginName] = [] 1109 pluginVersionList = [0, 0, 0]
1111 downloads[pluginName].append((pluginFile, tuple(pluginVersionList))) 1110
1111 if pluginName not in downloads:
1112 downloads[pluginName] = []
1113 downloads[pluginName].append((pluginFile, tuple(pluginVersionList)))
1112 1114
1113 # step 2: delete old entries 1115 # step 2: delete old entries
1114 hiddenPlugins = Preferences.getPluginManager("HiddenPlugins") 1116 hiddenPlugins = Preferences.getPluginManager("HiddenPlugins")
1115 for pluginName in downloads: 1117 for pluginName in downloads:
1116 downloads[pluginName].sort(key=lambda x: x[1]) 1118 downloads[pluginName].sort(key=lambda x: x[1])

eric ide

mercurial