From abf07e830155b61f63da2d85ca50f7831760e7f2 Mon Sep 17 00:00:00 2001 From: Neocky Date: Wed, 14 Jul 2021 21:26:06 +0200 Subject: [PATCH] Fixed issues and fixed spelling Changes: - Fixed #33 - Fixed #34 - Fixed #35 - Input for update confirmation can also be uppercase now - fixed spelling - some code cleanup --- src/plugin/plugin_downloader.py | 44 +++++++++++++++--------------- src/plugin/plugin_updatechecker.py | 35 ++++++++++++++++-------- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/plugin/plugin_downloader.py b/src/plugin/plugin_downloader.py index ba618e0..805ca12 100644 --- a/src/plugin/plugin_downloader.py +++ b/src/plugin/plugin_downloader.py @@ -51,20 +51,20 @@ def getVersionName(packageId, versionId): return versionName -def searchPackage(ressourceName): +def searchPackage(resourceName): configValues = configurationValues() - url = f"https://api.spiget.org/v2/search/resources/{ressourceName}?field=name&sort=-downloads" + url = f"https://api.spiget.org/v2/search/resources/{resourceName}?field=name&sort=-downloads" packageName = doAPIRequest(url) i = 1 - print(oColors.brightBlack + f"Searching: {ressourceName}" + oColors.standardWhite) + print(oColors.brightBlack + f"Searching: {resourceName}" + oColors.standardWhite) print("┌─────┬─────────────────────────────┬───────────┬──────────────────────────────────────────────────────────────────────┐") print("│ No. │ Name │ Downloads │ Description │") print("└─────┴─────────────────────────────┴───────────┴──────────────────────────────────────────────────────────────────────┘") - for ressource in packageName: - pName = ressource["name"] + for resource in packageName: + pName = resource["name"] newName = handleRegexPackageName(pName) - pTag = ressource["tag"] - pDownloads = ressource["downloads"] + pTag = resource["tag"] + pDownloads = resource["downloads"] print(f" [{i}]".rjust(6), end='') print(" ", end='') print(f"{newName}".ljust(30), end='') @@ -73,10 +73,10 @@ def searchPackage(ressourceName): print(f"{pTag}".ljust(120)) i = i + 1 - ressourceSelected = int(input("Select your wanted Ressource (No.)(0 to exit): ")) - if ressourceSelected != 0: - ressourceSelected = ressourceSelected - 1 - ressourceId = packageName[ressourceSelected]["id"] + resourceSelected = int(input("Select your wanted resource (No.)(0 to exit): ")) + if resourceSelected != 0: + resourceSelected = resourceSelected - 1 + resourceId = packageName[resourceSelected]["id"] if not configValues.localPluginFolder: if configValues.sftp_seperateDownloadPath is True: pluginDownloadPath = configValues.sftp_pathToSeperateDownloadPath @@ -88,20 +88,20 @@ def searchPackage(ressourceName): else: pluginDownloadPath = configValues.pathToPluginFolder try: - getSpecificPackage(ressourceId, pluginDownloadPath) + getSpecificPackage(resourceId, pluginDownloadPath) except HTTPError as err: print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite) -def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'): +def downloadSpecificVersion(resourceId, downloadPath, versionID='latest'): configValues = configurationValues() if versionID != 'latest': - #url = f"https://spigotmc.org/resources/{ressourceId}/download?version={versionID}" + #url = f"https://spigotmc.org/resources/{resourceId}/download?version={versionID}" print(oColors.brightRed + "Sorry but specific version downloads aren't supported because of cloudflare protection. :(" + oColors.standardWhite) print(oColors.brightRed + "Reverting to latest version." + oColors.standardWhite) - url = f"https://api.spiget.org/v2/resources/{ressourceId}/download" - #url = f"https://api.spiget.org/v2/resources/{ressourceId}/versions/latest/download" #throws 403 forbidden error...cloudflare :( + url = f"https://api.spiget.org/v2/resources/{resourceId}/download" + #url = f"https://api.spiget.org/v2/resources/{resourceId}/versions/latest/download" #throws 403 forbidden error...cloudflare :( urrlib_opener = urllib.request.build_opener() urrlib_opener.addheaders = [('User-agent', 'pluGET/1.0')] @@ -127,22 +127,22 @@ def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'): ftp_upload_file(ftpSession, downloadPath) -def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'): +def getSpecificPackage(resourceId, downloadPath, inputPackageVersion='latest'): configValues = configurationValues() if configValues.localPluginFolder == False: downloadPath = createTempPluginFolder() - url = f"https://api.spiget.org/v2/resources/{ressourceId}" + url = f"https://api.spiget.org/v2/resources/{resourceId}" packageDetails = doAPIRequest(url) packageName = packageDetails["name"] packageNameNew = handleRegexPackageName(packageName) - versionId = getVersionID(ressourceId, inputPackageVersion) - packageVersion = getVersionName(ressourceId, versionId) + versionId = getVersionID(resourceId, inputPackageVersion) + packageVersion = getVersionName(resourceId, versionId) packageDownloadName = f"{packageNameNew}-{packageVersion}.jar" downloadPackagePath = Path(f"{downloadPath}/{packageDownloadName}") if inputPackageVersion is None or inputPackageVersion == 'latest': - downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath) + downloadSpecificVersion(resourceId=resourceId, downloadPath=downloadPackagePath) else: - downloadSpecificVersion(ressourceId, downloadPackagePath, versionId) + downloadSpecificVersion(resourceId, downloadPackagePath, versionId) if not configValues.localPluginFolder: deleteTempPluginFolder(downloadPath) diff --git a/src/plugin/plugin_updatechecker.py b/src/plugin/plugin_updatechecker.py index 6aaab87..371681c 100644 --- a/src/plugin/plugin_updatechecker.py +++ b/src/plugin/plugin_updatechecker.py @@ -75,12 +75,24 @@ def getUpdateDescription(pluginId): return stringnonEmptyLines +def versionTuple(versionString): + return tuple(map(int, (versionString.split(".")))) + + +def getVersionWithoutLetters(versionString): + return re.sub(r'([A-Za-z]*)', '', versionString) + + def compareVersions(plugin_latest_version, pluginVersion): - if pluginVersion < plugin_latest_version: - plugin_is_outdated = True + try: + pluginVersionTuple = versionTuple(getVersionWithoutLetters(pluginVersion)) + plugin_latest_versionTuple = versionTuple(getVersionWithoutLetters(plugin_latest_version)) + except ValueError: + return False + if pluginVersionTuple < plugin_latest_versionTuple: + return True else: - plugin_is_outdated = False - return plugin_is_outdated + return False def eggCrackingJar(localJarFileName, searchMode): @@ -121,6 +133,9 @@ def eggCrackingJar(localJarFileName, searchMode): except FileNotFoundError: pluginVersion = '' pluginName = '' + except KeyError: + pluginVersion = '' + pluginName = '' if not configValues.localPluginFolder: deleteTempPluginFolder(tempPluginFolderPath) if searchMode == 'version': @@ -263,7 +278,7 @@ def updateInstalledPackage(inputSelectedObject='all'): print() updateConfirmation = input("Update these plugins [y/n] ? ") - if updateConfirmation != "y": + if str.lower(updateConfirmation) != "y": print(oColors.brightRed + "Aborting the update process."+ oColors.standardWhite) return False @@ -371,6 +386,7 @@ def updateInstalledPackage(inputSelectedObject='all'): 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) @@ -423,10 +439,10 @@ def getInstalledPlugin(localFileName, localFileVersion, localPluginFullName): localFileVersion = localFileVersionNew - for ressource in packageName: + for resource in packageName: if plugin_match_found == True: continue - pID = ressource["id"] + pID = resource["id"] url2 = f"https://api.spiget.org/v2/resources/{pID}/versions?size=100&sort=-name" try: packageVersions = doAPIRequest(url2) @@ -445,10 +461,7 @@ def getInstalledPlugin(localFileName, localFileVersion, localPluginFullName): else: if plugin_match_found != True: - pID = None - updateId = None - plugin_latest_version = None - plugin_is_outdated = None + pID = updateId = plugin_latest_version = plugin_is_outdated = None addToPluginList(localPluginFullName, pID, updateId, plugin_latest_version , plugin_is_outdated) return pluginID