From 367ee5be42e546a47a349c6ef21c0d40e98aee4c Mon Sep 17 00:00:00 2001 From: Neocky Date: Sun, 18 Jul 2021 14:51:02 +0200 Subject: [PATCH] Fixed that update all could fail and changed output colors and fixed get-paper command Changes: - fixed update all could fail and stop program when the file couldn't be downloaded - changed colors from `check all` so that green means on latest version and red outdated - fixed get-paper command - changed latet version from paper to 1.17.1 - code cleanup --- src/plugin/plugin_updatechecker.py | 145 ++++++++++++++++------------- src/serverjar/serverjar_checker.py | 24 ++--- src/serverjar/serverjar_paper.py | 28 +++--- 3 files changed, 103 insertions(+), 94 deletions(-) diff --git a/src/plugin/plugin_updatechecker.py b/src/plugin/plugin_updatechecker.py index 371681c..56c284a 100644 --- a/src/plugin/plugin_updatechecker.py +++ b/src/plugin/plugin_updatechecker.py @@ -233,9 +233,9 @@ def checkInstalledPackage(inputSelectedObject="all", inputOptionalParam=None): print(f" [{i+1}]".rjust(6), end='') print(" ", end='') if pluginIsOutdated == True: - print(oColors.brightGreen + f"{fileName}".ljust(33) + oColors.standardWhite, end='') - elif pluginIsOutdated == False: print(oColors.brightRed + f"{fileName}".ljust(33) + oColors.standardWhite, end='') + elif pluginIsOutdated == False: + print(oColors.brightGreen + f"{fileName}".ljust(33) + oColors.standardWhite, end='') else: print(f"{fileName}".ljust(33), end='') @@ -337,71 +337,86 @@ def updateInstalledPackage(inputSelectedObject='all'): i += 1 continue - if inputSelectedObject == 'all' or inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE): - if INSTALLEDPLUGINLIST[i][4] == True: - 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 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 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 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 - else: + if inputSelectedObject != 'all' and inputSelectedObject != pluginIdStr and not re.search(inputSelectedObject, fileName, re.IGNORECASE): i += 1 continue + 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 i += 1 except TypeError: diff --git a/src/serverjar/serverjar_checker.py b/src/serverjar/serverjar_checker.py index 54117cc..f08ec00 100644 --- a/src/serverjar/serverjar_checker.py +++ b/src/serverjar/serverjar_checker.py @@ -98,24 +98,16 @@ def updateServerjar(serverJarBuild='latest'): if 'paper' in installedServerjarFullName: print(oColors.brightBlack + f"Updating Paper to build: {serverJarBuild}" + oColors.standardWhite) - if not configValues.localPluginFolder: - try: - papermc_downloader(serverJarBuild, installedServerjarFullName) + try: + papermc_downloader(serverJarBuild, None, installedServerjarFullName) + if not configValues.localPluginFolder: sftp.remove(serverJarPath) - except HTTPError as err: - print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite) - except FileNotFoundError: - print(oColors.brightRed + "Error: Old serverjar file coulnd't be deleted" + oColors.standardWhite) - - else: - try: - papermc_downloader(serverJarBuild, installedServerjarFullName) + else: os.remove(serverJarPath) - except HTTPError as err: - print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite) - except FileNotFoundError: - print(oColors.brightRed + "Error: Old serverjar file coulnd't be deleted" + oColors.standardWhite) - + except HTTPError as err: + print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite) + except FileNotFoundError: + print(oColors.brightRed + "Error: Old serverjar file coulnd't be deleted" + oColors.standardWhite) else: print(oColors.brightRed + f"{installedServerjarFullName} isn't supported.") print(oColors.brightRed + "Aborting the process." + oColors.standardWhite) diff --git a/src/serverjar/serverjar_paper.py b/src/serverjar/serverjar_paper.py index 2f9015b..99c6da6 100644 --- a/src/serverjar/serverjar_paper.py +++ b/src/serverjar/serverjar_paper.py @@ -111,28 +111,28 @@ def paperCheckForUpdate(installedServerjarFullName): # Report an error if getInstalledPaperMinecraftVersion encountered an issue. if not mcVersion: - print(oColors.brightRed + f"ERR: An error was encountered while detecting the server's Minecraft version." + + print(oColors.brightRed + "ERR: An error was encountered while detecting the server's Minecraft version." + oColors.standardWhite) return False paperInstalledBuild = getInstalledPaperVersion(installedServerjarFullName) # Report an error if getInstalledPaperVersion encountered an issue. if not paperInstalledBuild: - print(oColors.brightRed + f"ERR: An error was encountered while detecting the server's Paper version." + + print(oColors.brightRed + "ERR: An error was encountered while detecting the server's Paper version." + oColors.standardWhite) return False versionGroup = findVersionGroup(mcVersion) # Report an error if findVersionGroup encountered an issue. if not versionGroup: - print(oColors.brightRed + f"ERR: An error was encountered while fetching the server's version group." + + print(oColors.brightRed + "ERR: An error was encountered while fetching the server's version group." + oColors.standardWhite) return False paperLatestBuild = findLatestBuild(versionGroup) # Report an error if findLatestBuild encountered an issue. if not paperLatestBuild: - print(oColors.brightRed + f"ERR: An error was encountered while fetching the latest version of PaperMC." + + print(oColors.brightRed + "ERR: An error was encountered while fetching the latest version of PaperMC." + oColors.standardWhite) return False # Not currently handled, but can be at a later date. Currently just stops the following from # being printed. @@ -140,27 +140,29 @@ def paperCheckForUpdate(installedServerjarFullName): paperVersionBehind = versionBehind(paperInstalledBuild, paperLatestBuild) # Report an error if getInstalledPaperVersion encountered an issue. if not paperVersionBehind: - print(oColors.brightRed + f"ERR: An error was encountered while detecting how many versions behind you are. " + print(oColors.brightRed + "ERR: An error was encountered while detecting how many versions behind you are. " f"Will display as 'N/A'." + oColors.standardWhite) paperVersionBehind = "N/A" # Sets paperVersionBehind to N/A while still letting the versionBehind check return # False for error-handing reasons. # Does not return false as versions behind doesn't break things. It is just helpful information. # paperVersionBehind will just display as "N/A" - print("┌─────┬────────────────────────────────┬──────────────┬──────────────┬───────────────────┐") - print("│ No. │ Name │ Installed V. │ Latest V. │ Versions behind │") - print("└─────┴────────────────────────────────┴──────────────┴──────────────┴───────────────────┘") + print("┌─────┬────────────────────────────────┬──────────────┬──────────────┐") + print("│ No. │ Name │ Installed V. │ Latest V. │") + print("└─────┴────────────────────────────────┴──────────────┴──────────────┘") print(" [1]".rjust(6), end='') print(" ", end='') - print("paper".ljust(33), end='') + if paperVersionBehind != 0: + print(oColors.brightRed + "paper".ljust(33) + oColors.standardWhite, end='') + else: + print(oColors.brightGreen + "paper".ljust(33) + oColors.standardWhite, end='') print(f"{paperInstalledBuild}".ljust(15), end='') - print(f"{paperLatestBuild}".ljust(15), end='') - print(f"{paperVersionBehind}".ljust(8)) + print(f"{paperLatestBuild}".ljust(15)) print(oColors.brightYellow + f"Versions behind: [{paperVersionBehind}]" + oColors.standardWhite) # https://papermc.io/api/docs/swagger-ui/index.html?configUrl=/api/openapi/swagger-config#/ -def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersion=None): +def papermc_downloader(paperBuild='latest', mcVersion=None, installedServerjarName=None): configValues = configurationValues() if configValues.localPluginFolder == False: downloadPath = createTempPluginFolder() @@ -172,7 +174,7 @@ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersi if mcVersion == None: if paperBuild == 'latest': - mcVersion = '1.17' + mcVersion = '1.17.1' else: mcVersion = findBuildVersion(paperBuild)