2021-03-01 22:39:48 +00:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
|
2021-03-03 22:25:44 +00:00
|
|
|
from consoleoutput import oColors #consoleTitle, clearConsole
|
2021-03-07 00:49:57 +00:00
|
|
|
from plugin_downloader import getPackageVersion #handleInput
|
2021-03-04 23:09:03 +00:00
|
|
|
from web_request import doAPIRequest
|
2021-03-01 22:39:48 +00:00
|
|
|
|
|
|
|
|
2021-03-03 22:25:44 +00:00
|
|
|
def createPluginList():
|
|
|
|
global INSTALLEDPLUGINLIST
|
|
|
|
INSTALLEDPLUGINLIST = []
|
|
|
|
return INSTALLEDPLUGINLIST
|
2021-03-03 16:13:43 +00:00
|
|
|
|
2021-03-01 22:39:48 +00:00
|
|
|
|
2021-03-03 22:25:44 +00:00
|
|
|
def addToPluginList(pluginId, versionId, plugin_is_outdated):
|
|
|
|
INSTALLEDPLUGINLIST.append([pluginId, versionId, plugin_is_outdated])
|
|
|
|
|
2021-03-01 22:39:48 +00:00
|
|
|
|
2021-03-03 16:13:43 +00:00
|
|
|
def getFileName(pluginName):
|
2021-03-01 22:39:48 +00:00
|
|
|
pluginNameFull = pluginName
|
|
|
|
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
|
|
|
|
pluginVersionFull = pluginVersion.group()
|
|
|
|
pluginNameOnly = pluginNameFull.replace(pluginVersionFull, '')
|
2021-03-03 22:25:44 +00:00
|
|
|
pluginNameOnly = re.sub(r'(\-$)', '', pluginNameOnly)
|
2021-03-03 16:13:43 +00:00
|
|
|
return pluginNameOnly
|
|
|
|
|
|
|
|
|
|
|
|
def getFileVersion(pluginName):
|
2021-03-03 22:25:44 +00:00
|
|
|
#pluginVersionString = None
|
2021-03-03 16:13:43 +00:00
|
|
|
pluginNameFull = pluginName
|
|
|
|
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
|
|
|
|
pluginVersionFull = pluginVersion.group()
|
|
|
|
pluginVersionString = pluginVersionFull.replace('.jar', '')
|
|
|
|
return pluginVersionString
|
|
|
|
|
2021-03-03 22:25:44 +00:00
|
|
|
|
|
|
|
def compareVersions(pluginId, pluginVersion):
|
2021-03-04 23:09:03 +00:00
|
|
|
url = f"https://api.spiget.org/v2/resources/{pluginId}/versions/latest"
|
|
|
|
latestUpdateSearch = doAPIRequest(url)
|
2021-03-03 16:13:43 +00:00
|
|
|
versionLatestUpdate = latestUpdateSearch["name"]
|
2021-03-03 22:25:44 +00:00
|
|
|
print(pluginVersion)
|
|
|
|
print(versionLatestUpdate)
|
2021-03-03 16:13:43 +00:00
|
|
|
if pluginVersion != versionLatestUpdate:
|
|
|
|
plugin_is_outdated = True
|
|
|
|
else:
|
|
|
|
plugin_is_outdated = False
|
|
|
|
return plugin_is_outdated
|
|
|
|
|
|
|
|
|
|
|
|
def getInstalledPackages(pluginFolderPath):
|
2021-03-03 22:25:44 +00:00
|
|
|
createPluginList()
|
2021-03-03 16:13:43 +00:00
|
|
|
pluginList = os.listdir(pluginFolderPath)
|
|
|
|
print(pluginList)
|
2021-03-03 22:25:44 +00:00
|
|
|
i = 0
|
2021-03-03 16:13:43 +00:00
|
|
|
for plugin in pluginList:
|
|
|
|
print(plugin)
|
|
|
|
fileName = getFileName(plugin)
|
|
|
|
fileVersion = getFileVersion(plugin)
|
2021-03-03 22:25:44 +00:00
|
|
|
pluginId = getInstalledPlugin(fileName, fileVersion)
|
|
|
|
|
|
|
|
print(f"name: {fileName}")
|
|
|
|
print(f"version: {fileVersion}")
|
|
|
|
|
|
|
|
print(INSTALLEDPLUGINLIST)
|
|
|
|
|
2021-03-03 16:13:43 +00:00
|
|
|
if pluginId == None:
|
2021-03-03 22:25:44 +00:00
|
|
|
print(oColors.brightRed + "Couldn't find plugin id. Sorry :(" + oColors.standardWhite)
|
2021-03-03 16:13:43 +00:00
|
|
|
continue
|
2021-03-03 22:25:44 +00:00
|
|
|
if INSTALLEDPLUGINLIST[i][2] == True:
|
2021-03-04 23:09:03 +00:00
|
|
|
os.remove(f"C:\\Users\\USER\\Desktop\\plugins\\{plugin}")
|
2021-03-03 22:25:44 +00:00
|
|
|
getLatestPackageVersion(pluginId, r"C:\\Users\\USER\\Desktop\\plugins\\")
|
2021-03-04 23:09:03 +00:00
|
|
|
i = i + 1
|
2021-03-03 22:25:44 +00:00
|
|
|
print(INSTALLEDPLUGINLIST[1][0])
|
2021-03-03 16:13:43 +00:00
|
|
|
#getLatestPackageVersion(pluginID, r"C:\\Users\USER\Desktop\\plugins\\")
|
|
|
|
|
|
|
|
|
2021-03-03 22:25:44 +00:00
|
|
|
def getInstalledPlugin(localFileName, localFileVersion):
|
2021-03-04 23:09:03 +00:00
|
|
|
url = "https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name"
|
|
|
|
packageName = doAPIRequest(url)
|
2021-03-03 16:13:43 +00:00
|
|
|
print("https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name")
|
2021-03-04 23:09:03 +00:00
|
|
|
#packageName = response.json()
|
2021-03-02 23:17:15 +00:00
|
|
|
i = 1
|
2021-03-03 16:13:43 +00:00
|
|
|
plugin_match_found = False
|
|
|
|
pluginID = None
|
2021-03-02 23:17:15 +00:00
|
|
|
for ressource in packageName:
|
2021-03-03 16:13:43 +00:00
|
|
|
if plugin_match_found == True:
|
|
|
|
break
|
2021-03-02 23:17:15 +00:00
|
|
|
pName = ressource["name"]
|
|
|
|
pID = ressource["id"]
|
2021-03-03 16:13:43 +00:00
|
|
|
print(f" [{i}] {pName} - {pID}")
|
2021-03-04 23:09:03 +00:00
|
|
|
url2 = f"https://api.spiget.org/v2/resources/{pID}/versions?size=100&sort=-name"
|
|
|
|
packageVersions = doAPIRequest(url2)
|
2021-03-03 16:13:43 +00:00
|
|
|
for updates in packageVersions:
|
|
|
|
updateVersion = updates["name"]
|
|
|
|
if localFileVersion == updateVersion:
|
|
|
|
plugin_match_found = True
|
|
|
|
pluginID = pID
|
2021-03-03 22:25:44 +00:00
|
|
|
updateId = updates["id"]
|
|
|
|
plugin_is_outdated = compareVersions(pID, updateVersion)
|
|
|
|
addToPluginList(pID, updateId, plugin_is_outdated)
|
|
|
|
print(updateId)
|
2021-03-03 16:13:43 +00:00
|
|
|
print(pID)
|
2021-03-03 22:25:44 +00:00
|
|
|
print("Found match")
|
2021-03-03 16:13:43 +00:00
|
|
|
break
|
2021-03-02 23:17:15 +00:00
|
|
|
i = i + 1
|
2021-03-03 16:13:43 +00:00
|
|
|
return pluginID
|
|
|
|
|
2021-03-01 22:39:48 +00:00
|
|
|
|
2021-03-04 23:09:03 +00:00
|
|
|
# start query
|
2021-03-01 22:39:48 +00:00
|
|
|
# get id
|
2021-03-03 16:13:43 +00:00
|
|
|
# search with id for all version upates
|
2021-03-01 22:39:48 +00:00
|
|
|
# get version that matches installed version
|
|
|
|
# if match then download latest update
|
|
|
|
# else get second query
|