2021-03-01 22:39:48 +00:00
|
|
|
import os
|
|
|
|
import re
|
2021-03-17 23:03:07 +00:00
|
|
|
import io
|
2021-06-12 15:03:55 +00:00
|
|
|
import base64
|
2021-03-17 23:03:07 +00:00
|
|
|
from zipfile import ZipFile
|
2021-03-14 19:21:26 +00:00
|
|
|
from urllib.error import HTTPError
|
2021-03-16 00:04:13 +00:00
|
|
|
from pathlib import Path
|
2021-03-17 23:03:07 +00:00
|
|
|
from rich.progress import track
|
2021-03-01 22:39:48 +00:00
|
|
|
|
2021-03-12 00:39:39 +00:00
|
|
|
from utils.consoleoutput import oColors
|
|
|
|
from utils.web_request import doAPIRequest
|
2021-03-27 11:07:19 +00:00
|
|
|
from handlers.handle_config import configurationValues
|
2021-05-30 16:52:35 +00:00
|
|
|
from handlers.handle_sftp import createSFTPConnection, sftp_listAll, sftp_downloadFile, sftp_validateFileAttributes
|
|
|
|
from handlers.handle_ftp import createFTPConnection, ftp_listAll, ftp_downloadFile, ftp_validateFileAttributes
|
2021-03-12 00:39:39 +00:00
|
|
|
from plugin.plugin_downloader import getSpecificPackage
|
2021-03-30 21:55:04 +00:00
|
|
|
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder
|
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-06-19 16:01:05 +00:00
|
|
|
def addToPluginList(localFileName, pluginId, versionId, plugin_latest_version, plugin_is_outdated):
|
|
|
|
INSTALLEDPLUGINLIST.append([localFileName, pluginId, versionId, plugin_latest_version, plugin_is_outdated])
|
2021-03-03 22:25:44 +00:00
|
|
|
|
2021-03-01 22:39:48 +00:00
|
|
|
|
2021-03-13 21:09:32 +00:00
|
|
|
def getFileName(pluginName):
|
2021-03-01 22:39:48 +00:00
|
|
|
pluginNameFull = pluginName
|
2021-03-10 22:49:57 +00:00
|
|
|
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
|
2021-03-10 01:05:56 +00:00
|
|
|
try:
|
2021-03-10 22:49:57 +00:00
|
|
|
pluginVersionFull = pluginVersion.group()
|
2021-03-10 01:05:56 +00:00
|
|
|
except AttributeError:
|
|
|
|
pluginVersionFull = pluginVersion
|
|
|
|
pluginNameOnlyy = pluginNameFull.replace(pluginVersionFull, '')
|
|
|
|
pluginNameOnly = re.sub(r'(\-$)', '', pluginNameOnlyy)
|
2021-03-13 21:09:32 +00:00
|
|
|
pluginNameOnlyy = re.sub(r'(\-v$)', '', pluginNameOnly)
|
|
|
|
return pluginNameOnlyy
|
2021-03-03 16:13:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
def getFileVersion(pluginName):
|
|
|
|
pluginNameFull = pluginName
|
|
|
|
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
|
|
|
|
pluginVersionFull = pluginVersion.group()
|
|
|
|
pluginVersionString = pluginVersionFull.replace('.jar', '')
|
2021-03-17 23:03:07 +00:00
|
|
|
if pluginVersionString.endswith('.'):
|
|
|
|
pluginVersionString = ''
|
|
|
|
if pluginVersionString == '':
|
2021-05-14 22:46:29 +00:00
|
|
|
pluginVersionString = eggCrackingJar(pluginNameFull, 'version')
|
2021-03-03 16:13:43 +00:00
|
|
|
return pluginVersionString
|
|
|
|
|
2021-03-03 22:25:44 +00:00
|
|
|
|
2021-03-13 18:21:03 +00:00
|
|
|
def getLatestPluginVersion(pluginId):
|
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-13 18:21:03 +00:00
|
|
|
return versionLatestUpdate
|
|
|
|
|
|
|
|
|
2021-06-19 16:01:05 +00:00
|
|
|
def getUpdateDescription(pluginId):
|
|
|
|
url = f"https://api.spiget.org/v2/resources/{pluginId}/updates?size=1&sort=-date"
|
|
|
|
latestDescriptionSearch = doAPIRequest(url)
|
|
|
|
versionLatestDescription = latestDescriptionSearch[0]["description"]
|
|
|
|
versionLatestDescription = base64.b64decode(versionLatestDescription)
|
|
|
|
versionLatestDescriptionText =versionLatestDescription.decode('utf-8')
|
|
|
|
htmlRegex = re.compile('<.*?>')
|
|
|
|
versionLatestDescriptionText = re.sub(htmlRegex, '', versionLatestDescriptionText)
|
|
|
|
linesChangelogDescription = versionLatestDescriptionText.split("\n")
|
|
|
|
nonEmptyLines = [line for line in linesChangelogDescription if line.strip() != ""]
|
|
|
|
stringnonEmptyLines = ""
|
|
|
|
for line in nonEmptyLines:
|
|
|
|
stringnonEmptyLines += line + "\n"
|
|
|
|
stringnonEmptyLines = stringnonEmptyLines[:-1]
|
|
|
|
return stringnonEmptyLines
|
|
|
|
|
|
|
|
|
2021-07-14 19:26:06 +00:00
|
|
|
def versionTuple(versionString):
|
|
|
|
return tuple(map(int, (versionString.split("."))))
|
|
|
|
|
|
|
|
|
|
|
|
def getVersionWithoutLetters(versionString):
|
|
|
|
return re.sub(r'([A-Za-z]*)', '', versionString)
|
|
|
|
|
|
|
|
|
2021-03-13 18:21:03 +00:00
|
|
|
def compareVersions(plugin_latest_version, pluginVersion):
|
2021-07-14 19:26:06 +00:00
|
|
|
try:
|
|
|
|
pluginVersionTuple = versionTuple(getVersionWithoutLetters(pluginVersion))
|
|
|
|
plugin_latest_versionTuple = versionTuple(getVersionWithoutLetters(plugin_latest_version))
|
|
|
|
except ValueError:
|
|
|
|
return False
|
|
|
|
if pluginVersionTuple < plugin_latest_versionTuple:
|
|
|
|
return True
|
2021-03-03 16:13:43 +00:00
|
|
|
else:
|
2021-07-14 19:26:06 +00:00
|
|
|
return False
|
2021-03-03 16:13:43 +00:00
|
|
|
|
|
|
|
|
2021-05-14 22:46:29 +00:00
|
|
|
def eggCrackingJar(localJarFileName, searchMode):
|
2021-03-27 11:07:19 +00:00
|
|
|
configValues = configurationValues()
|
|
|
|
if not configValues.localPluginFolder:
|
2021-06-26 23:46:15 +00:00
|
|
|
tempPluginFolderPath = createTempPluginFolder()
|
2021-03-30 21:55:04 +00:00
|
|
|
if configValues.sftp_useSftp:
|
|
|
|
sftp = createSFTPConnection()
|
|
|
|
pathToPluginJar = Path(f"{tempPluginFolderPath}/{localJarFileName}")
|
|
|
|
sftp_downloadFile(sftp, pathToPluginJar, localJarFileName)
|
|
|
|
else:
|
|
|
|
ftp = createFTPConnection()
|
|
|
|
pathToPluginJar = Path(f"{tempPluginFolderPath}/{localJarFileName}")
|
|
|
|
ftp_downloadFile(ftp, pathToPluginJar, localJarFileName)
|
2021-03-17 23:03:07 +00:00
|
|
|
else:
|
2021-03-27 11:07:19 +00:00
|
|
|
pluginPath = configValues.pathToPluginFolder
|
2021-03-30 21:55:04 +00:00
|
|
|
pathToPluginJar = Path(f"{pluginPath}/{localJarFileName}")
|
2021-03-17 23:03:07 +00:00
|
|
|
pluginVersion = ''
|
2021-05-14 22:46:29 +00:00
|
|
|
pluginName = ''
|
2021-03-17 23:03:07 +00:00
|
|
|
with ZipFile(pathToPluginJar, 'r') as pluginJar:
|
|
|
|
try:
|
|
|
|
with io.TextIOWrapper(pluginJar.open('plugin.yml', 'r'), encoding="utf-8") as pluginYml:
|
|
|
|
pluginYmlContentLine = pluginYml.readlines()
|
|
|
|
for line in pluginYmlContentLine:
|
2021-05-14 22:46:29 +00:00
|
|
|
if searchMode == 'version':
|
2021-05-28 21:52:16 +00:00
|
|
|
if re.match(r'^\s*?version: ', line):
|
|
|
|
pluginVersion = re.sub(r'^\s*?version: ', '', line)
|
2021-05-14 22:46:29 +00:00
|
|
|
pluginVersion = pluginVersion.replace('\n', '')
|
|
|
|
pluginVersion = pluginVersion.replace("'", '')
|
|
|
|
pluginVersion = pluginVersion.replace('"', '')
|
|
|
|
elif searchMode == 'name':
|
2021-05-28 21:52:16 +00:00
|
|
|
if re.match(r'^\s*?name: ', line):
|
|
|
|
pluginName = re.sub(r'^\s*?name: ', '', line)
|
2021-05-14 22:46:29 +00:00
|
|
|
pluginName = pluginName.replace('\n', '')
|
|
|
|
pluginName = pluginName.replace("'", '')
|
|
|
|
pluginName = pluginName.replace('"', '')
|
2021-03-17 23:03:07 +00:00
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
|
|
pluginVersion = ''
|
2021-05-14 22:46:29 +00:00
|
|
|
pluginName = ''
|
2021-07-14 19:26:06 +00:00
|
|
|
except KeyError:
|
|
|
|
pluginVersion = ''
|
|
|
|
pluginName = ''
|
2021-03-30 21:55:04 +00:00
|
|
|
if not configValues.localPluginFolder:
|
|
|
|
deleteTempPluginFolder(tempPluginFolderPath)
|
2021-05-14 22:46:29 +00:00
|
|
|
if searchMode == 'version':
|
|
|
|
return pluginVersion
|
|
|
|
if searchMode == 'name':
|
|
|
|
return pluginName
|
2021-03-17 23:03:07 +00:00
|
|
|
|
|
|
|
|
2021-06-19 22:36:36 +00:00
|
|
|
def checkInstalledPackage(inputSelectedObject="all", inputOptionalParam=None):
|
2021-03-26 19:24:15 +00:00
|
|
|
configValues = configurationValues()
|
2021-03-08 01:56:00 +00:00
|
|
|
createPluginList()
|
2021-05-29 18:42:02 +00:00
|
|
|
pluginFolderPath = configValues.pathToPluginFolder
|
2021-03-26 19:24:15 +00:00
|
|
|
if not configValues.localPluginFolder:
|
2021-03-30 21:55:04 +00:00
|
|
|
if configValues.sftp_useSftp:
|
|
|
|
connection = createSFTPConnection()
|
|
|
|
pluginList = sftp_listAll(connection)
|
|
|
|
else:
|
|
|
|
connection = createFTPConnection()
|
|
|
|
pluginList = ftp_listAll(connection)
|
2021-03-10 01:05:56 +00:00
|
|
|
else:
|
2021-05-29 18:42:02 +00:00
|
|
|
pluginList = os.listdir(pluginFolderPath)
|
2021-06-19 16:01:05 +00:00
|
|
|
|
2021-03-08 01:56:00 +00:00
|
|
|
i = 0
|
2021-03-26 19:24:15 +00:00
|
|
|
oldPlugins = 0
|
2021-03-21 13:30:27 +00:00
|
|
|
print(oColors.brightBlack + f"Checking: {inputSelectedObject}" + oColors.standardWhite)
|
2021-06-19 22:36:36 +00:00
|
|
|
if inputOptionalParam != "changelog":
|
|
|
|
print(oColors.brightBlack + f"Use 'check {inputSelectedObject} changelog' to get the latest changelog from plugins" + oColors.standardWhite)
|
2021-06-20 11:54:15 +00:00
|
|
|
print("┌─────┬────────────────────────────────┬──────────────┬──────────────┐")
|
|
|
|
print("│ No. │ Name │ Installed V. │ Latest V. │")
|
|
|
|
print("└─────┴────────────────────────────────┴──────────────┴──────────────┘")
|
2021-03-12 00:39:39 +00:00
|
|
|
try:
|
2021-03-27 17:58:16 +00:00
|
|
|
for plugin in track(pluginList, description="Checking for updates" ,transient=True, complete_style="bright_yellow"):
|
2021-05-30 16:52:35 +00:00
|
|
|
if not configValues.localPluginFolder:
|
2021-06-21 22:08:57 +00:00
|
|
|
pluginFile = f"{configValues.sftp_folderPath}/{plugin}"
|
2021-05-30 16:52:35 +00:00
|
|
|
if configValues.sftp_useSftp:
|
|
|
|
pluginAttributes = sftp_validateFileAttributes(connection, pluginFile)
|
|
|
|
if pluginAttributes == False:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
pluginAttributes = ftp_validateFileAttributes(connection, pluginFile)
|
|
|
|
if pluginAttributes == False:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if not os.path.isfile(Path(f"{pluginFolderPath}/{plugin}")):
|
|
|
|
continue
|
|
|
|
if not re.search(r'.jar$', plugin):
|
|
|
|
continue
|
2021-03-12 00:39:39 +00:00
|
|
|
try:
|
|
|
|
fileName = getFileName(plugin)
|
|
|
|
fileVersion = getFileVersion(plugin)
|
2021-05-14 22:46:29 +00:00
|
|
|
pluginId = getInstalledPlugin(fileName, fileVersion, plugin)
|
2021-03-12 00:39:39 +00:00
|
|
|
except TypeError:
|
|
|
|
continue
|
2021-05-28 21:52:16 +00:00
|
|
|
|
2021-03-12 00:39:39 +00:00
|
|
|
pluginIdStr = str(pluginId)
|
|
|
|
if fileVersion == '':
|
|
|
|
fileVersion = 'N/A'
|
|
|
|
try:
|
2021-06-19 16:01:05 +00:00
|
|
|
pluginLatestVersion = INSTALLEDPLUGINLIST[i][3]
|
2021-03-12 00:39:39 +00:00
|
|
|
except IndexError:
|
2021-03-13 18:21:03 +00:00
|
|
|
pluginLatestVersion = 'N/A'
|
2021-03-16 20:10:09 +00:00
|
|
|
|
2021-03-13 18:21:03 +00:00
|
|
|
if pluginLatestVersion == None:
|
|
|
|
pluginLatestVersion = 'N/A'
|
|
|
|
|
|
|
|
try:
|
2021-06-19 16:01:05 +00:00
|
|
|
pluginIsOutdated = INSTALLEDPLUGINLIST[i][4]
|
2021-03-13 18:21:03 +00:00
|
|
|
except IndexError:
|
|
|
|
pluginIsOutdated = 'N/A'
|
|
|
|
|
|
|
|
if pluginIsOutdated == None:
|
2021-03-12 00:39:39 +00:00
|
|
|
pluginIsOutdated = 'N/A'
|
|
|
|
|
|
|
|
if pluginIsOutdated == True:
|
2021-03-26 19:24:15 +00:00
|
|
|
oldPlugins = oldPlugins + 1
|
2021-03-17 23:03:07 +00:00
|
|
|
|
2021-05-29 18:42:02 +00:00
|
|
|
if re.search(r'.jar$', fileName):
|
2021-05-28 21:52:16 +00:00
|
|
|
fileName = eggCrackingJar(plugin, "name")
|
|
|
|
|
2021-06-19 16:01:05 +00:00
|
|
|
if inputSelectedObject != "all" and inputSelectedObject != "*":
|
|
|
|
if inputSelectedObject != pluginIdStr or not re.search(inputSelectedObject, fileName, re.IGNORECASE):
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
|
|
|
|
if inputSelectedObject == "all" or inputSelectedObject != "*" or inputSelectedObject != "all":
|
2021-03-13 18:21:03 +00:00
|
|
|
if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
|
2021-03-21 13:30:27 +00:00
|
|
|
if pluginLatestVersion == 'N/A':
|
2021-03-26 19:24:15 +00:00
|
|
|
print(oColors.brightBlack + f" [{1}]".rjust(6), end='')
|
2021-03-21 13:30:27 +00:00
|
|
|
else:
|
2021-03-26 19:24:15 +00:00
|
|
|
print(f" [{1}]".rjust(6), end='')
|
2021-03-21 13:30:27 +00:00
|
|
|
else:
|
2021-06-19 16:01:05 +00:00
|
|
|
if pluginLatestVersion == 'N/A':
|
|
|
|
print(oColors.brightBlack + f" [{i+1}]".rjust(6), end='')
|
|
|
|
else:
|
|
|
|
print(f" [{i+1}]".rjust(6), end='')
|
2021-03-26 19:24:15 +00:00
|
|
|
print(" ", end='')
|
2021-06-20 11:54:15 +00:00
|
|
|
if pluginIsOutdated == True:
|
|
|
|
print(oColors.brightRed + f"{fileName}".ljust(33) + oColors.standardWhite, end='')
|
2021-07-18 12:51:02 +00:00
|
|
|
elif pluginIsOutdated == False:
|
|
|
|
print(oColors.brightGreen + f"{fileName}".ljust(33) + oColors.standardWhite, end='')
|
2021-06-20 11:54:15 +00:00
|
|
|
else:
|
|
|
|
print(f"{fileName}".ljust(33), end='')
|
|
|
|
|
2021-03-13 18:21:03 +00:00
|
|
|
print(f"{fileVersion}".ljust(15), end='')
|
2021-06-20 11:54:15 +00:00
|
|
|
print(f"{pluginLatestVersion}".ljust(15))
|
2021-06-19 22:36:36 +00:00
|
|
|
if (inputOptionalParam == "changelog" and pluginLatestVersion != 'N/A'):
|
|
|
|
print(oColors.brightYellow + f"CHANGELOG {fileName}:" + oColors.standardWhite)
|
2021-06-19 11:47:12 +00:00
|
|
|
description = getUpdateDescription(pluginId)
|
|
|
|
print(description)
|
2021-06-19 22:36:36 +00:00
|
|
|
print()
|
2021-06-19 16:01:05 +00:00
|
|
|
if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
print(oColors.brightRed + "Wrong input! Use 'check all' to check every plugin for updates!" + oColors.standardWhite)
|
|
|
|
break
|
2021-03-08 01:56:00 +00:00
|
|
|
|
2021-03-16 20:10:09 +00:00
|
|
|
i += 1
|
2021-03-12 00:39:39 +00:00
|
|
|
except TypeError:
|
2021-03-21 13:30:27 +00:00
|
|
|
print(oColors.brightRed + "Error occured: Aborted checking for updates." + oColors.standardWhite)
|
2021-03-26 19:24:15 +00:00
|
|
|
print(oColors.brightYellow + f"Outdated plugins: [{oldPlugins}/{i}]" + oColors.standardWhite)
|
2021-03-08 01:56:00 +00:00
|
|
|
|
|
|
|
|
2021-03-10 01:05:56 +00:00
|
|
|
def updateInstalledPackage(inputSelectedObject='all'):
|
2021-03-26 19:24:15 +00:00
|
|
|
configValues = configurationValues()
|
2021-06-19 22:36:36 +00:00
|
|
|
if not configValues.localPluginFolder:
|
|
|
|
if configValues.sftp_useSftp:
|
|
|
|
connection = createSFTPConnection()
|
|
|
|
else:
|
|
|
|
connection = createFTPConnection()
|
|
|
|
|
|
|
|
try:
|
2021-06-20 11:54:15 +00:00
|
|
|
print(oColors.brightBlack + "Selected plugins with available Updates:" + oColors.standardWhite)
|
2021-06-19 22:36:36 +00:00
|
|
|
if inputSelectedObject == "all" or inputSelectedObject == "*":
|
|
|
|
for pluginIndex in range(len(INSTALLEDPLUGINLIST)):
|
2021-06-20 11:54:15 +00:00
|
|
|
if INSTALLEDPLUGINLIST[pluginIndex][4] == True:
|
|
|
|
fileName = getFileName(INSTALLEDPLUGINLIST[pluginIndex][0])
|
|
|
|
print(fileName, end=' ')
|
2021-06-19 22:36:36 +00:00
|
|
|
else:
|
|
|
|
print(inputSelectedObject, end=' ')
|
|
|
|
|
|
|
|
print()
|
|
|
|
updateConfirmation = input("Update these plugins [y/n] ? ")
|
2021-07-14 19:26:06 +00:00
|
|
|
if str.lower(updateConfirmation) != "y":
|
2021-06-19 22:36:36 +00:00
|
|
|
print(oColors.brightRed + "Aborting the update process."+ oColors.standardWhite)
|
|
|
|
return False
|
|
|
|
|
|
|
|
except NameError:
|
|
|
|
print(oColors.brightRed + "Check for updates before updating plugins with: 'check all'" + oColors.standardWhite)
|
|
|
|
print(oColors.brightRed + "Started checking for updates..." + oColors.standardWhite)
|
|
|
|
checkInstalledPackage()
|
|
|
|
print(oColors.brightRed + f"Please input 'update {inputSelectedObject}' again!" + oColors.standardWhite)
|
|
|
|
return False
|
2021-05-29 18:42:02 +00:00
|
|
|
|
2021-03-03 22:25:44 +00:00
|
|
|
i = 0
|
2021-03-10 22:49:57 +00:00
|
|
|
pluginsUpdated = 0
|
2021-03-14 19:21:26 +00:00
|
|
|
indexNumberUpdated = 0
|
2021-03-21 13:30:27 +00:00
|
|
|
print(oColors.brightBlack + f"Updating: {inputSelectedObject}" + oColors.standardWhite)
|
|
|
|
print("┌─────┬────────────────────────────────┬────────────┬──────────┐")
|
2021-03-23 17:32:20 +00:00
|
|
|
print("│ No. │ Name │ Old V. │ New V. │")
|
2021-03-21 13:30:27 +00:00
|
|
|
print("└─────┴────────────────────────────────┴────────────┴──────────┘")
|
2021-03-12 00:39:39 +00:00
|
|
|
try:
|
2021-06-19 22:36:36 +00:00
|
|
|
for pluginArray in track(INSTALLEDPLUGINLIST, description="Updating" ,transient=True, complete_style="bright_magenta", ):
|
2021-06-19 16:01:05 +00:00
|
|
|
plugin = INSTALLEDPLUGINLIST[i][0]
|
2021-05-30 16:52:35 +00:00
|
|
|
if not configValues.localPluginFolder:
|
2021-06-26 23:46:15 +00:00
|
|
|
pluginFile = f"{configValues.sftp_folderPath}/{plugin}"
|
2021-05-30 16:52:35 +00:00
|
|
|
if configValues.sftp_useSftp:
|
|
|
|
pluginAttributes = sftp_validateFileAttributes(connection, pluginFile)
|
|
|
|
if pluginAttributes == False:
|
2021-06-19 16:01:05 +00:00
|
|
|
i += 1
|
2021-05-30 16:52:35 +00:00
|
|
|
continue
|
|
|
|
else:
|
|
|
|
pluginAttributes = ftp_validateFileAttributes(connection, pluginFile)
|
|
|
|
if pluginAttributes == False:
|
2021-06-19 16:01:05 +00:00
|
|
|
i += 1
|
2021-05-30 16:52:35 +00:00
|
|
|
continue
|
|
|
|
else:
|
2021-06-19 22:36:36 +00:00
|
|
|
pluginFolderPath = configValues.pathToPluginFolder
|
2021-05-30 16:52:35 +00:00
|
|
|
if not os.path.isfile(Path(f"{pluginFolderPath}/{plugin}")):
|
2021-06-19 16:01:05 +00:00
|
|
|
i += 1
|
2021-05-30 16:52:35 +00:00
|
|
|
continue
|
|
|
|
if not re.search(r'.jar$', plugin):
|
2021-06-19 16:01:05 +00:00
|
|
|
i += 1
|
2021-05-30 16:52:35 +00:00
|
|
|
continue
|
2021-05-29 18:42:02 +00:00
|
|
|
|
2021-03-12 00:39:39 +00:00
|
|
|
try:
|
2021-06-19 22:36:36 +00:00
|
|
|
fileName = getFileName(plugin)
|
2021-03-12 00:39:39 +00:00
|
|
|
fileVersion = getFileVersion(plugin)
|
2021-06-19 22:36:36 +00:00
|
|
|
pluginId = INSTALLEDPLUGINLIST[i][1]
|
|
|
|
latestVersion = INSTALLEDPLUGINLIST[i][3]
|
|
|
|
except (TypeError, ValueError):
|
|
|
|
i += 1
|
2021-03-13 18:21:03 +00:00
|
|
|
continue
|
2021-05-29 18:42:02 +00:00
|
|
|
|
|
|
|
if re.search(r'.jar$', fileName):
|
2021-05-28 21:52:16 +00:00
|
|
|
fileName = eggCrackingJar(plugin, "name")
|
2021-05-29 18:42:02 +00:00
|
|
|
|
2021-03-12 00:39:39 +00:00
|
|
|
pluginIdStr = str(pluginId)
|
2021-03-18 22:42:02 +00:00
|
|
|
if pluginId == None or pluginId == '':
|
2021-06-19 16:01:05 +00:00
|
|
|
i += 1
|
2021-03-12 00:39:39 +00:00
|
|
|
continue
|
2021-05-29 18:42:02 +00:00
|
|
|
|
2021-07-18 12:51:02 +00:00
|
|
|
if inputSelectedObject != 'all' and inputSelectedObject != pluginIdStr and not re.search(inputSelectedObject, fileName, re.IGNORECASE):
|
2021-06-19 22:36:36 +00:00
|
|
|
i += 1
|
|
|
|
continue
|
2021-07-18 12:51:02 +00:00
|
|
|
if INSTALLEDPLUGINLIST[i][4] != True:
|
|
|
|
i += 1
|
|
|
|
continue
|
|
|
|
if INSTALLEDPLUGINLIST[i][4] == False and inputSelectedObject != 'all':
|
|
|
|
print(oColors.brightGreen + f"{fileName} is already on {latestVersion}" + oColors.standardWhite)
|
|
|
|
print(oColors.brightRed + "Aborting the update process."+ oColors.standardWhite)
|
|
|
|
break
|
|
|
|
|
|
|
|
print(f" [{indexNumberUpdated+1}]".rjust(6), end='')
|
|
|
|
print(" ", end='')
|
|
|
|
print(f"{fileName}".ljust(33), end='')
|
|
|
|
print(f"{fileVersion}".ljust(13), end='')
|
|
|
|
print(f"{latestVersion}".ljust(13))
|
|
|
|
if not configValues.localPluginFolder:
|
|
|
|
if configValues.sftp_seperateDownloadPath is True:
|
|
|
|
pluginPath = configValues.sftp_pathToSeperateDownloadPath
|
|
|
|
else:
|
|
|
|
pluginPath = configValues.sftp_folderPath
|
|
|
|
pluginPath = f"{pluginPath}/{plugin}"
|
|
|
|
indexNumberUpdated += 1
|
|
|
|
pluginsUpdated += 1
|
|
|
|
if configValues.sftp_useSftp:
|
|
|
|
sftp = createSFTPConnection()
|
|
|
|
try:
|
|
|
|
getSpecificPackage(pluginId, pluginPath)
|
|
|
|
if configValues.sftp_seperateDownloadPath is False:
|
|
|
|
sftp.remove(pluginPath)
|
|
|
|
except HTTPError as err:
|
|
|
|
print(oColors.brightRed + f"HTTPError: {err.code} - {err.reason}" + oColors.standardWhite)
|
|
|
|
pluginsUpdated -= 1
|
|
|
|
except TypeError:
|
|
|
|
print(oColors.brightRed + f"TypeError: Couldn't download new version. Is the file available on spigotmc?" + oColors.standardWhite)
|
|
|
|
pluginsUpdated -= 1
|
|
|
|
except FileNotFoundError:
|
|
|
|
print(oColors.brightRed + f"FileNotFoundError: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
|
|
|
|
|
|
|
else:
|
|
|
|
ftp = createFTPConnection()
|
|
|
|
try:
|
|
|
|
getSpecificPackage(pluginId, pluginPath)
|
|
|
|
if configValues.sftp_seperateDownloadPath is False:
|
|
|
|
ftp.delete(pluginPath)
|
|
|
|
except HTTPError as err:
|
|
|
|
print(oColors.brightRed + f"HTTPError: {err.code} - {err.reason}" + oColors.standardWhite)
|
|
|
|
pluginsUpdated -= 1
|
|
|
|
except TypeError:
|
|
|
|
print(oColors.brightRed + f"TypeError: Couldn't download new version. Is the file available on spigotmc?" + oColors.standardWhite)
|
|
|
|
pluginsUpdated -= 1
|
|
|
|
except FileNotFoundError:
|
|
|
|
print(oColors.brightRed + f"FileNotFoundError: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
|
|
|
|
|
|
|
else:
|
|
|
|
if configValues.seperateDownloadPath is True:
|
|
|
|
pluginPath = configValues.pathToSeperateDownloadPath
|
|
|
|
else:
|
|
|
|
pluginPath = configValues.pathToPluginFolder
|
|
|
|
indexNumberUpdated += 1
|
|
|
|
pluginsUpdated += 1
|
|
|
|
try:
|
|
|
|
getSpecificPackage(pluginId, pluginPath)
|
|
|
|
if configValues.seperateDownloadPath is False:
|
|
|
|
pluginPath = f"{pluginPath}/{plugin}"
|
|
|
|
os.remove(pluginPath)
|
|
|
|
except HTTPError as err:
|
|
|
|
print(oColors.brightRed + f"HTTPError: {err.code} - {err.reason}" + oColors.standardWhite)
|
|
|
|
pluginsUpdated -= 1
|
|
|
|
except TypeError:
|
|
|
|
print(oColors.brightRed + f"TypeError: Couldn't download new version. Is the file available on spigotmc?" + oColors.standardWhite)
|
|
|
|
pluginsUpdated -= 1
|
|
|
|
except FileNotFoundError:
|
|
|
|
print(oColors.brightRed + f"FileNotFoundError: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
|
|
|
if inputSelectedObject != 'all':
|
|
|
|
break
|
|
|
|
elif inputSelectedObject != 'all':
|
|
|
|
print(oColors.brightGreen + f"{fileName} is already on {latestVersion}" + oColors.standardWhite)
|
|
|
|
print(oColors.brightRed + "Aborting the update process."+ oColors.standardWhite)
|
|
|
|
break
|
2021-03-14 19:21:26 +00:00
|
|
|
|
2021-04-07 18:38:29 +00:00
|
|
|
i += 1
|
2021-03-12 00:39:39 +00:00
|
|
|
except TypeError:
|
2021-06-19 16:01:05 +00:00
|
|
|
print(oColors.brightRed + "Error occured: Aborted updating plugins." + oColors.standardWhite)
|
2021-06-19 22:36:36 +00:00
|
|
|
except NameError:
|
|
|
|
print(oColors.brightRed + "Check for updates before updating plugins with: 'check all'" + oColors.standardWhite)
|
|
|
|
print(oColors.brightRed + "Started checking for updates..." + oColors.standardWhite)
|
|
|
|
checkInstalledPackage()
|
|
|
|
print(oColors.brightRed + f"Please input 'update {inputSelectedObject}' again!" + oColors.standardWhite)
|
|
|
|
if i != 0:
|
|
|
|
print(oColors.brightYellow + f"Plugins updated: [{pluginsUpdated}/{i}]" + oColors.standardWhite)
|
|
|
|
if inputSelectedObject =='all' and pluginsUpdated == 0 and i != 0:
|
2021-03-21 13:30:27 +00:00
|
|
|
print(oColors.brightGreen + "All found plugins are on the latest version!" + oColors.standardWhite)
|
2021-03-03 16:13:43 +00:00
|
|
|
|
|
|
|
|
2021-05-14 22:46:29 +00:00
|
|
|
def getInstalledPlugin(localFileName, localFileVersion, localPluginFullName):
|
2021-03-13 22:32:52 +00:00
|
|
|
url = "https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name&sort=-downloads"
|
2021-03-04 23:09:03 +00:00
|
|
|
packageName = doAPIRequest(url)
|
2021-03-03 16:13:43 +00:00
|
|
|
plugin_match_found = False
|
|
|
|
pluginID = None
|
2021-05-14 22:46:29 +00:00
|
|
|
localFileVersionNew = localFileVersion
|
|
|
|
i = 0
|
|
|
|
for i in range(0, 3):
|
2021-03-03 16:13:43 +00:00
|
|
|
if plugin_match_found == True:
|
2021-05-28 21:52:16 +00:00
|
|
|
break
|
2021-05-14 22:46:29 +00:00
|
|
|
if i == 1:
|
|
|
|
localFileVersionNew = re.sub(r'(\-\w*)', '', localFileVersion)
|
|
|
|
if i == 2:
|
|
|
|
pluginNameinYML = eggCrackingJar(localPluginFullName, 'name')
|
|
|
|
url = "https://api.spiget.org/v2/search/resources/" + pluginNameinYML + "?field=name&sort=-downloads"
|
2021-05-28 21:52:16 +00:00
|
|
|
try:
|
|
|
|
packageName = doAPIRequest(url)
|
|
|
|
except ValueError:
|
|
|
|
continue
|
|
|
|
|
2021-05-14 22:46:29 +00:00
|
|
|
localFileVersion = localFileVersionNew
|
|
|
|
|
2021-07-14 19:26:06 +00:00
|
|
|
for resource in packageName:
|
2021-05-14 22:46:29 +00:00
|
|
|
if plugin_match_found == True:
|
2021-05-28 21:52:16 +00:00
|
|
|
continue
|
2021-07-14 19:26:06 +00:00
|
|
|
pID = resource["id"]
|
2021-05-14 22:46:29 +00:00
|
|
|
url2 = f"https://api.spiget.org/v2/resources/{pID}/versions?size=100&sort=-name"
|
2021-05-28 21:52:16 +00:00
|
|
|
try:
|
|
|
|
packageVersions = doAPIRequest(url2)
|
|
|
|
except ValueError:
|
|
|
|
continue
|
2021-05-14 22:46:29 +00:00
|
|
|
for updates in packageVersions:
|
|
|
|
updateVersion = updates["name"]
|
|
|
|
if localFileVersionNew in updateVersion:
|
|
|
|
plugin_match_found = True
|
|
|
|
pluginID = pID
|
|
|
|
updateId = updates["id"]
|
|
|
|
plugin_latest_version = getLatestPluginVersion(pID)
|
|
|
|
plugin_is_outdated = compareVersions(plugin_latest_version, updateVersion)
|
2021-06-19 16:01:05 +00:00
|
|
|
addToPluginList(localPluginFullName, pID, updateId, plugin_latest_version , plugin_is_outdated)
|
2021-05-14 22:46:29 +00:00
|
|
|
return pluginID
|
2021-03-14 12:25:13 +00:00
|
|
|
|
2021-03-16 20:10:09 +00:00
|
|
|
else:
|
2021-03-14 12:25:13 +00:00
|
|
|
if plugin_match_found != True:
|
2021-07-14 19:26:06 +00:00
|
|
|
pID = updateId = plugin_latest_version = plugin_is_outdated = None
|
2021-06-19 16:01:05 +00:00
|
|
|
addToPluginList(localPluginFullName, pID, updateId, plugin_latest_version , plugin_is_outdated)
|
2021-03-13 18:21:03 +00:00
|
|
|
|
2021-03-03 16:13:43 +00:00
|
|
|
return pluginID
|