Catched FileNotfoundError & Plugins updated will now display correctly

Changes:
- Catched file not found error
- Plugins updated
- Updated wrong index numbers when updating
This commit is contained in:
Neocky 2021-03-14 20:21:26 +01:00
parent 053a67e2d8
commit 662f303935
2 changed files with 51 additions and 19 deletions

View File

@ -116,15 +116,9 @@ def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
downloadPackagePath = f"{downloadPath}\\{packageDownloadName}" downloadPackagePath = f"{downloadPath}\\{packageDownloadName}"
if checkConfig().localPluginFolder: if checkConfig().localPluginFolder:
if inputPackageVersion is None or inputPackageVersion == 'latest': if inputPackageVersion is None or inputPackageVersion == 'latest':
try:
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath) downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)
except HTTPError as err:
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
else: else:
try:
downloadSpecificVersion(ressourceId, downloadPackagePath, versionId) downloadSpecificVersion(ressourceId, downloadPackagePath, versionId)
except HTTPError as err:
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
if not checkConfig().localPluginFolder: if not checkConfig().localPluginFolder:
if inputPackageVersion is None or inputPackageVersion == 'latest': if inputPackageVersion is None or inputPackageVersion == 'latest':

View File

@ -1,5 +1,6 @@
import os import os
import re import re
from urllib.error import HTTPError
from utils.consoleoutput import oColors from utils.consoleoutput import oColors
from utils.web_request import doAPIRequest from utils.web_request import doAPIRequest
@ -127,6 +128,7 @@ def updateInstalledPackage(inputSelectedObject='all'):
pluginList = os.listdir(checkConfig().pathToPluginFolder) pluginList = os.listdir(checkConfig().pathToPluginFolder)
i = 0 i = 0
pluginsUpdated = 0 pluginsUpdated = 0
indexNumberUpdated = 0
print(f"Updating: {inputSelectedObject}") print(f"Updating: {inputSelectedObject}")
print("Index | Name | Old V. | New V.") print("Index | Name | Old V. | New V.")
try: try:
@ -148,28 +150,47 @@ def updateInstalledPackage(inputSelectedObject='all'):
if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE): if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
if INSTALLEDPLUGINLIST[i][3] == True: if INSTALLEDPLUGINLIST[i][3] == True:
print(f" [{pluginsUpdated+1}]".ljust(8), end='') print(f" [{indexNumberUpdated+1}]".ljust(8), end='')
print(f"{fileName}".ljust(30), end='') print(f"{fileName}".ljust(30), end='')
print(f"{fileVersion}".ljust(8), end='') print(f"{fileVersion}".ljust(8), end='')
print(" ", end='') print(" ", end='')
print(f"{latestVersion}".ljust(8)) print(f"{latestVersion}".ljust(8))
if not checkConfig().localPluginFolder: if not checkConfig().localPluginFolder:
if checkConfig().sftp_pathToSeperateDownloadPath is True:
pluginPath = checkConfig().sftp_pathToSeperateDownloadPath
else:
pluginPath = checkConfig().sftp_folderPath pluginPath = checkConfig().sftp_folderPath
pluginPath = f"{pluginPath}\\{plugin}" pluginPath = f"{pluginPath}\\{plugin}"
sftp = createSFTPConnection() sftp = createSFTPConnection()
sftp.remove(pluginPath) indexNumberUpdated += 1
getSpecificPackage(pluginId, checkConfig().sftp_folderPath)
pluginsUpdated += 1 pluginsUpdated += 1
try:
getSpecificPackage(pluginId, checkConfig().sftp_folderPath)
if checkConfig().sftp_seperateDownloadPath is False:
sftp.remove(pluginPath)
except HTTPError as err:
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
pluginsUpdated -= 1
except FileNotFoundError:
print(oColors.brightRed + f"Error: Old plugin file coulnd't be deleted" + oColors.standardWhite)
else: else:
if checkConfig().seperateDownloadPath is True: if checkConfig().seperateDownloadPath is True:
pluginPath = checkConfig().pathToSeperateDownloadPath pluginPath = checkConfig().pathToSeperateDownloadPath
else: else:
pluginPath = checkConfig().pathToPluginFolder pluginPath = checkConfig().pathToPluginFolder
pluginPath = f"{pluginPath}\\{plugin}" pluginPath = f"{pluginPath}\\{plugin}"
os.remove(pluginPath) indexNumberUpdated += 1
getSpecificPackage(pluginId, checkConfig().pathToPluginFolder)
pluginsUpdated += 1 pluginsUpdated += 1
try:
getSpecificPackage(pluginId, checkConfig().pathToPluginFolder)
if checkConfig().seperateDownloadPath is False:
os.remove(pluginPath)
except HTTPError as err:
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
pluginsUpdated -= 1
except FileNotFoundError:
print(oColors.brightRed + f"Error: Old plugin file coulnd't be deleted" + oColors.standardWhite)
break break
else: else:
print(f"{fileName} is already on {latestVersion}") print(f"{fileName} is already on {latestVersion}")
@ -178,7 +199,7 @@ def updateInstalledPackage(inputSelectedObject='all'):
if inputSelectedObject == 'all': if inputSelectedObject == 'all':
if INSTALLEDPLUGINLIST[i][3] == True: if INSTALLEDPLUGINLIST[i][3] == True:
print(f" [{pluginsUpdated+1}]".ljust(8), end='') print(f" [{indexNumberUpdated+1}]".ljust(8), end='')
print(f"{fileName}".ljust(30), end='') print(f"{fileName}".ljust(30), end='')
print(f"{fileVersion}".ljust(8), end='') print(f"{fileVersion}".ljust(8), end='')
print(" ", end='') print(" ", end='')
@ -192,9 +213,17 @@ def updateInstalledPackage(inputSelectedObject='all'):
pluginPath = checkConfig().sftp_folderPath pluginPath = checkConfig().sftp_folderPath
pluginPath = f"{pluginPath}\\{plugin}" pluginPath = f"{pluginPath}\\{plugin}"
sftp = createSFTPConnection() sftp = createSFTPConnection()
sftp.remove(pluginPath) indexNumberUpdated += 1
getSpecificPackage(pluginId, checkConfig().sftp_folderPath)
pluginsUpdated += 1 pluginsUpdated += 1
try:
getSpecificPackage(pluginId, checkConfig().sftp_folderPath)
if checkConfig().sftp_seperateDownloadPath is False:
sftp.remove(pluginPath)
except HTTPError as err:
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
pluginsUpdated -= 1
except FileNotFoundError:
print(oColors.brightRed + f"Error: Old plugin file coulnd't be deleted" + oColors.standardWhite)
else: else:
if checkConfig().seperateDownloadPath is True: if checkConfig().seperateDownloadPath is True:
@ -202,9 +231,18 @@ def updateInstalledPackage(inputSelectedObject='all'):
else: else:
pluginPath = checkConfig().pathToPluginFolder pluginPath = checkConfig().pathToPluginFolder
pluginPath = f"{pluginPath}\\{plugin}" pluginPath = f"{pluginPath}\\{plugin}"
os.remove(pluginPath) indexNumberUpdated += 1
getSpecificPackage(pluginId, checkConfig().pathToPluginFolder)
pluginsUpdated += 1 pluginsUpdated += 1
try:
getSpecificPackage(pluginId, checkConfig().pathToPluginFolder)
if checkConfig().seperateDownloadPath is False:
os.remove(pluginPath)
except HTTPError as err:
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
pluginsUpdated -= 1
except FileNotFoundError:
print(oColors.brightRed + f"Error: Old plugin file coulnd't be deleted" + oColors.standardWhite)
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)