2021-03-01 22:39:48 +00:00
|
|
|
import os
|
|
|
|
import re
|
2021-03-17 23:03:07 +00:00
|
|
|
import io
|
2021-05-30 16:52:35 +00:00
|
|
|
import stat
|
|
|
|
import pysftp
|
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-03-13 18:21:03 +00:00
|
|
|
def addToPluginList(pluginId, versionId, plugin_latest_version, plugin_is_outdated):
|
|
|
|
INSTALLEDPLUGINLIST.append([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
|
|
|
|
|
|
|
|
|
|
|
|
def compareVersions(plugin_latest_version, pluginVersion):
|
|
|
|
if pluginVersion < plugin_latest_version:
|
2021-03-03 16:13:43 +00:00
|
|
|
plugin_is_outdated = True
|
|
|
|
else:
|
|
|
|
plugin_is_outdated = False
|
|
|
|
return plugin_is_outdated
|
|
|
|
|
|
|
|
|
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-03-30 21:55:04 +00:00
|
|
|
if configValues.sftp_useSftp:
|
|
|
|
tempPluginFolderPath = createTempPluginFolder()
|
|
|
|
sftp = createSFTPConnection()
|
|
|
|
pathToPluginJar = Path(f"{tempPluginFolderPath}/{localJarFileName}")
|
|
|
|
sftp_downloadFile(sftp, pathToPluginJar, localJarFileName)
|
|
|
|
else:
|
|
|
|
tempPluginFolderPath = createTempPluginFolder()
|
|
|
|
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-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-03-10 01:05:56 +00:00
|
|
|
def checkInstalledPackage(inputSelectedObject="all"):
|
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-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-03-26 19:24:15 +00:00
|
|
|
print("┌─────┬────────────────────────────────┬──────────────┬──────────────┬───────────────────┐")
|
|
|
|
print("│ No. │ Name │ Installed V. │ Latest V. │ Update available │")
|
|
|
|
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:
|
|
|
|
if configValues.sftp_seperateDownloadPath is True:
|
|
|
|
pluginFile = f"{configValues.sftp_pathToSeperateDownloadPath}/{plugin}"
|
|
|
|
else:
|
|
|
|
pluginFile = f"{configValues.sftp_folderPath}/{plugin}"
|
2021-05-29 18:42:02 +00:00
|
|
|
|
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-05-29 18:42:02 +00:00
|
|
|
|
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-03-13 18:21:03 +00:00
|
|
|
pluginLatestVersion = INSTALLEDPLUGINLIST[i][2]
|
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:
|
|
|
|
pluginIsOutdated = INSTALLEDPLUGINLIST[i][3]
|
|
|
|
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-03-13 18:21:03 +00:00
|
|
|
if inputSelectedObject != "*" and inputSelectedObject != "all":
|
|
|
|
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='')
|
|
|
|
print(" ", end='')
|
2021-03-13 18:21:03 +00:00
|
|
|
print(f"{fileName}".ljust(33), end='')
|
|
|
|
print(f"{fileVersion}".ljust(15), end='')
|
2021-03-27 11:07:19 +00:00
|
|
|
print(f"{pluginLatestVersion}".ljust(15), end='')
|
|
|
|
print(f"{pluginIsOutdated}".ljust(5) + oColors.standardWhite)
|
2021-03-13 18:21:03 +00:00
|
|
|
break
|
2021-03-08 01:56:00 +00:00
|
|
|
else:
|
2021-03-21 13:30:27 +00:00
|
|
|
if pluginLatestVersion == 'N/A':
|
2021-03-26 19:24:15 +00:00
|
|
|
print(oColors.brightBlack + f" [{i+1}]".rjust(6), end='')
|
2021-03-21 13:30:27 +00:00
|
|
|
else:
|
2021-03-26 19:24:15 +00:00
|
|
|
print(f" [{i+1}]".rjust(6), end='')
|
|
|
|
print(" ", end='')
|
2021-03-13 18:21:03 +00:00
|
|
|
print(f"{fileName}".ljust(33), end='')
|
|
|
|
print(f"{fileVersion}".ljust(15), end='')
|
2021-03-27 11:07:19 +00:00
|
|
|
print(f"{pluginLatestVersion}".ljust(15), end='')
|
|
|
|
print(f"{pluginIsOutdated}".ljust(5) + oColors.standardWhite)
|
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-03-03 22:25:44 +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-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-03-27 17:58:16 +00:00
|
|
|
for plugin in track(pluginList, description="Updating" ,transient=True, complete_style="bright_magenta"):
|
2021-05-30 16:52:35 +00:00
|
|
|
if not configValues.localPluginFolder:
|
|
|
|
if configValues.sftp_seperateDownloadPath is True:
|
|
|
|
pluginFile = f"{configValues.sftp_pathToSeperateDownloadPath}/{plugin}"
|
|
|
|
else:
|
|
|
|
pluginFile = f"{configValues.sftp_folderPath}/{plugin}"
|
2021-05-29 18:42:02 +00:00
|
|
|
|
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-05-29 18:42:02 +00:00
|
|
|
|
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-13 18:21:03 +00:00
|
|
|
latestVersion = getLatestPluginVersion(pluginId)
|
2021-03-12 00:39:39 +00:00
|
|
|
except TypeError:
|
|
|
|
continue
|
2021-03-13 18:21:03 +00:00
|
|
|
except ValueError:
|
|
|
|
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-03-12 00:39:39 +00:00
|
|
|
print(oColors.brightRed + "Couldn't find plugin id. Sorry :(" + oColors.standardWhite)
|
|
|
|
continue
|
2021-05-29 18:42:02 +00:00
|
|
|
|
2021-03-12 00:39:39 +00:00
|
|
|
if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
|
2021-03-13 18:21:03 +00:00
|
|
|
if INSTALLEDPLUGINLIST[i][3] == True:
|
2021-03-26 19:24:15 +00:00
|
|
|
print(f" [{indexNumberUpdated+1}]".rjust(6), end='')
|
|
|
|
print(" ", end='')
|
2021-03-21 13:30:27 +00:00
|
|
|
print(f"{fileName}".ljust(33), end='')
|
2021-03-27 17:58:16 +00:00
|
|
|
print(f"{fileVersion}".ljust(13), end='')
|
|
|
|
print(f"{latestVersion}".ljust(13))
|
2021-03-13 18:21:03 +00:00
|
|
|
|
2021-03-26 19:24:15 +00:00
|
|
|
if not configValues.localPluginFolder:
|
|
|
|
if configValues.sftp_seperateDownloadPath is True:
|
|
|
|
pluginPath = configValues.sftp_pathToSeperateDownloadPath
|
2021-03-14 19:21:26 +00:00
|
|
|
else:
|
2021-03-26 19:24:15 +00:00
|
|
|
pluginPath = configValues.sftp_folderPath
|
2021-03-16 00:04:13 +00:00
|
|
|
pluginPath = Path(f"{pluginPath}/{plugin}")
|
2021-03-13 18:21:03 +00:00
|
|
|
sftp = createSFTPConnection()
|
2021-03-14 19:21:26 +00:00
|
|
|
indexNumberUpdated += 1
|
2021-03-13 18:21:03 +00:00
|
|
|
pluginsUpdated += 1
|
2021-03-14 19:21:26 +00:00
|
|
|
try:
|
2021-03-26 19:24:15 +00:00
|
|
|
getSpecificPackage(pluginId, configValues.sftp_folderPath)
|
|
|
|
if configValues.sftp_seperateDownloadPath is False:
|
2021-03-14 19:21:26 +00:00
|
|
|
sftp.remove(pluginPath)
|
|
|
|
except HTTPError as err:
|
|
|
|
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
|
|
|
|
pluginsUpdated -= 1
|
|
|
|
except FileNotFoundError:
|
2021-03-16 00:04:13 +00:00
|
|
|
print(oColors.brightRed + "Error: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
2021-03-13 18:21:03 +00:00
|
|
|
else:
|
2021-03-26 19:24:15 +00:00
|
|
|
if configValues.seperateDownloadPath is True:
|
|
|
|
pluginPath = configValues.pathToSeperateDownloadPath
|
2021-03-14 12:25:13 +00:00
|
|
|
else:
|
2021-05-29 18:42:02 +00:00
|
|
|
pluginPath = pluginFolderPath
|
2021-03-16 00:04:13 +00:00
|
|
|
pluginPath = Path(f"{pluginPath}/{plugin}")
|
2021-03-14 19:21:26 +00:00
|
|
|
indexNumberUpdated += 1
|
2021-03-13 18:21:03 +00:00
|
|
|
pluginsUpdated += 1
|
2021-03-14 19:21:26 +00:00
|
|
|
try:
|
2021-05-29 18:42:02 +00:00
|
|
|
getSpecificPackage(pluginId, pluginFolderPath)
|
2021-03-26 19:24:15 +00:00
|
|
|
if configValues.seperateDownloadPath is False:
|
2021-03-14 19:21:26 +00:00
|
|
|
os.remove(pluginPath)
|
|
|
|
except HTTPError as err:
|
|
|
|
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
|
|
|
|
pluginsUpdated -= 1
|
|
|
|
except FileNotFoundError:
|
|
|
|
print(oColors.brightRed + f"Error: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
2021-03-13 18:21:03 +00:00
|
|
|
break
|
2021-03-10 01:05:56 +00:00
|
|
|
else:
|
2021-03-13 18:21:03 +00:00
|
|
|
print(f"{fileName} is already on {latestVersion}")
|
|
|
|
print(oColors.brightRed + "Aborting the update process."+ oColors.standardWhite)
|
|
|
|
break
|
2021-03-12 00:39:39 +00:00
|
|
|
|
|
|
|
if inputSelectedObject == 'all':
|
2021-03-13 18:21:03 +00:00
|
|
|
if INSTALLEDPLUGINLIST[i][3] == True:
|
2021-03-26 19:24:15 +00:00
|
|
|
print(f" [{indexNumberUpdated+1}]".rjust(6), end='')
|
|
|
|
print(" ", end='')
|
2021-03-21 13:30:27 +00:00
|
|
|
print(f"{fileName}".ljust(33), end='')
|
2021-03-27 17:58:16 +00:00
|
|
|
print(f"{fileVersion}".ljust(13), end='')
|
|
|
|
print(f"{latestVersion}".ljust(13))
|
2021-03-13 18:21:03 +00:00
|
|
|
|
2021-03-26 19:24:15 +00:00
|
|
|
if not configValues.localPluginFolder:
|
2021-03-30 21:55:04 +00:00
|
|
|
if configValues.sftp_useSftp:
|
|
|
|
if configValues.sftp_seperateDownloadPath is True:
|
|
|
|
pluginPath = configValues.sftp_pathToSeperateDownloadPath
|
|
|
|
else:
|
|
|
|
pluginPath = configValues.sftp_folderPath
|
|
|
|
pluginPath = f"{pluginPath}/{plugin}"
|
|
|
|
sftp = createSFTPConnection()
|
|
|
|
indexNumberUpdated += 1
|
|
|
|
pluginsUpdated += 1
|
|
|
|
try:
|
|
|
|
getSpecificPackage(pluginId, configValues.sftp_folderPath)
|
|
|
|
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 FileNotFoundError:
|
|
|
|
print(oColors.brightRed + f"FileNotFoundError: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
2021-03-14 12:25:13 +00:00
|
|
|
else:
|
2021-03-30 21:55:04 +00:00
|
|
|
if configValues.sftp_seperateDownloadPath is True:
|
|
|
|
pluginPath = configValues.sftp_pathToSeperateDownloadPath
|
|
|
|
else:
|
|
|
|
pluginPath = configValues.sftp_folderPath
|
|
|
|
pluginPath = f"{pluginPath}/{plugin}"
|
|
|
|
ftp = createFTPConnection()
|
|
|
|
indexNumberUpdated += 1
|
|
|
|
pluginsUpdated += 1
|
|
|
|
try:
|
|
|
|
getSpecificPackage(pluginId, configValues.sftp_folderPath)
|
|
|
|
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 FileNotFoundError:
|
|
|
|
print(oColors.brightRed + f"FileNotFoundError: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
2021-03-12 00:39:39 +00:00
|
|
|
|
|
|
|
else:
|
2021-03-26 19:24:15 +00:00
|
|
|
if configValues.seperateDownloadPath is True:
|
|
|
|
pluginPath = configValues.pathToSeperateDownloadPath
|
2021-03-14 12:25:13 +00:00
|
|
|
else:
|
2021-05-29 18:42:02 +00:00
|
|
|
pluginPath = pluginFolderPath
|
2021-03-16 00:04:13 +00:00
|
|
|
pluginPath = Path(f"{pluginPath}/{plugin}")
|
2021-03-14 19:21:26 +00:00
|
|
|
indexNumberUpdated += 1
|
2021-03-12 00:39:39 +00:00
|
|
|
pluginsUpdated += 1
|
2021-03-14 19:21:26 +00:00
|
|
|
try:
|
2021-05-29 18:42:02 +00:00
|
|
|
getSpecificPackage(pluginId, pluginFolderPath)
|
2021-03-26 19:24:15 +00:00
|
|
|
if configValues.seperateDownloadPath is False:
|
2021-03-14 19:21:26 +00:00
|
|
|
os.remove(pluginPath)
|
2021-03-31 16:11:41 +00:00
|
|
|
except HTTPError as err:
|
|
|
|
print(oColors.brightRed + f"HTTPError: {err.code} - {err.reason}" + oColors.standardWhite)
|
|
|
|
pluginsUpdated -= 1
|
2021-03-14 19:21:26 +00:00
|
|
|
except FileNotFoundError:
|
2021-03-30 21:55:04 +00:00
|
|
|
print(oColors.brightRed + f"FileNotFoundError: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
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-03-21 13:30:27 +00:00
|
|
|
print(oColors.brightRed + "Error occured: Aborted updating for plugins." + oColors.standardWhite)
|
2021-03-27 11:07:19 +00:00
|
|
|
print(oColors.brightYellow + f"Plugins updated: [{pluginsUpdated}/{i}]" + oColors.standardWhite)
|
2021-03-13 18:21:03 +00:00
|
|
|
if inputSelectedObject =='all' and pluginsUpdated == 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
|
|
|
|
|
|
|
|
for ressource in packageName:
|
|
|
|
if plugin_match_found == True:
|
2021-05-28 21:52:16 +00:00
|
|
|
continue
|
2021-05-14 22:46:29 +00:00
|
|
|
pID = ressource["id"]
|
|
|
|
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)
|
|
|
|
addToPluginList(pID, updateId, plugin_latest_version , plugin_is_outdated)
|
|
|
|
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:
|
|
|
|
pID = None
|
|
|
|
updateId = None
|
|
|
|
plugin_latest_version = None
|
|
|
|
plugin_is_outdated = None
|
|
|
|
addToPluginList(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
|