From 17611c741ef3e8a1b15520eb06099fd86414704b Mon Sep 17 00:00:00 2001 From: Neocky Date: Fri, 26 Mar 2021 20:24:15 +0100 Subject: [PATCH 1/3] Better output & first part of new config handling Changes: - better output when downloading files - optimization when getting values from the config --- src/__main__.py | 6 +- src/handlers/handle_config.py | 94 +++++++++++++++++++++--------- src/plugin/plugin_downloader.py | 24 ++++---- src/plugin/plugin_updatechecker.py | 88 +++++++++++++++------------- src/utils/utilities.py | 8 ++- 5 files changed, 133 insertions(+), 87 deletions(-) diff --git a/src/__main__.py b/src/__main__.py index 77a4580..8abf093 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -1,14 +1,14 @@ from utils.consoleoutput import consoleTitle, clearConsole, printMainMenu from utils.utilities import check_requirements from handlers.handle_input import createInputLists, getInput -from handlers.handle_config import checkConfig +from handlers.handle_config import checkConfig, configurationValues def mainFunction(): consoleTitle() clearConsole() - checkConfig() - check_requirements() + #checkConfig() + #check_requirements() createInputLists() printMainMenu() getInput() diff --git a/src/handlers/handle_config.py b/src/handlers/handle_config.py index 94e318a..f048683 100644 --- a/src/handlers/handle_config.py +++ b/src/handlers/handle_config.py @@ -6,6 +6,42 @@ from pathlib import Path from utils.consoleoutput import oColors +class configurationValues: + def __init__(self): + config = configparser.ConfigParser() + config.sections() + config.read("config.ini") + localPluginFolder = config['General']['LocalPluginFolder'] + self.pathToPluginFolder = Path(config['General']['PathToPluginFolder']) + seperateDownloadPath = config['General']['SeperateDownloadPath'] + self.pathToSeperateDownloadPath = Path(config['General']['PathToSeperateDownloadPath']) + + self.sftp_server = config['SFTP - Remote Server']['Server'] + self.sftp_user = config['SFTP - Remote Server']['Username'] + self.sftp_password = config['SFTP - Remote Server']['Password'] + sftp_port = config['SFTP - Remote Server']['Port'] + self.sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer'] + sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath'] + self.sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath'] + + self.sftp_port = int(sftp_port) + if localPluginFolder == 'True': + self.localPluginFolder = True + else: + self.localPluginFolder = False + + if seperateDownloadPath == 'True': + self.seperateDownloadPath = True + else: + self.seperateDownloadPath = False + + if sftp_seperateDownloadPath == 'True': + self.sftp_seperateDownloadPath = True + else: + self.sftp_seperateDownloadPath = False + + + def checkConfig(): currentFolder = os.getcwd() configAvailable = os.path.isfile("config.ini") @@ -16,41 +52,41 @@ def checkConfig(): input("Press any key + enter to exit...") sys.exit() - class configValues: - config = configparser.ConfigParser() - config.sections() - config.read("config.ini") - localPluginFolder = config['General']['LocalPluginFolder'] - pathToPluginFolder = Path(config['General']['PathToPluginFolder']) - seperateDownloadPath = config['General']['SeperateDownloadPath'] - pathToSeperateDownloadPath = Path(config['General']['PathToSeperateDownloadPath']) + #class configValues: + # config = configparser.ConfigParser() + # config.sections() + # config.read("config.ini") + # localPluginFolder = config['General']['LocalPluginFolder'] + # pathToPluginFolder = Path(config['General']['PathToPluginFolder']) + # seperateDownloadPath = config['General']['SeperateDownloadPath'] + # pathToSeperateDownloadPath = Path(config['General']['PathToSeperateDownloadPath']) - sftp_server = config['SFTP - Remote Server']['Server'] - sftp_user = config['SFTP - Remote Server']['Username'] - sftp_password = config['SFTP - Remote Server']['Password'] - sftp_port = config['SFTP - Remote Server']['Port'] - sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer'] - sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath'] - sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath'] + # sftp_server = config['SFTP - Remote Server']['Server'] + # sftp_user = config['SFTP - Remote Server']['Username'] + # sftp_password = config['SFTP - Remote Server']['Password'] + # sftp_port = config['SFTP - Remote Server']['Port'] + # sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer'] + # sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath'] + # sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath'] - sftp_port = int(sftp_port) - if localPluginFolder == 'True': - localPluginFolder = True - else: - localPluginFolder = False + # sftp_port = int(sftp_port) + # if localPluginFolder == 'True': + # localPluginFolder = True + # else: + # localPluginFolder = False - if seperateDownloadPath == 'True': - seperateDownloadPath = True - else: - seperateDownloadPath = False + # if seperateDownloadPath == 'True': + # seperateDownloadPath = True + # else: + # seperateDownloadPath = False - if sftp_seperateDownloadPath == 'True': - sftp_seperateDownloadPath = True - else: - sftp_seperateDownloadPath = False + # if sftp_seperateDownloadPath == 'True': + # sftp_seperateDownloadPath = True + # else: + # sftp_seperateDownloadPath = False os.chdir(currentFolder) - return configValues + #return configValues def createConfig(): diff --git a/src/plugin/plugin_downloader.py b/src/plugin/plugin_downloader.py index 382438f..a0497c9 100644 --- a/src/plugin/plugin_downloader.py +++ b/src/plugin/plugin_downloader.py @@ -5,18 +5,11 @@ from pathlib import Path from utils.consoleoutput import oColors from utils.web_request import doAPIRequest -from utils.utilities import createTempPluginFolder, deleteTempPluginFolder -from handlers.handle_config import checkConfig +from utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calculateFileSizeKb, calculateFileSizeMb +from handlers.handle_config import checkConfig, configurationValues from handlers.handle_sftp import sftp_upload_file, sftp_cdPluginDir, createSFTPConnection -def calculateFileSize(downloadFileSize): - fileSizeDownload = int(downloadFileSize) - fileSizeKb = fileSizeDownload / 1024 - roundedFileSize = round(fileSizeKb, 2) - return roundedFileSize - - def handleRegexPackageName(packageNameFull): packageNameFull2 = packageNameFull # trims the part of the package that has for example "[1.1 Off]" in it @@ -102,10 +95,15 @@ def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'): remotefile = urllib.request.urlopen(url) filesize = remotefile.info()['Content-Length'] urllib.request.urlretrieve(url, downloadPath) - filesizeData = calculateFileSize(filesize) - print(f"Downloadsize: {filesizeData} KB") - print(f"File downloaded here: {downloadPath}") - if not checkConfig().localPluginFolder: + filesize = int(filesize) + print(" ", end='') + if filesize >= 1000000: + filesizeData = calculateFileSizeMb(filesize) + print("Downloaded " + (str(filesizeData)).rjust(9) + f" MB here {downloadPath}") + else: + filesizeData = calculateFileSizeKb(filesize) + print("Downloaded " + (str(filesizeData)).rjust(9) + f" KB here {downloadPath}") + if not configurationValues.localPluginFolder: sftpSession = createSFTPConnection() sftp_upload_file(sftpSession, downloadPath) diff --git a/src/plugin/plugin_updatechecker.py b/src/plugin/plugin_updatechecker.py index c775dc1..240e6f0 100644 --- a/src/plugin/plugin_updatechecker.py +++ b/src/plugin/plugin_updatechecker.py @@ -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 +from handlers.handle_config import checkConfig, configurationValues from handlers.handle_sftp import createSFTPConnection, sftp_listAll from plugin.plugin_downloader import getSpecificPackage @@ -86,18 +86,19 @@ def eggCrackingJar(localJarFileName): def checkInstalledPackage(inputSelectedObject="all"): + 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 - oldPackages = 0 + oldPlugins = 0 print(oColors.brightBlack + f"Checking: {inputSelectedObject}" + oColors.standardWhite) - print("┌─────┬────────────────────────────────┬──────────────┬───────────┬───────────────────┐") - print("│ No. │ Name │ Installed V. │ Latest V. │ Update available │") - print("└─────┴────────────────────────────────┴──────────────┴───────────┴───────────────────┘") + print("┌─────┬────────────────────────────────┬──────────────┬──────────────┬───────────────────┐") + print("│ No. │ Name │ Installed V. │ Latest V. │ Update available │") + print("└─────┴────────────────────────────────┴──────────────┴──────────────┴───────────────────┘") try: for plugin in track(pluginList, description="Checking for updates" ,transient=True, complete_style="cyan"): try: @@ -127,42 +128,45 @@ def checkInstalledPackage(inputSelectedObject="all"): pluginIsOutdated = 'N/A' if pluginIsOutdated == True: - oldPackages = oldPackages + 1 + oldPlugins = oldPlugins + 1 if inputSelectedObject != "*" and inputSelectedObject != "all": if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE): if pluginLatestVersion == 'N/A': - print(oColors.brightBlack + f" [{1}]".ljust(8), end='') + print(oColors.brightBlack + f" [{1}]".rjust(6), end='') else: - print(f" [{1}]".ljust(8), end='') + print(f" [{1}]".rjust(6), end='') + print(" ", end='') print(f"{fileName}".ljust(33), end='') print(f"{fileVersion}".ljust(15), end='') - print(f"{pluginLatestVersion}".ljust(12), end='') + print(f"{pluginLatestVersion}".ljust(14), end='') print(f" {pluginIsOutdated}".ljust(5) + oColors.standardWhite) break else: if pluginLatestVersion == 'N/A': - print(oColors.brightBlack + f" [{i+1}]".ljust(8), end='') + print(oColors.brightBlack + f" [{i+1}]".rjust(6), end='') else: - print(f" [{i+1}]".ljust(8), end='') + print(f" [{i+1}]".rjust(6), end='') + print(" ", end='') print(f"{fileName}".ljust(33), end='') print(f"{fileVersion}".ljust(15), end='') - print(f"{pluginLatestVersion}".ljust(12), end='') + print(f"{pluginLatestVersion}".ljust(14), end='') print(f" {pluginIsOutdated}".ljust(5) + oColors.standardWhite) i += 1 except TypeError: print(oColors.brightRed + "Error occured: Aborted checking for updates." + oColors.standardWhite) - print(oColors.brightYellow + f"Old packages: [{oldPackages}/{i}]" + oColors.standardWhite) + print(oColors.brightYellow + f"Outdated plugins: [{oldPlugins}/{i}]" + oColors.standardWhite) def updateInstalledPackage(inputSelectedObject='all'): + 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 pluginsUpdated = 0 indexNumberUpdated = 0 @@ -189,24 +193,25 @@ def updateInstalledPackage(inputSelectedObject='all'): continue if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE): if INSTALLEDPLUGINLIST[i][3] == True: - print(f" [{indexNumberUpdated+1}]".ljust(8), end='') + print(f" [{indexNumberUpdated+1}]".rjust(6), end='') + print(" ", end='') print(f"{fileName}".ljust(33), end='') print(f"{fileVersion}".ljust(8), end='') print(" ", end='') print(f"{latestVersion}".ljust(8)) - if not checkConfig().localPluginFolder: - if checkConfig().sftp_seperateDownloadPath is True: - pluginPath = checkConfig().sftp_pathToSeperateDownloadPath + if not configValues.localPluginFolder: + if configValues.sftp_seperateDownloadPath is True: + pluginPath = configValues.sftp_pathToSeperateDownloadPath else: - pluginPath = checkConfig().sftp_folderPath + pluginPath = configValues.sftp_folderPath pluginPath = Path(f"{pluginPath}/{plugin}") sftp = createSFTPConnection() indexNumberUpdated += 1 pluginsUpdated += 1 try: - getSpecificPackage(pluginId, checkConfig().sftp_folderPath) - if checkConfig().sftp_seperateDownloadPath is False: + getSpecificPackage(pluginId, configValues.sftp_folderPath) + if configValues.sftp_seperateDownloadPath is False: sftp.remove(pluginPath) except HTTPError as err: print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite) @@ -214,16 +219,16 @@ def updateInstalledPackage(inputSelectedObject='all'): except FileNotFoundError: print(oColors.brightRed + "Error: Old plugin file coulnd't be deleted" + oColors.standardWhite) else: - if checkConfig().seperateDownloadPath is True: - pluginPath = checkConfig().pathToSeperateDownloadPath + if configValues.seperateDownloadPath is True: + pluginPath = configValues.pathToSeperateDownloadPath else: - pluginPath = checkConfig().pathToPluginFolder + pluginPath = configValues.pathToPluginFolder pluginPath = Path(f"{pluginPath}/{plugin}") indexNumberUpdated += 1 pluginsUpdated += 1 try: - getSpecificPackage(pluginId, checkConfig().pathToPluginFolder) - if checkConfig().seperateDownloadPath is False: + getSpecificPackage(pluginId, configValues.pathToPluginFolder) + if configValues.seperateDownloadPath is False: os.remove(pluginPath) except HTTPError as err: print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite) @@ -238,24 +243,25 @@ def updateInstalledPackage(inputSelectedObject='all'): if inputSelectedObject == 'all': if INSTALLEDPLUGINLIST[i][3] == True: - print(f" [{indexNumberUpdated+1}]".ljust(8), end='') + print(f" [{indexNumberUpdated+1}]".rjust(6), end='') + print(" ", end='') print(f"{fileName}".ljust(33), end='') print(f"{fileVersion}".ljust(8), end='') print(" ", end='') print(f"{latestVersion}".ljust(8)) - if not checkConfig().localPluginFolder: - if checkConfig().sftp_seperateDownloadPath is True: - pluginPath = checkConfig().sftp_pathToSeperateDownloadPath + if not configValues.localPluginFolder: + if configValues.sftp_seperateDownloadPath is True: + pluginPath = configValues.sftp_pathToSeperateDownloadPath else: - pluginPath = checkConfig().sftp_folderPath + pluginPath = configValues.sftp_folderPath pluginPath = f"{pluginPath}/{plugin}" sftp = createSFTPConnection() indexNumberUpdated += 1 pluginsUpdated += 1 try: - getSpecificPackage(pluginId, checkConfig().sftp_folderPath) - if checkConfig().sftp_seperateDownloadPath is False: + getSpecificPackage(pluginId, configValues.sftp_folderPath) + if configValues.sftp_seperateDownloadPath is False: sftp.remove(pluginPath) except HTTPError as err: print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite) @@ -264,16 +270,16 @@ def updateInstalledPackage(inputSelectedObject='all'): print(oColors.brightRed + f"Error: Old plugin file coulnd't be deleted" + oColors.standardWhite) else: - if checkConfig().seperateDownloadPath is True: - pluginPath = checkConfig().pathToSeperateDownloadPath + if configValues.seperateDownloadPath is True: + pluginPath = configValues.pathToSeperateDownloadPath else: - pluginPath = checkConfig().pathToPluginFolder + pluginPath = configValues.pathToPluginFolder pluginPath = Path(f"{pluginPath}/{plugin}") indexNumberUpdated += 1 pluginsUpdated += 1 try: - getSpecificPackage(pluginId, checkConfig().pathToPluginFolder) - if checkConfig().seperateDownloadPath is False: + getSpecificPackage(pluginId, configValues.pathToPluginFolder) + if configValues.seperateDownloadPath is False: os.remove(pluginPath) except HTTPError as err: print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite) diff --git a/src/utils/utilities.py b/src/utils/utilities.py index a1a4ce8..a65f91c 100644 --- a/src/utils/utilities.py +++ b/src/utils/utilities.py @@ -6,7 +6,7 @@ import requests from pathlib import Path from utils.consoleoutput import oColors -from handlers.handle_config import checkConfig +from handlers.handle_config import checkConfig, configurationValues from handlers.handle_sftp import createSFTPConnection @@ -160,3 +160,9 @@ def calculateFileSizeMb(downloadFileSize): fileSizeMb = fileSizeDownload / 1024 / 1024 roundedFileSize = round(fileSizeMb, 2) return roundedFileSize + +def calculateFileSizeKb(downloadFileSize): + fileSizeDownload = int(downloadFileSize) + fileSizeKb = fileSizeDownload / 1024 + roundedFileSize = round(fileSizeKb, 2) + return roundedFileSize \ No newline at end of file From fddc0c252c8572a6e5dccad7f442eea48a769222 Mon Sep 17 00:00:00 2001 From: Neocky Date: Sat, 27 Mar 2021 12:07:19 +0100 Subject: [PATCH 2/3] Better config handling & better output for serverjar Changes: - better config handling - better output for serverjar checking --- src/__main__.py | 6 +- src/handlers/handle_config.py | 95 +++++++++--------------------- src/handlers/handle_input.py | 17 +++--- src/plugin/plugin_downloader.py | 16 ++--- src/plugin/plugin_remover.py | 13 ++-- src/plugin/plugin_updatechecker.py | 19 +++--- src/serverjar/serverjar_checker.py | 20 ++++--- src/serverjar/serverjar_paper.py | 27 +++++---- src/utils/utilities.py | 14 +++-- 9 files changed, 100 insertions(+), 127 deletions(-) diff --git a/src/__main__.py b/src/__main__.py index 8abf093..77a4580 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -1,14 +1,14 @@ from utils.consoleoutput import consoleTitle, clearConsole, printMainMenu from utils.utilities import check_requirements from handlers.handle_input import createInputLists, getInput -from handlers.handle_config import checkConfig, configurationValues +from handlers.handle_config import checkConfig def mainFunction(): consoleTitle() clearConsole() - #checkConfig() - #check_requirements() + checkConfig() + check_requirements() createInputLists() printMainMenu() getInput() diff --git a/src/handlers/handle_config.py b/src/handlers/handle_config.py index f048683..16ed848 100644 --- a/src/handlers/handle_config.py +++ b/src/handlers/handle_config.py @@ -7,43 +7,41 @@ from utils.consoleoutput import oColors class configurationValues: - def __init__(self): - config = configparser.ConfigParser() - config.sections() - config.read("config.ini") - localPluginFolder = config['General']['LocalPluginFolder'] - self.pathToPluginFolder = Path(config['General']['PathToPluginFolder']) - seperateDownloadPath = config['General']['SeperateDownloadPath'] - self.pathToSeperateDownloadPath = Path(config['General']['PathToSeperateDownloadPath']) + config = configparser.ConfigParser() + config.sections() + config.read("config.ini") + localPluginFolder = config['General']['LocalPluginFolder'] + pathToPluginFolder = Path(config['General']['PathToPluginFolder']) + seperateDownloadPath = config['General']['SeperateDownloadPath'] + pathToSeperateDownloadPath = Path(config['General']['PathToSeperateDownloadPath']) - self.sftp_server = config['SFTP - Remote Server']['Server'] - self.sftp_user = config['SFTP - Remote Server']['Username'] - self.sftp_password = config['SFTP - Remote Server']['Password'] - sftp_port = config['SFTP - Remote Server']['Port'] - self.sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer'] - sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath'] - self.sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath'] + sftp_server = config['SFTP - Remote Server']['Server'] + sftp_user = config['SFTP - Remote Server']['Username'] + sftp_password = config['SFTP - Remote Server']['Password'] + sftp_port = config['SFTP - Remote Server']['Port'] + sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer'] + sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath'] + sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath'] - self.sftp_port = int(sftp_port) - if localPluginFolder == 'True': - self.localPluginFolder = True - else: - self.localPluginFolder = False + sftp_port = int(sftp_port) + if localPluginFolder == 'True': + localPluginFolder = True + else: + localPluginFolder = False - if seperateDownloadPath == 'True': - self.seperateDownloadPath = True - else: - self.seperateDownloadPath = False - - if sftp_seperateDownloadPath == 'True': - self.sftp_seperateDownloadPath = True - else: - self.sftp_seperateDownloadPath = False + if seperateDownloadPath == 'True': + seperateDownloadPath = True + else: + seperateDownloadPath = False + if sftp_seperateDownloadPath == 'True': + sftp_seperateDownloadPath = True + else: + sftp_seperateDownloadPath = False def checkConfig(): - currentFolder = os.getcwd() + #currentFolder = os.getcwd() configAvailable = os.path.isfile("config.ini") if not configAvailable: @@ -51,42 +49,7 @@ def checkConfig(): print(oColors.brightRed + "Config created. Edit config before executing again!" + oColors.standardWhite) input("Press any key + enter to exit...") sys.exit() - - #class configValues: - # config = configparser.ConfigParser() - # config.sections() - # config.read("config.ini") - # localPluginFolder = config['General']['LocalPluginFolder'] - # pathToPluginFolder = Path(config['General']['PathToPluginFolder']) - # seperateDownloadPath = config['General']['SeperateDownloadPath'] - # pathToSeperateDownloadPath = Path(config['General']['PathToSeperateDownloadPath']) - - # sftp_server = config['SFTP - Remote Server']['Server'] - # sftp_user = config['SFTP - Remote Server']['Username'] - # sftp_password = config['SFTP - Remote Server']['Password'] - # sftp_port = config['SFTP - Remote Server']['Port'] - # sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer'] - # sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath'] - # sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath'] - - # sftp_port = int(sftp_port) - # if localPluginFolder == 'True': - # localPluginFolder = True - # else: - # localPluginFolder = False - - # if seperateDownloadPath == 'True': - # seperateDownloadPath = True - # else: - # seperateDownloadPath = False - - # if sftp_seperateDownloadPath == 'True': - # sftp_seperateDownloadPath = True - # else: - # sftp_seperateDownloadPath = False - - os.chdir(currentFolder) - #return configValues + #os.chdir(currentFolder) def createConfig(): diff --git a/src/handlers/handle_input.py b/src/handlers/handle_input.py index 8a418de..4108b1e 100644 --- a/src/handlers/handle_input.py +++ b/src/handlers/handle_input.py @@ -2,7 +2,7 @@ import sys from utils.consoleoutput import oColors from utils.utilities import getHelp, getCommandHelp -from handlers.handle_config import checkConfig +from handlers.handle_config import configurationValues from plugin.plugin_downloader import searchPackage, getSpecificPackage from plugin.plugin_updatechecker import updateInstalledPackage, checkInstalledPackage from plugin.plugin_remover import removePlugin @@ -30,21 +30,22 @@ def createInputLists(): def handleInput(inputCommand, inputSelectedObject, inputParams): + configValues = configurationValues() while True: if inputCommand == 'get': if inputSelectedObject.isdigit(): - if not checkConfig().localPluginFolder: - if checkConfig().sftp_seperateDownloadPath is True: - pluginPath = checkConfig().sftp_pathToSeperateDownloadPath + if not configValues.localPluginFolder: + if configValues.sftp_seperateDownloadPath is True: + pluginPath = configValues.sftp_pathToSeperateDownloadPath else: - pluginPath = checkConfig().sftp_folderPath + pluginPath = configValues.sftp_folderPath getSpecificPackage(inputSelectedObject, pluginPath, inputParams) break else: - if checkConfig().seperateDownloadPath is True: - pluginPath = checkConfig().pathToSeperateDownloadPath + if configValues.seperateDownloadPath is True: + pluginPath = configValues.pathToSeperateDownloadPath else: - pluginPath = checkConfig().pathToPluginFolder + pluginPath = configValues.pathToPluginFolder getSpecificPackage(inputSelectedObject, pluginPath, inputParams) break else: diff --git a/src/plugin/plugin_downloader.py b/src/plugin/plugin_downloader.py index a0497c9..e28a4eb 100644 --- a/src/plugin/plugin_downloader.py +++ b/src/plugin/plugin_downloader.py @@ -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) diff --git a/src/plugin/plugin_remover.py b/src/plugin/plugin_remover.py index b9019f8..1367822 100644 --- a/src/plugin/plugin_remover.py +++ b/src/plugin/plugin_remover.py @@ -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}") diff --git a/src/plugin/plugin_updatechecker.py b/src/plugin/plugin_updatechecker.py index 240e6f0..a02e949 100644 --- a/src/plugin/plugin_updatechecker.py +++ b/src/plugin/plugin_updatechecker.py @@ -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) diff --git a/src/serverjar/serverjar_checker.py b/src/serverjar/serverjar_checker.py index d018600..0f6ab86 100644 --- a/src/serverjar/serverjar_checker.py +++ b/src/serverjar/serverjar_checker.py @@ -4,17 +4,18 @@ from urllib.error import HTTPError from pathlib import Path from handlers.handle_sftp import createSFTPConnection, sftp_listFilesInServerRoot -from handlers.handle_config import checkConfig +from handlers.handle_config import configurationValues from utils.consoleoutput import oColors from serverjar.serverjar_paper import paperCheckForUpdate, papermc_downloader def checkInstalledServerjar(): - if not checkConfig().localPluginFolder: + configValues = configurationValues() + if not configValues.localPluginFolder: sftp = createSFTPConnection() serverRootList = sftp_listFilesInServerRoot(sftp) else: - serverRootList = os.path.dirname(checkConfig().pathToPluginFolder) + serverRootList = os.path.dirname(configValues.pathToPluginFolder) serverRootList = os.listdir(serverRootList) installedServerjarFullName = None try: @@ -34,7 +35,7 @@ def checkInstalledServerjar(): print(oColors.brightRed + "Aborting the process." + oColors.standardWhite) input("Press any key + enter to exit...") sys.exit() - + print(oColors.brightBlack + f"Checking: {installedServerjarFullName}" + oColors.standardWhite) if 'paper' in installedServerjarFullName: paperCheckForUpdate(installedServerjarFullName) @@ -44,19 +45,20 @@ def checkInstalledServerjar(): def updateServerjar(serverJarBuild='latest'): + configValues = configurationValues() try: if serverJarBuild == None: serverJarBuild = 'latest' - if not checkConfig().localPluginFolder: + if not configValues.localPluginFolder: sftp = createSFTPConnection() - serverRootPath = checkConfig().sftp_folderPath + serverRootPath = configValues.sftp_folderPath serverRootPath = Path(str(serverRootPath).replace(r'/plugins', '')) serverRootList = sftp_listFilesInServerRoot(sftp) else: - serverRoot = os.path.dirname(checkConfig().pathToPluginFolder) + serverRoot = os.path.dirname(configValues.pathToPluginFolder) serverRootList = os.listdir(serverRoot) - serverRootPath = checkConfig().pathToPluginFolder + serverRootPath = configValues.pathToPluginFolder helpPath = Path('/plugins') helpPathstr = str(helpPath) serverRootPath = Path(str(serverRootPath).replace(helpPathstr, '')) @@ -91,7 +93,7 @@ def updateServerjar(serverJarBuild='latest'): if 'paper' in installedServerjarFullName: print(f"Updating Paper to build: {serverJarBuild}") - if not checkConfig().localPluginFolder: + if not configValues.localPluginFolder: try: papermc_downloader(serverJarBuild, installedServerjarFullName) sftp.remove(serverJarPath) diff --git a/src/serverjar/serverjar_paper.py b/src/serverjar/serverjar_paper.py index 2b43734..67dbde3 100644 --- a/src/serverjar/serverjar_paper.py +++ b/src/serverjar/serverjar_paper.py @@ -7,7 +7,7 @@ from pathlib import Path from utils.consoleoutput import oColors from utils.web_request import doAPIRequest from handlers.handle_sftp import sftp_upload_server_jar, sftp_cdPluginDir, createSFTPConnection -from handlers.handle_config import checkConfig +from handlers.handle_config import configurationValues from utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calculateFileSizeMb @@ -107,23 +107,24 @@ def paperCheckForUpdate(installedServerjarFullName): paperLatestBuild = findLatestBuild(versionGroup) paperVersionBehind = versionBehind(paperInstalledBuild, paperLatestBuild) - print(f"Paper for {mcVersion}") - print("Index | Name | Installed V. | Latest V. | Versions behind ") - print(f" [1]".ljust(8), end='') - print(f"paper".ljust(21), end='') - print(f"{paperInstalledBuild}".ljust(8), end='') - print(" ", end='') - print(f"{paperLatestBuild}".ljust(8), end='') - print(" ", end='') + print("┌─────┬────────────────────────────────┬──────────────┬──────────────┬───────────────────┐") + print("│ No. │ Name │ Installed V. │ Latest V. │ Versions behind │") + print("└─────┴────────────────────────────────┴──────────────┴──────────────┴───────────────────┘") + print(" [1]".rjust(6), end='') + print(" ", end='') + print("paper".ljust(33), end='') + print(f"{paperInstalledBuild}".ljust(15), end='') + print(f"{paperLatestBuild}".ljust(15), end='') print(f"{paperVersionBehind}".ljust(8)) # https://papermc.io/api/docs/swagger-ui/index.html?configUrl=/api/openapi/swagger-config#/ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersion=None): - if checkConfig().localPluginFolder == False: + configValues = configurationValues() + if configValues.localPluginFolder == False: downloadPath = createTempPluginFolder() else: - downloadPath = checkConfig().pathToPluginFolder + downloadPath = configValues.pathToPluginFolder helpPath = Path('/plugins') helpPathstr = str(helpPath) downloadPath = Path(str(downloadPath).replace(helpPathstr, '')) @@ -149,7 +150,7 @@ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersi downloadPackagePath = Path(f"{downloadPath}/{downloadFileName}") - if checkConfig().localPluginFolder == False: + if configValues.localPluginFolder == False: downloadPath = createTempPluginFolder() url = f"https://papermc.io/api/v2/projects/paper/versions/{mcVersion}/builds/{paperBuild}/downloads/{downloadFileName}" @@ -161,7 +162,7 @@ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersi print(f"Downloadsize: {filesizeData} MB") print(f"File downloaded here: {downloadPackagePath}") - if not checkConfig().localPluginFolder: + if not configValues.localPluginFolder: sftpSession = createSFTPConnection() sftp_upload_server_jar(sftpSession, downloadPackagePath) deleteTempPluginFolder(downloadPath) diff --git a/src/utils/utilities.py b/src/utils/utilities.py index a65f91c..4dcf20b 100644 --- a/src/utils/utilities.py +++ b/src/utils/utilities.py @@ -6,7 +6,7 @@ import requests from pathlib import Path from utils.consoleoutput import oColors -from handlers.handle_config import checkConfig, configurationValues +from handlers.handle_config import configurationValues from handlers.handle_sftp import createSFTPConnection @@ -95,11 +95,12 @@ def getCommandHelp(optionalParams): def check_local_plugin_folder(): - if checkConfig().localPluginFolder: - if checkConfig().seperateDownloadPath: - pluginFolderPath = checkConfig().pathToSeperateDownloadPath + configValues = configurationValues() + if configValues.localPluginFolder: + if configValues.seperateDownloadPath: + pluginFolderPath = configValues.pathToSeperateDownloadPath else: - pluginFolderPath = checkConfig().pathToPluginFolder + pluginFolderPath = configValues.pathToPluginFolder if not os.path.isdir(pluginFolderPath): print(oColors.brightRed + "Plugin folder coulnd*t be found. Creating one..." + oColors.standardWhite) @@ -129,9 +130,10 @@ def apiTest(): def check_requirements(): + configValues = configurationValues() apiTest() check_local_plugin_folder() - if not checkConfig().localPluginFolder: + if not configValues.localPluginFolder: createSFTPConnection() From 205a13ee94a61f0ef761ac26a898eeaa5b2ded8c Mon Sep 17 00:00:00 2001 From: Neocky Date: Sat, 27 Mar 2021 18:58:16 +0100 Subject: [PATCH 3/3] Optimized config handling & beautified output Changes: - optimized config handling - added spinner to paper download - changed progress bar colors - better output for updating paper version - misc code cleanup --- src/handlers/handle_config.py | 58 +++++++++++++++--------------- src/plugin/plugin_downloader.py | 3 +- src/plugin/plugin_updatechecker.py | 16 ++++----- src/serverjar/serverjar_checker.py | 2 +- src/serverjar/serverjar_paper.py | 14 ++++---- 5 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/handlers/handle_config.py b/src/handlers/handle_config.py index 16ed848..54baf55 100644 --- a/src/handlers/handle_config.py +++ b/src/handlers/handle_config.py @@ -7,49 +7,47 @@ from utils.consoleoutput import oColors class configurationValues: - config = configparser.ConfigParser() - config.sections() - config.read("config.ini") - localPluginFolder = config['General']['LocalPluginFolder'] - pathToPluginFolder = Path(config['General']['PathToPluginFolder']) - seperateDownloadPath = config['General']['SeperateDownloadPath'] - pathToSeperateDownloadPath = Path(config['General']['PathToSeperateDownloadPath']) + def __init__(self): + config = configparser.ConfigParser() + config.sections() + config.read("config.ini") + localPluginFolder = config['General']['LocalPluginFolder'] + self.pathToPluginFolder = Path(config['General']['PathToPluginFolder']) + seperateDownloadPath = config['General']['SeperateDownloadPath'] + self.pathToSeperateDownloadPath = Path(config['General']['PathToSeperateDownloadPath']) - sftp_server = config['SFTP - Remote Server']['Server'] - sftp_user = config['SFTP - Remote Server']['Username'] - sftp_password = config['SFTP - Remote Server']['Password'] - sftp_port = config['SFTP - Remote Server']['Port'] - sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer'] - sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath'] - sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath'] + self.sftp_server = config['SFTP - Remote Server']['Server'] + self.sftp_user = config['SFTP - Remote Server']['Username'] + self.sftp_password = config['SFTP - Remote Server']['Password'] + sftp_port = config['SFTP - Remote Server']['Port'] + self.sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer'] + sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath'] + self.sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath'] - sftp_port = int(sftp_port) - if localPluginFolder == 'True': - localPluginFolder = True - else: - localPluginFolder = False + self.sftp_port = int(sftp_port) + if localPluginFolder == 'True': + self.localPluginFolder = True + else: + self.localPluginFolder = False - if seperateDownloadPath == 'True': - seperateDownloadPath = True - else: - seperateDownloadPath = False + if seperateDownloadPath == 'True': + self.seperateDownloadPath = True + else: + self.seperateDownloadPath = False - if sftp_seperateDownloadPath == 'True': - sftp_seperateDownloadPath = True - else: - sftp_seperateDownloadPath = False + if sftp_seperateDownloadPath == 'True': + self.sftp_seperateDownloadPath = True + else: + self.sftp_seperateDownloadPath = False def checkConfig(): - #currentFolder = os.getcwd() configAvailable = os.path.isfile("config.ini") - if not configAvailable: createConfig() print(oColors.brightRed + "Config created. Edit config before executing again!" + oColors.standardWhite) input("Press any key + enter to exit...") sys.exit() - #os.chdir(currentFolder) def createConfig(): diff --git a/src/plugin/plugin_downloader.py b/src/plugin/plugin_downloader.py index e28a4eb..15c6f6c 100644 --- a/src/plugin/plugin_downloader.py +++ b/src/plugin/plugin_downloader.py @@ -85,6 +85,7 @@ def searchPackage(ressourceName): def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'): + configValues = configurationValues() if versionID != 'latest': #url = f"https://spigotmc.org/resources/{ressourceId}/download?version={versionID}" print(oColors.brightRed + "Sorry but specific version downloads aren't supported because of cloudflare protection. :(" + oColors.standardWhite) @@ -104,7 +105,7 @@ def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'): else: filesizeData = calculateFileSizeKb(filesize) print("Downloaded " + (str(filesizeData)).rjust(9) + f" KB here {downloadPath}") - if not configurationValues.localPluginFolder: + if not configValues.localPluginFolder: sftpSession = createSFTPConnection() sftp_upload_file(sftpSession, downloadPath) diff --git a/src/plugin/plugin_updatechecker.py b/src/plugin/plugin_updatechecker.py index a02e949..df2eb6e 100644 --- a/src/plugin/plugin_updatechecker.py +++ b/src/plugin/plugin_updatechecker.py @@ -101,7 +101,7 @@ def checkInstalledPackage(inputSelectedObject="all"): print("│ No. │ Name │ Installed V. │ Latest V. │ Update available │") print("└─────┴────────────────────────────────┴──────────────┴──────────────┴───────────────────┘") try: - for plugin in track(pluginList, description="Checking for updates" ,transient=True, complete_style="cyan"): + for plugin in track(pluginList, description="Checking for updates" ,transient=True, complete_style="bright_yellow"): try: fileName = getFileName(plugin) fileVersion = getFileVersion(plugin) @@ -176,7 +176,7 @@ def updateInstalledPackage(inputSelectedObject='all'): print("│ No. │ Name │ Old V. │ New V. │") print("└─────┴────────────────────────────────┴────────────┴──────────┘") try: - for plugin in track(pluginList, description="Updating" ,transient=True, complete_style="red"): + for plugin in track(pluginList, description="Updating" ,transient=True, complete_style="bright_magenta"): try: fileName = getFileName(plugin) fileVersion = getFileVersion(plugin) @@ -197,9 +197,9 @@ def updateInstalledPackage(inputSelectedObject='all'): print(f" [{indexNumberUpdated+1}]".rjust(6), end='') print(" ", end='') print(f"{fileName}".ljust(33), end='') - print(f"{fileVersion}".ljust(8), end='') - print(" ", end='') - print(f"{latestVersion}".ljust(8)) + print(f"{fileVersion}".ljust(13), end='') + #print(" ", end='') + print(f"{latestVersion}".ljust(13)) if not configValues.localPluginFolder: if configValues.sftp_seperateDownloadPath is True: @@ -247,9 +247,9 @@ def updateInstalledPackage(inputSelectedObject='all'): print(f" [{indexNumberUpdated+1}]".rjust(6), end='') print(" ", end='') print(f"{fileName}".ljust(33), end='') - print(f"{fileVersion}".ljust(8), end='') - print(" ", end='') - print(f"{latestVersion}".ljust(8)) + print(f"{fileVersion}".ljust(13), end='') + #print(" ", end='') + print(f"{latestVersion}".ljust(13)) if not configValues.localPluginFolder: if configValues.sftp_seperateDownloadPath is True: diff --git a/src/serverjar/serverjar_checker.py b/src/serverjar/serverjar_checker.py index 0f6ab86..7e702b0 100644 --- a/src/serverjar/serverjar_checker.py +++ b/src/serverjar/serverjar_checker.py @@ -92,7 +92,7 @@ def updateServerjar(serverJarBuild='latest'): serverJarPath = Path(f"{serverRootPath}/{installedServerjarFullName}") if 'paper' in installedServerjarFullName: - print(f"Updating Paper to build: {serverJarBuild}") + print(oColors.brightBlack + f"Updating Paper to build: {serverJarBuild}" + oColors.standardWhite) if not configValues.localPluginFolder: try: papermc_downloader(serverJarBuild, installedServerjarFullName) diff --git a/src/serverjar/serverjar_paper.py b/src/serverjar/serverjar_paper.py index 67dbde3..f46f56a 100644 --- a/src/serverjar/serverjar_paper.py +++ b/src/serverjar/serverjar_paper.py @@ -3,6 +3,7 @@ import sys import re import urllib.request from pathlib import Path +from rich.console import Console from utils.consoleoutput import oColors from utils.web_request import doAPIRequest @@ -116,6 +117,7 @@ def paperCheckForUpdate(installedServerjarFullName): print(f"{paperInstalledBuild}".ljust(15), end='') print(f"{paperLatestBuild}".ljust(15), end='') print(f"{paperVersionBehind}".ljust(8)) + print(oColors.brightYellow + f"Versions behind: [{paperVersionBehind}]" + oColors.standardWhite) # https://papermc.io/api/docs/swagger-ui/index.html?configUrl=/api/openapi/swagger-config#/ @@ -156,16 +158,16 @@ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersi url = f"https://papermc.io/api/v2/projects/paper/versions/{mcVersion}/builds/{paperBuild}/downloads/{downloadFileName}" remotefile = urllib.request.urlopen(url) filesize = remotefile.info()['Content-Length'] - print(f"Starting Paper-{paperBuild} download for {mcVersion}...") - urllib.request.urlretrieve(url, downloadPackagePath) + print(f"Getting Paper {paperBuild} for {mcVersion}") + console = Console() + with console.status("Downloading...", spinner='line', spinner_style='bright_magenta') as status: + urllib.request.urlretrieve(url, downloadPackagePath) filesizeData = calculateFileSizeMb(filesize) - - print(f"Downloadsize: {filesizeData} MB") - print(f"File downloaded here: {downloadPackagePath}") + print("Downloaded " + (str(filesizeData)).rjust(9) + f" MB here {downloadPackagePath}") if not configValues.localPluginFolder: sftpSession = createSFTPConnection() sftp_upload_server_jar(sftpSession, downloadPackagePath) deleteTempPluginFolder(downloadPath) - print(oColors.brightGreen + "Downloaded successfully " + oColors.standardWhite + f"Paper-{paperBuild}" + \ + print(oColors.brightGreen + "Downloaded successfully " + oColors.standardWhite + f"Paper {paperBuild}" + \ oColors.brightGreen + " for " + oColors.standardWhite + f"{mcVersion}" + oColors.standardWhite)