mirror of
https://github.com/Neocky/pluGET.git
synced 2024-04-29 16:12:30 +00:00
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
This commit is contained in:
parent
c551c6bd66
commit
abf07e8301
@ -51,20 +51,20 @@ def getVersionName(packageId, versionId):
|
|||||||
return versionName
|
return versionName
|
||||||
|
|
||||||
|
|
||||||
def searchPackage(ressourceName):
|
def searchPackage(resourceName):
|
||||||
configValues = configurationValues()
|
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)
|
packageName = doAPIRequest(url)
|
||||||
i = 1
|
i = 1
|
||||||
print(oColors.brightBlack + f"Searching: {ressourceName}" + oColors.standardWhite)
|
print(oColors.brightBlack + f"Searching: {resourceName}" + oColors.standardWhite)
|
||||||
print("┌─────┬─────────────────────────────┬───────────┬──────────────────────────────────────────────────────────────────────┐")
|
print("┌─────┬─────────────────────────────┬───────────┬──────────────────────────────────────────────────────────────────────┐")
|
||||||
print("│ No. │ Name │ Downloads │ Description │")
|
print("│ No. │ Name │ Downloads │ Description │")
|
||||||
print("└─────┴─────────────────────────────┴───────────┴──────────────────────────────────────────────────────────────────────┘")
|
print("└─────┴─────────────────────────────┴───────────┴──────────────────────────────────────────────────────────────────────┘")
|
||||||
for ressource in packageName:
|
for resource in packageName:
|
||||||
pName = ressource["name"]
|
pName = resource["name"]
|
||||||
newName = handleRegexPackageName(pName)
|
newName = handleRegexPackageName(pName)
|
||||||
pTag = ressource["tag"]
|
pTag = resource["tag"]
|
||||||
pDownloads = ressource["downloads"]
|
pDownloads = resource["downloads"]
|
||||||
print(f" [{i}]".rjust(6), end='')
|
print(f" [{i}]".rjust(6), end='')
|
||||||
print(" ", end='')
|
print(" ", end='')
|
||||||
print(f"{newName}".ljust(30), end='')
|
print(f"{newName}".ljust(30), end='')
|
||||||
@ -73,10 +73,10 @@ def searchPackage(ressourceName):
|
|||||||
print(f"{pTag}".ljust(120))
|
print(f"{pTag}".ljust(120))
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
|
||||||
ressourceSelected = int(input("Select your wanted Ressource (No.)(0 to exit): "))
|
resourceSelected = int(input("Select your wanted resource (No.)(0 to exit): "))
|
||||||
if ressourceSelected != 0:
|
if resourceSelected != 0:
|
||||||
ressourceSelected = ressourceSelected - 1
|
resourceSelected = resourceSelected - 1
|
||||||
ressourceId = packageName[ressourceSelected]["id"]
|
resourceId = packageName[resourceSelected]["id"]
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
if configValues.sftp_seperateDownloadPath is True:
|
if configValues.sftp_seperateDownloadPath is True:
|
||||||
pluginDownloadPath = configValues.sftp_pathToSeperateDownloadPath
|
pluginDownloadPath = configValues.sftp_pathToSeperateDownloadPath
|
||||||
@ -88,20 +88,20 @@ def searchPackage(ressourceName):
|
|||||||
else:
|
else:
|
||||||
pluginDownloadPath = configValues.pathToPluginFolder
|
pluginDownloadPath = configValues.pathToPluginFolder
|
||||||
try:
|
try:
|
||||||
getSpecificPackage(ressourceId, pluginDownloadPath)
|
getSpecificPackage(resourceId, pluginDownloadPath)
|
||||||
except HTTPError as err:
|
except HTTPError as err:
|
||||||
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
|
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()
|
configValues = configurationValues()
|
||||||
if versionID != 'latest':
|
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 + "Sorry but specific version downloads aren't supported because of cloudflare protection. :(" + oColors.standardWhite)
|
||||||
print(oColors.brightRed + "Reverting to latest version." + 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/{resourceId}/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}/versions/latest/download" #throws 403 forbidden error...cloudflare :(
|
||||||
|
|
||||||
urrlib_opener = urllib.request.build_opener()
|
urrlib_opener = urllib.request.build_opener()
|
||||||
urrlib_opener.addheaders = [('User-agent', 'pluGET/1.0')]
|
urrlib_opener.addheaders = [('User-agent', 'pluGET/1.0')]
|
||||||
@ -127,22 +127,22 @@ def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'):
|
|||||||
ftp_upload_file(ftpSession, downloadPath)
|
ftp_upload_file(ftpSession, downloadPath)
|
||||||
|
|
||||||
|
|
||||||
def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
|
def getSpecificPackage(resourceId, downloadPath, inputPackageVersion='latest'):
|
||||||
configValues = configurationValues()
|
configValues = configurationValues()
|
||||||
if configValues.localPluginFolder == False:
|
if configValues.localPluginFolder == False:
|
||||||
downloadPath = createTempPluginFolder()
|
downloadPath = createTempPluginFolder()
|
||||||
url = f"https://api.spiget.org/v2/resources/{ressourceId}"
|
url = f"https://api.spiget.org/v2/resources/{resourceId}"
|
||||||
packageDetails = doAPIRequest(url)
|
packageDetails = doAPIRequest(url)
|
||||||
packageName = packageDetails["name"]
|
packageName = packageDetails["name"]
|
||||||
packageNameNew = handleRegexPackageName(packageName)
|
packageNameNew = handleRegexPackageName(packageName)
|
||||||
versionId = getVersionID(ressourceId, inputPackageVersion)
|
versionId = getVersionID(resourceId, inputPackageVersion)
|
||||||
packageVersion = getVersionName(ressourceId, versionId)
|
packageVersion = getVersionName(resourceId, versionId)
|
||||||
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
|
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
|
||||||
downloadPackagePath = Path(f"{downloadPath}/{packageDownloadName}")
|
downloadPackagePath = Path(f"{downloadPath}/{packageDownloadName}")
|
||||||
if inputPackageVersion is None or inputPackageVersion == 'latest':
|
if inputPackageVersion is None or inputPackageVersion == 'latest':
|
||||||
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)
|
downloadSpecificVersion(resourceId=resourceId, downloadPath=downloadPackagePath)
|
||||||
else:
|
else:
|
||||||
downloadSpecificVersion(ressourceId, downloadPackagePath, versionId)
|
downloadSpecificVersion(resourceId, downloadPackagePath, versionId)
|
||||||
|
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
deleteTempPluginFolder(downloadPath)
|
deleteTempPluginFolder(downloadPath)
|
||||||
|
@ -75,12 +75,24 @@ def getUpdateDescription(pluginId):
|
|||||||
return stringnonEmptyLines
|
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):
|
def compareVersions(plugin_latest_version, pluginVersion):
|
||||||
if pluginVersion < plugin_latest_version:
|
try:
|
||||||
plugin_is_outdated = True
|
pluginVersionTuple = versionTuple(getVersionWithoutLetters(pluginVersion))
|
||||||
|
plugin_latest_versionTuple = versionTuple(getVersionWithoutLetters(plugin_latest_version))
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
if pluginVersionTuple < plugin_latest_versionTuple:
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
plugin_is_outdated = False
|
return False
|
||||||
return plugin_is_outdated
|
|
||||||
|
|
||||||
|
|
||||||
def eggCrackingJar(localJarFileName, searchMode):
|
def eggCrackingJar(localJarFileName, searchMode):
|
||||||
@ -121,6 +133,9 @@ def eggCrackingJar(localJarFileName, searchMode):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pluginVersion = ''
|
pluginVersion = ''
|
||||||
pluginName = ''
|
pluginName = ''
|
||||||
|
except KeyError:
|
||||||
|
pluginVersion = ''
|
||||||
|
pluginName = ''
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
deleteTempPluginFolder(tempPluginFolderPath)
|
deleteTempPluginFolder(tempPluginFolderPath)
|
||||||
if searchMode == 'version':
|
if searchMode == 'version':
|
||||||
@ -263,7 +278,7 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
|
|
||||||
print()
|
print()
|
||||||
updateConfirmation = input("Update these plugins [y/n] ? ")
|
updateConfirmation = input("Update these plugins [y/n] ? ")
|
||||||
if updateConfirmation != "y":
|
if str.lower(updateConfirmation) != "y":
|
||||||
print(oColors.brightRed + "Aborting the update process."+ oColors.standardWhite)
|
print(oColors.brightRed + "Aborting the update process."+ oColors.standardWhite)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -371,6 +386,7 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
try:
|
try:
|
||||||
getSpecificPackage(pluginId, pluginPath)
|
getSpecificPackage(pluginId, pluginPath)
|
||||||
if configValues.seperateDownloadPath is False:
|
if configValues.seperateDownloadPath is False:
|
||||||
|
pluginPath = f"{pluginPath}/{plugin}"
|
||||||
os.remove(pluginPath)
|
os.remove(pluginPath)
|
||||||
except HTTPError as err:
|
except HTTPError as err:
|
||||||
print(oColors.brightRed + f"HTTPError: {err.code} - {err.reason}" + oColors.standardWhite)
|
print(oColors.brightRed + f"HTTPError: {err.code} - {err.reason}" + oColors.standardWhite)
|
||||||
@ -423,10 +439,10 @@ def getInstalledPlugin(localFileName, localFileVersion, localPluginFullName):
|
|||||||
|
|
||||||
localFileVersion = localFileVersionNew
|
localFileVersion = localFileVersionNew
|
||||||
|
|
||||||
for ressource in packageName:
|
for resource in packageName:
|
||||||
if plugin_match_found == True:
|
if plugin_match_found == True:
|
||||||
continue
|
continue
|
||||||
pID = ressource["id"]
|
pID = resource["id"]
|
||||||
url2 = f"https://api.spiget.org/v2/resources/{pID}/versions?size=100&sort=-name"
|
url2 = f"https://api.spiget.org/v2/resources/{pID}/versions?size=100&sort=-name"
|
||||||
try:
|
try:
|
||||||
packageVersions = doAPIRequest(url2)
|
packageVersions = doAPIRequest(url2)
|
||||||
@ -445,10 +461,7 @@ def getInstalledPlugin(localFileName, localFileVersion, localPluginFullName):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
if plugin_match_found != True:
|
if plugin_match_found != True:
|
||||||
pID = None
|
pID = updateId = plugin_latest_version = plugin_is_outdated = None
|
||||||
updateId = None
|
|
||||||
plugin_latest_version = None
|
|
||||||
plugin_is_outdated = None
|
|
||||||
addToPluginList(localPluginFullName, pID, updateId, plugin_latest_version , plugin_is_outdated)
|
addToPluginList(localPluginFullName, pID, updateId, plugin_latest_version , plugin_is_outdated)
|
||||||
|
|
||||||
return pluginID
|
return pluginID
|
||||||
|
Loading…
Reference in New Issue
Block a user