From 716227eafa79b0a7c1816c3604f65ab9aeee9840 Mon Sep 17 00:00:00 2001 From: Zander <28664144+ZandercraftGames@users.noreply.github.com> Date: Sun, 9 May 2021 00:23:11 -0400 Subject: [PATCH 1/4] Add PyCharm configurations to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index f0a442b..b384ee0 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,6 @@ dmypy.json # VSCode Settings .vscode + +# PyCharm Settings +.idea From 11b4fdcbeb4f046b3782ab2e8bfca123b11d790e Mon Sep 17 00:00:00 2001 From: Zander <28664144+ZandercraftGames@users.noreply.github.com> Date: Sun, 9 May 2021 01:33:05 -0400 Subject: [PATCH 2/4] Add error handling to "check serverjar" command on paper servers. Fixes use assignment issues when detection doesn't work. --- src/serverjar/serverjar_paper.py | 80 +++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 18 deletions(-) diff --git a/src/serverjar/serverjar_paper.py b/src/serverjar/serverjar_paper.py index daa90f9..2146eba 100644 --- a/src/serverjar/serverjar_paper.py +++ b/src/serverjar/serverjar_paper.py @@ -15,6 +15,8 @@ from utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calc # = 1.16.5 def getInstalledPaperMinecraftVersion(localPaperName): + if localPaperName is None: + return False mcVersionFull = re.search(r'(\d*\.*\d)+', localPaperName) try: mcVersion = mcVersionFull.group() @@ -25,6 +27,8 @@ def getInstalledPaperMinecraftVersion(localPaperName): # = 550 def getInstalledPaperVersion(localPaperName): + if localPaperName is None: + return False paperBuildFull = re.search(r'([\d]*.jar)', localPaperName) try: paperBuild = paperBuildFull.group() @@ -36,52 +40,51 @@ def getInstalledPaperVersion(localPaperName): def findVersionGroup(mcVersion): versionGroups = ['1.16', '1.15'] - versionGroupFound = False + if mcVersion is None: + return False for versionGroup in versionGroups: - if versionGroupFound == True: - break url = f"https://papermc.io/api/v2/projects/paper/version_group/{versionGroup}/builds" papermcdetails = doAPIRequest(url) papermcVersionForMc = papermcdetails["versions"] for versions in papermcVersionForMc: if versions == mcVersion: - versionGroupFound = True paperVersionGroup = versionGroup - break + return paperVersionGroup if versionGroup == mcVersion: - versionGroupFound = True paperVersionGroup = versionGroup - break - - return paperVersionGroup + return paperVersionGroup + return False # Not found def findBuildVersion(wantedPaperBuild): versionGroups = ['1.16', '1.15'] - paperBuildFound = False + if wantedPaperBuild is None: + return False for versionGroup in versionGroups: - if paperBuildFound is True: - break url = f"https://papermc.io/api/v2/projects/paper/version_group/{versionGroup}/builds" papermcdetails = doAPIRequest(url) paperMcBuilds = papermcdetails["builds"] for build in paperMcBuilds: paperBuild = str(build["build"]) if paperBuild == wantedPaperBuild: - paperBuildFound = True paperVersionGroup = build["version"] - break - return paperVersionGroup - + return paperVersionGroup + return False # Not found def findLatestBuild(paperVersionGroup): + if paperVersionGroup is None: + return False url = f"https://papermc.io/api/v2/projects/paper/version_group/{paperVersionGroup}/builds" papermcbuilds = doAPIRequest(url) + if papermcbuilds["status"] == 404: + return False latestPaperBuild = papermcbuilds["builds"][-1]["build"] return latestPaperBuild def findLatestBuildForVersion(mcVersion): + if mcVersion is None: + return False url = f"https://papermc.io/api/v2/projects/paper/versions/{mcVersion}" papermcbuilds = doAPIRequest(url) latestPaperBuild = papermcbuilds["builds"][-1] @@ -89,6 +92,8 @@ def findLatestBuildForVersion(mcVersion): def versionBehind(installedPaperBuild, latestPaperBuild): + if installedPaperBuild or latestPaperBuild is None: + return False installedPaperBuildint = int(installedPaperBuild) latestPaperBuildint = int(latestPaperBuild) versionsBehind = latestPaperBuildint - installedPaperBuildint @@ -96,6 +101,8 @@ def versionBehind(installedPaperBuild, latestPaperBuild): def getDownloadFileName(paperMcVersion, paperBuild): + if paperMcVersion or paperBuild is None: + return False url = f"https://papermc.io/api/v2/projects/paper/versions/{paperMcVersion}/builds/{paperBuild}" buildDetails = doAPIRequest(url) downloadName = buildDetails["downloads"]["application"]["name"] @@ -104,11 +111,48 @@ def getDownloadFileName(paperMcVersion, paperBuild): def paperCheckForUpdate(installedServerjarFullName): mcVersion = getInstalledPaperMinecraftVersion(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." + + 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." + + 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." + + 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." + + oColors.standardWhite) + return False # Not currently handled, but can be at a later date. Currently just stops the following from + # being printed. + 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. " + f"Will display as False." + oColors.standardWhite) + # Does not return false as versions behind doesn't break things. It is just helpful information. + # paperVersionBehind will just display as "False" + + print("┌─────┬────────────────────────────────┬──────────────┬──────────────┬───────────────────┐") print("│ No. │ Name │ Installed V. │ Latest V. │ Versions behind │") print("└─────┴────────────────────────────────┴──────────────┴──────────────┴───────────────────┘") @@ -172,8 +216,8 @@ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersi else: sftpSession = createSFTPConnection() sftp_upload_server_jar(sftpSession, downloadPackagePath) - + deleteTempPluginFolder(downloadPath) print(oColors.brightGreen + "Downloaded successfully " + oColors.standardWhite + f"Paper {paperBuild}" + \ - oColors.brightGreen + " for " + oColors.standardWhite + f"{mcVersion}" + oColors.standardWhite) + oColors.brightGreen + " for " + oColors.standardWhite + f"{mcVersion}" + oColors.standardWhite) From b31cca5e310497d863e93c73bc76e7da0cb10855 Mon Sep 17 00:00:00 2001 From: Zander <28664144+ZandercraftGames@users.noreply.github.com> Date: Sat, 15 May 2021 19:02:09 -0400 Subject: [PATCH 3/4] Fix findLatestBuild check returning false on a successful API response. --- src/serverjar/serverjar_paper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/serverjar/serverjar_paper.py b/src/serverjar/serverjar_paper.py index 2146eba..f238e2f 100644 --- a/src/serverjar/serverjar_paper.py +++ b/src/serverjar/serverjar_paper.py @@ -76,7 +76,7 @@ def findLatestBuild(paperVersionGroup): return False url = f"https://papermc.io/api/v2/projects/paper/version_group/{paperVersionGroup}/builds" papermcbuilds = doAPIRequest(url) - if papermcbuilds["status"] == 404: + if "status" in papermcbuilds: # Checks if the API returns a status. This means that there was an error. return False latestPaperBuild = papermcbuilds["builds"][-1]["build"] return latestPaperBuild From a08aab7ae434e44a46800c2b66b2b21570000b29 Mon Sep 17 00:00:00 2001 From: Zander <28664144+ZandercraftGames@users.noreply.github.com> Date: Sat, 15 May 2021 19:05:29 -0400 Subject: [PATCH 4/4] Made paperVersionBehind display "N/A" instead of "False" for more clarity. --- src/serverjar/serverjar_paper.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/serverjar/serverjar_paper.py b/src/serverjar/serverjar_paper.py index f238e2f..16658e6 100644 --- a/src/serverjar/serverjar_paper.py +++ b/src/serverjar/serverjar_paper.py @@ -71,6 +71,7 @@ def findBuildVersion(wantedPaperBuild): return paperVersionGroup return False # Not found + def findLatestBuild(paperVersionGroup): if paperVersionGroup is None: return False @@ -148,10 +149,12 @@ def paperCheckForUpdate(installedServerjarFullName): # 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. " - f"Will display as False." + oColors.standardWhite) - # Does not return false as versions behind doesn't break things. It is just helpful information. - # paperVersionBehind will just display as "False" + 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 │")