Better config handling & better output for serverjar

Changes:
- better config handling
- better output for serverjar checking
This commit is contained in:
Neocky
2021-03-27 12:07:19 +01:00
parent 17611c741e
commit fddc0c252c
9 changed files with 100 additions and 127 deletions

View File

@@ -6,7 +6,7 @@ from pathlib import Path
from utils.consoleoutput import oColors
from utils.web_request import doAPIRequest
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calculateFileSizeKb, calculateFileSizeMb
from handlers.handle_config import checkConfig, configurationValues
from handlers.handle_config import configurationValues
from handlers.handle_sftp import sftp_upload_file, sftp_cdPluginDir, createSFTPConnection
@@ -51,6 +51,7 @@ def getVersionName(packageId, versionId):
def searchPackage(ressourceName):
configValues = configurationValues()
url = f"https://api.spiget.org/v2/search/resources/{ressourceName}?field=name&sort=-downloads"
packageName = doAPIRequest(url)
i = 1
@@ -71,14 +72,14 @@ def searchPackage(ressourceName):
if ressourceSelected != 0:
ressourceSelected = ressourceSelected - 1
ressourceId = packageName[ressourceSelected]["id"]
if not checkConfig().localPluginFolder:
if not configValues.localPluginFolder:
try:
getSpecificPackage(ressourceId, checkConfig().sftp_folderPath)
getSpecificPackage(ressourceId, configValues.sftp_folderPath)
except HTTPError as err:
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
else:
try:
getSpecificPackage(ressourceId, checkConfig().pathToPluginFolder)
getSpecificPackage(ressourceId, configValues.pathToPluginFolder)
except HTTPError as err:
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
@@ -109,7 +110,8 @@ def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'):
def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
if checkConfig().localPluginFolder == False:
configValues = configurationValues()
if configValues.localPluginFolder == False:
downloadPath = createTempPluginFolder()
url = f"https://api.spiget.org/v2/resources/{ressourceId}"
packageDetails = doAPIRequest(url)
@@ -119,13 +121,13 @@ def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
packageVersion = getVersionName(ressourceId, versionId)
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
downloadPackagePath = Path(f"{downloadPath}/{packageDownloadName}")
if checkConfig().localPluginFolder:
if configValues.localPluginFolder:
if inputPackageVersion is None or inputPackageVersion == 'latest':
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)
else:
downloadSpecificVersion(ressourceId, downloadPackagePath, versionId)
if not checkConfig().localPluginFolder:
if not configValues.localPluginFolder:
if inputPackageVersion is None or inputPackageVersion == 'latest':
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)
deleteTempPluginFolder(downloadPath)

View File

@@ -3,18 +3,19 @@ import re
from pathlib import Path
from utils.consoleoutput import oColors
from handlers.handle_config import checkConfig
from handlers.handle_config import configurationValues
from handlers.handle_sftp import createSFTPConnection, sftp_listAll
from plugin.plugin_updatechecker import getFileName, getFileVersion, getInstalledPlugin, createPluginList
def removePlugin(pluginToRemove):
configValues = configurationValues()
createPluginList()
if not checkConfig().localPluginFolder:
if not configValues.localPluginFolder:
sftp = createSFTPConnection()
pluginList = sftp_listAll(sftp)
else:
pluginList = os.listdir(checkConfig().pathToPluginFolder)
pluginList = os.listdir(configValues.pathToPluginFolder)
i = 0
try:
for plugin in pluginList:
@@ -28,8 +29,8 @@ def removePlugin(pluginToRemove):
if pluginToRemove == pluginIdStr or re.search(pluginToRemove, fileName, re.IGNORECASE):
print(f"Removing: {fileName}")
if not checkConfig().localPluginFolder:
pluginPath = checkConfig().sftp_folderPath
if not configValues.localPluginFolder:
pluginPath = configValues.sftp_folderPath
pluginPath = f"{pluginPath}/{plugin}"
sftp = createSFTPConnection()
sftp.remove(pluginPath)
@@ -37,7 +38,7 @@ def removePlugin(pluginToRemove):
i += 1
break
else:
pluginPath = checkConfig().pathToPluginFolder
pluginPath = configValues.pathToPluginFolder
pluginPath = Path(f"{pluginPath}/{plugin}")
os.remove(pluginPath)
print(f"Removed: {fileName}")

View File

@@ -8,7 +8,7 @@ from rich.progress import track
from utils.consoleoutput import oColors
from utils.web_request import doAPIRequest
from handlers.handle_config import checkConfig, configurationValues
from handlers.handle_config import configurationValues
from handlers.handle_sftp import createSFTPConnection, sftp_listAll
from plugin.plugin_downloader import getSpecificPackage
@@ -64,10 +64,11 @@ def compareVersions(plugin_latest_version, pluginVersion):
def eggCrackingJar(localJarFileName):
if not checkConfig().localPluginFolder:
pluginPath = checkConfig().sftp_folderPath
configValues = configurationValues()
if not configValues.localPluginFolder:
pluginPath = configValues.sftp_folderPath
else:
pluginPath = checkConfig().pathToPluginFolder
pluginPath = configValues.pathToPluginFolder
pathToPluginJar = Path(f"{pluginPath}/{localJarFileName}")
pluginVersion = ''
with ZipFile(pathToPluginJar, 'r') as pluginJar:
@@ -139,8 +140,8 @@ def checkInstalledPackage(inputSelectedObject="all"):
print(" ", end='')
print(f"{fileName}".ljust(33), end='')
print(f"{fileVersion}".ljust(15), end='')
print(f"{pluginLatestVersion}".ljust(14), end='')
print(f" {pluginIsOutdated}".ljust(5) + oColors.standardWhite)
print(f"{pluginLatestVersion}".ljust(15), end='')
print(f"{pluginIsOutdated}".ljust(5) + oColors.standardWhite)
break
else:
if pluginLatestVersion == 'N/A':
@@ -150,8 +151,8 @@ def checkInstalledPackage(inputSelectedObject="all"):
print(" ", end='')
print(f"{fileName}".ljust(33), end='')
print(f"{fileVersion}".ljust(15), end='')
print(f"{pluginLatestVersion}".ljust(14), end='')
print(f" {pluginIsOutdated}".ljust(5) + oColors.standardWhite)
print(f"{pluginLatestVersion}".ljust(15), end='')
print(f"{pluginIsOutdated}".ljust(5) + oColors.standardWhite)
i += 1
except TypeError:
@@ -290,7 +291,7 @@ def updateInstalledPackage(inputSelectedObject='all'):
i = i + 1
except TypeError:
print(oColors.brightRed + "Error occured: Aborted updating for plugins." + oColors.standardWhite)
print(oColors.brightYellow + f"[{pluginsUpdated}/{i}] Plugins updated" + oColors.standardWhite)
print(oColors.brightYellow + f"Plugins updated: [{pluginsUpdated}/{i}]" + oColors.standardWhite)
if inputSelectedObject =='all' and pluginsUpdated == 0:
print(oColors.brightGreen + "All found plugins are on the latest version!" + oColors.standardWhite)