mirror of
https://github.com/Neocky/pluGET.git
synced 2024-04-29 16:12:30 +00:00
Every plugin has now an array entry; Beautified the output
Changes: - added latest version of plugin to installedplugin array - fixed issue when array couldn't be created; Now the array will always be created - added bright Green to console Output - deleted debug output for the innput
This commit is contained in:
parent
0d17bfe25b
commit
3fed1580f8
@ -67,9 +67,9 @@ def getInput():
|
|||||||
print(oColors.brightRed + "Wrong input! Use: > *command* *selectedObject* *optionalParams*" + oColors.standardWhite)
|
print(oColors.brightRed + "Wrong input! Use: > *command* *selectedObject* *optionalParams*" + oColors.standardWhite)
|
||||||
|
|
||||||
inputParams = inputParams[0] if inputParams else None
|
inputParams = inputParams[0] if inputParams else None
|
||||||
print(inputCommand)
|
#print(inputCommand)
|
||||||
print(inputSelectedObject)
|
#print(inputSelectedObject)
|
||||||
print(inputParams)
|
#print(inputParams)
|
||||||
handleInput(inputCommand, inputSelectedObject, inputParams)
|
handleInput(inputCommand, inputSelectedObject, inputParams)
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,11 +14,11 @@ def createPluginList():
|
|||||||
return INSTALLEDPLUGINLIST
|
return INSTALLEDPLUGINLIST
|
||||||
|
|
||||||
|
|
||||||
def addToPluginList(pluginId, versionId, plugin_is_outdated):
|
def addToPluginList(pluginId, versionId, plugin_latest_version, plugin_is_outdated):
|
||||||
INSTALLEDPLUGINLIST.append([pluginId, versionId, plugin_is_outdated])
|
INSTALLEDPLUGINLIST.append([pluginId, versionId, plugin_latest_version, plugin_is_outdated])
|
||||||
|
|
||||||
|
|
||||||
def getFileName(pluginName):
|
def getFileName(pluginName): # TODO delete end of pluginName -v like BossShopPro-v
|
||||||
pluginNameFull = pluginName
|
pluginNameFull = pluginName
|
||||||
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
|
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
|
||||||
try:
|
try:
|
||||||
@ -38,11 +38,15 @@ def getFileVersion(pluginName):
|
|||||||
return pluginVersionString
|
return pluginVersionString
|
||||||
|
|
||||||
|
|
||||||
def compareVersions(pluginId, pluginVersion):
|
def getLatestPluginVersion(pluginId):
|
||||||
url = f"https://api.spiget.org/v2/resources/{pluginId}/versions/latest"
|
url = f"https://api.spiget.org/v2/resources/{pluginId}/versions/latest"
|
||||||
latestUpdateSearch = doAPIRequest(url)
|
latestUpdateSearch = doAPIRequest(url)
|
||||||
versionLatestUpdate = latestUpdateSearch["name"]
|
versionLatestUpdate = latestUpdateSearch["name"]
|
||||||
if pluginVersion != versionLatestUpdate:
|
return versionLatestUpdate
|
||||||
|
|
||||||
|
|
||||||
|
def compareVersions(plugin_latest_version, pluginVersion):
|
||||||
|
if pluginVersion < plugin_latest_version:
|
||||||
plugin_is_outdated = True
|
plugin_is_outdated = True
|
||||||
else:
|
else:
|
||||||
plugin_is_outdated = False
|
plugin_is_outdated = False
|
||||||
@ -58,7 +62,8 @@ def checkInstalledPackage(inputSelectedObject="all"):
|
|||||||
pluginList = os.listdir(checkConfig().pathToPluginFolder)
|
pluginList = os.listdir(checkConfig().pathToPluginFolder)
|
||||||
i = 0
|
i = 0
|
||||||
oldPackages = 0
|
oldPackages = 0
|
||||||
print("Index / Name / Installed Version / Update available")
|
print(f"Checking: {inputSelectedObject}")
|
||||||
|
print("Index | Name | Installed V. | Latest V. | Update available")
|
||||||
try:
|
try:
|
||||||
for plugin in pluginList:
|
for plugin in pluginList:
|
||||||
try:
|
try:
|
||||||
@ -73,27 +78,43 @@ def checkInstalledPackage(inputSelectedObject="all"):
|
|||||||
fileVersion = 'N/A'
|
fileVersion = 'N/A'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pluginIsOutdated = INSTALLEDPLUGINLIST[i][2]
|
pluginLatestVersion = INSTALLEDPLUGINLIST[i][2]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
pluginLatestVersion = 'N/A'
|
||||||
|
|
||||||
|
if pluginLatestVersion == None:
|
||||||
|
pluginLatestVersion = 'N/A'
|
||||||
|
|
||||||
|
try:
|
||||||
|
pluginIsOutdated = INSTALLEDPLUGINLIST[i][3]
|
||||||
|
except IndexError:
|
||||||
|
pluginIsOutdated = 'N/A'
|
||||||
|
|
||||||
|
if pluginIsOutdated == None:
|
||||||
pluginIsOutdated = 'N/A'
|
pluginIsOutdated = 'N/A'
|
||||||
|
|
||||||
if pluginIsOutdated == True:
|
if pluginIsOutdated == True:
|
||||||
oldPackages = oldPackages + 1
|
oldPackages = oldPackages + 1
|
||||||
|
|
||||||
if inputSelectedObject != "*":
|
if inputSelectedObject != "*" and inputSelectedObject != "all":
|
||||||
if inputSelectedObject != "all":
|
|
||||||
if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
|
if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
|
||||||
print(f"[{1}] {fileName} - {fileVersion} - {pluginIsOutdated}")
|
print(f" [{1}]".ljust(8), end='')
|
||||||
|
print(f"{fileName}".ljust(33), end='')
|
||||||
|
print(f"{fileVersion}".ljust(15), end='')
|
||||||
|
print(f"{pluginLatestVersion}".ljust(12), end='')
|
||||||
|
print(f" {pluginIsOutdated}".ljust(5))
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print(f"[{i+1}] {fileName} - {fileVersion} - {pluginIsOutdated}") # TODO find better way for the 2 else
|
print(f" [{i+1}]".ljust(8), end='')
|
||||||
else:
|
print(f"{fileName}".ljust(33), end='')
|
||||||
print(f"[{i+1}] {fileName} - {fileVersion} - {pluginIsOutdated}")
|
print(f"{fileVersion}".ljust(15), end='')
|
||||||
|
print(f"{pluginLatestVersion}".ljust(12), end='')
|
||||||
|
print(f" {pluginIsOutdated}".ljust(5))
|
||||||
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
except TypeError:
|
except TypeError:
|
||||||
print(oColors.brightRed + "Aborted checking for plugins." + oColors.standardWhite)
|
print(oColors.brightRed + "Aborted checking for plugins." + oColors.standardWhite)
|
||||||
print(f"Old packages: [{oldPackages}/{i}]")
|
print(oColors.brightYellow + f"Old packages: [{oldPackages}/{i}]" + oColors.standardWhite)
|
||||||
|
|
||||||
|
|
||||||
def updateInstalledPackage(inputSelectedObject='all'):
|
def updateInstalledPackage(inputSelectedObject='all'):
|
||||||
@ -105,15 +126,19 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
pluginList = os.listdir(checkConfig().pathToPluginFolder)
|
pluginList = os.listdir(checkConfig().pathToPluginFolder)
|
||||||
i = 0
|
i = 0
|
||||||
pluginsUpdated = 0
|
pluginsUpdated = 0
|
||||||
|
print(f"Updating: {inputSelectedObject}")
|
||||||
|
print("Index | Name | Old V. | New V.")
|
||||||
try:
|
try:
|
||||||
for plugin in pluginList:
|
for plugin in pluginList:
|
||||||
print(plugin)
|
|
||||||
try:
|
try:
|
||||||
fileName = getFileName(plugin)
|
fileName = getFileName(plugin)
|
||||||
fileVersion = getFileVersion(plugin)
|
fileVersion = getFileVersion(plugin)
|
||||||
pluginId = getInstalledPlugin(fileName, fileVersion)
|
pluginId = getInstalledPlugin(fileName, fileVersion)
|
||||||
|
latestVersion = getLatestPluginVersion(pluginId)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
continue
|
continue
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
pluginIdStr = str(pluginId)
|
pluginIdStr = str(pluginId)
|
||||||
|
|
||||||
if pluginId == None:
|
if pluginId == None:
|
||||||
@ -121,7 +146,13 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
|
if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
|
||||||
print(f"Updating: {fileName}")
|
if INSTALLEDPLUGINLIST[i][3] == True:
|
||||||
|
print(f" [{pluginsUpdated+1}]".ljust(8), end='')
|
||||||
|
print(f"{fileName}".ljust(30), end='')
|
||||||
|
print(f"{fileVersion}".ljust(8), end='')
|
||||||
|
print(" ", end='')
|
||||||
|
print(f"{latestVersion}".ljust(8))
|
||||||
|
|
||||||
if not checkConfig().localPluginFolder:
|
if not checkConfig().localPluginFolder:
|
||||||
pluginPath = checkConfig().sftp_folderPath
|
pluginPath = checkConfig().sftp_folderPath
|
||||||
pluginPath = f"{pluginPath}\\{plugin}"
|
pluginPath = f"{pluginPath}\\{plugin}"
|
||||||
@ -136,31 +167,39 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
getSpecificPackage(pluginId, checkConfig().pathToPluginFolder)
|
getSpecificPackage(pluginId, checkConfig().pathToPluginFolder)
|
||||||
pluginsUpdated += 1
|
pluginsUpdated += 1
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
print(f"{fileName} is already on {latestVersion}")
|
||||||
|
print(oColors.brightRed + "Aborting the update process."+ oColors.standardWhite)
|
||||||
|
break
|
||||||
|
|
||||||
if inputSelectedObject == 'all':
|
if inputSelectedObject == 'all':
|
||||||
if INSTALLEDPLUGINLIST[i][2] == True:
|
if INSTALLEDPLUGINLIST[i][3] == True:
|
||||||
|
print(f" [{pluginsUpdated+1}]".ljust(8), end='')
|
||||||
|
print(f"{fileName}".ljust(30), end='')
|
||||||
|
print(f"{fileVersion}".ljust(8), end='')
|
||||||
|
print(" ", end='')
|
||||||
|
print(f"{latestVersion}".ljust(8))
|
||||||
|
|
||||||
if not checkConfig().localPluginFolder:
|
if not checkConfig().localPluginFolder:
|
||||||
pluginPath = checkConfig().sftp_folderPath
|
pluginPath = checkConfig().sftp_folderPath
|
||||||
pluginPath = f"{pluginPath}\\{plugin}"
|
pluginPath = f"{pluginPath}\\{plugin}"
|
||||||
print("Deleting old plugin...")
|
|
||||||
sftp = createSFTPConnection()
|
sftp = createSFTPConnection()
|
||||||
sftp.remove(pluginPath)
|
sftp.remove(pluginPath)
|
||||||
print("Downloading new plugin...")
|
|
||||||
getSpecificPackage(pluginId, checkConfig().sftp_folderPath)
|
getSpecificPackage(pluginId, checkConfig().sftp_folderPath)
|
||||||
pluginsUpdated += 1
|
pluginsUpdated += 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
pluginPath = checkConfig().pathToPluginFolder
|
pluginPath = checkConfig().pathToPluginFolder
|
||||||
pluginPath = f"{pluginPath}\\{plugin}"
|
pluginPath = f"{pluginPath}\\{plugin}"
|
||||||
print("Deleting old plugin...")
|
|
||||||
os.remove(pluginPath)
|
os.remove(pluginPath)
|
||||||
print("Downloading new plugin...")
|
|
||||||
getSpecificPackage(pluginId, checkConfig().pathToPluginFolder)
|
getSpecificPackage(pluginId, checkConfig().pathToPluginFolder)
|
||||||
pluginsUpdated += 1
|
pluginsUpdated += 1
|
||||||
i = i + 1
|
i = i + 1
|
||||||
except TypeError:
|
except TypeError:
|
||||||
print(oColors.brightRed + "Aborted updating for plugins." + oColors.standardWhite)
|
print(oColors.brightRed + "Aborted updating for plugins." + oColors.standardWhite)
|
||||||
print(f"[{pluginsUpdated}/{i}] Plugins updated")
|
print(f"[{pluginsUpdated}/{i}] Plugins updated")
|
||||||
|
if inputSelectedObject =='all' and pluginsUpdated == 0:
|
||||||
|
print(oColors.brightGreen + "All plugins are on the latest version!" + oColors.standardWhite)
|
||||||
|
|
||||||
|
|
||||||
def getInstalledPlugin(localFileName, localFileVersion):
|
def getInstalledPlugin(localFileName, localFileVersion):
|
||||||
@ -172,7 +211,7 @@ def getInstalledPlugin(localFileName, localFileVersion):
|
|||||||
for ressource in packageName:
|
for ressource in packageName:
|
||||||
if plugin_match_found == True:
|
if plugin_match_found == True:
|
||||||
break
|
break
|
||||||
#pName = ressource["name"]
|
|
||||||
pID = ressource["id"]
|
pID = ressource["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"
|
||||||
packageVersions = doAPIRequest(url2)
|
packageVersions = doAPIRequest(url2)
|
||||||
@ -182,10 +221,19 @@ def getInstalledPlugin(localFileName, localFileVersion):
|
|||||||
plugin_match_found = True
|
plugin_match_found = True
|
||||||
pluginID = pID
|
pluginID = pID
|
||||||
updateId = updates["id"]
|
updateId = updates["id"]
|
||||||
plugin_is_outdated = compareVersions(pID, updateVersion)
|
plugin_latest_version = getLatestPluginVersion(pID)
|
||||||
addToPluginList(pID, updateId, plugin_is_outdated)
|
plugin_is_outdated = compareVersions(plugin_latest_version, updateVersion)
|
||||||
|
addToPluginList(pID, updateId, plugin_latest_version , plugin_is_outdated)
|
||||||
break
|
break
|
||||||
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
else:
|
||||||
|
pID = None
|
||||||
|
updateId = None
|
||||||
|
plugin_latest_version = None
|
||||||
|
plugin_is_outdated = None
|
||||||
|
addToPluginList(pID, updateId, plugin_latest_version , plugin_is_outdated)
|
||||||
|
|
||||||
return pluginID
|
return pluginID
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ class oColors:
|
|||||||
brightYellow = "\033[93m"
|
brightYellow = "\033[93m"
|
||||||
brightMagenta = "\033[95m"
|
brightMagenta = "\033[95m"
|
||||||
brightRed = "\033[91m"
|
brightRed = "\033[91m"
|
||||||
|
brightGreen = "\033[92m"
|
||||||
darkMagenta = "\033[35m"
|
darkMagenta = "\033[35m"
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user