Finished paper support; Created independent paths

Changes:
- Created OS independent paths
- finished paper support
- created many catches for paper handling errors
This commit is contained in:
Neocky 2021-03-16 01:04:13 +01:00
parent 5e296e858f
commit 430dbcd8d2
8 changed files with 132 additions and 65 deletions

View File

@ -1,13 +1,13 @@
import os import os
import sys import sys
import configparser import configparser
from pathlib import Path
from utils.consoleoutput import oColors from utils.consoleoutput import oColors
def checkConfig(): def checkConfig():
currentFolder = os.getcwd() currentFolder = os.getcwd()
os.chdir('..')
configAvailable = os.path.isfile("config.ini") configAvailable = os.path.isfile("config.ini")
if not configAvailable: if not configAvailable:
@ -21,9 +21,9 @@ def checkConfig():
config.sections() config.sections()
config.read("config.ini") config.read("config.ini")
localPluginFolder = config['General']['LocalPluginFolder'] localPluginFolder = config['General']['LocalPluginFolder']
pathToPluginFolder = config['General']['PathToPluginFolder'] pathToPluginFolder = Path(config['General']['PathToPluginFolder'])
seperateDownloadPath = config['General']['SeperateDownloadPath'] seperateDownloadPath = config['General']['SeperateDownloadPath']
pathToSeperateDownloadPath = config['General']['PathToSeperateDownloadPath'] pathToSeperateDownloadPath = Path(config['General']['PathToSeperateDownloadPath'])
sftp_server = config['SFTP - Remote Server']['Server'] sftp_server = config['SFTP - Remote Server']['Server']
sftp_user = config['SFTP - Remote Server']['Username'] sftp_user = config['SFTP - Remote Server']['Username']
@ -75,5 +75,5 @@ def createConfig():
config['SFTP - Remote Server']['PathToSeperateDownloadPath'] = '.\\plugins' config['SFTP - Remote Server']['PathToSeperateDownloadPath'] = '.\\plugins'
with open('./config.ini', 'w') as configfile: with open('config.ini', 'w') as configfile:
config.write(configfile) config.write(configfile)

View File

@ -1,6 +1,7 @@
import re import re
import urllib.request import urllib.request
from urllib.error import HTTPError from urllib.error import HTTPError
from pathlib import Path
from utils.consoleoutput import oColors from utils.consoleoutput import oColors
from utils.web_request import doAPIRequest from utils.web_request import doAPIRequest
@ -119,7 +120,7 @@ def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
versionId = getVersionID(ressourceId, inputPackageVersion) versionId = getVersionID(ressourceId, inputPackageVersion)
packageVersion = getVersionName(ressourceId, versionId) packageVersion = getVersionName(ressourceId, versionId)
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar" packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
downloadPackagePath = f"{downloadPath}\\{packageDownloadName}" downloadPackagePath = Path(f"{downloadPath}/{packageDownloadName}")
if checkConfig().localPluginFolder: if checkConfig().localPluginFolder:
if inputPackageVersion is None or inputPackageVersion == 'latest': if inputPackageVersion is None or inputPackageVersion == 'latest':
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath) downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)

View File

@ -1,5 +1,6 @@
import os import os
import re import re
from pathlib import Path
from utils.consoleoutput import oColors from utils.consoleoutput import oColors
from handlers.handle_config import checkConfig from handlers.handle_config import checkConfig
@ -29,7 +30,7 @@ def removePlugin(pluginToRemove):
print(f"Removing: {fileName}") print(f"Removing: {fileName}")
if not checkConfig().localPluginFolder: if not checkConfig().localPluginFolder:
pluginPath = checkConfig().sftp_folderPath pluginPath = checkConfig().sftp_folderPath
pluginPath = f"{pluginPath}\\{plugin}" pluginPath = f"{pluginPath}/{plugin}"
sftp = createSFTPConnection() sftp = createSFTPConnection()
sftp.remove(pluginPath) sftp.remove(pluginPath)
print(f"Removed: {fileName}") print(f"Removed: {fileName}")
@ -37,7 +38,7 @@ def removePlugin(pluginToRemove):
break break
else: else:
pluginPath = checkConfig().pathToPluginFolder pluginPath = checkConfig().pathToPluginFolder
pluginPath = f"{pluginPath}\\{plugin}" pluginPath = Path(f"{pluginPath}/{plugin}")
os.remove(pluginPath) os.remove(pluginPath)
print(f"Removed: {fileName}") print(f"Removed: {fileName}")
i += 1 i += 1

View File

@ -1,6 +1,7 @@
import os import os
import re import re
from urllib.error import HTTPError from urllib.error import HTTPError
from pathlib import Path
from utils.consoleoutput import oColors from utils.consoleoutput import oColors
from utils.web_request import doAPIRequest from utils.web_request import doAPIRequest
@ -138,6 +139,8 @@ def updateInstalledPackage(inputSelectedObject='all'):
fileVersion = getFileVersion(plugin) fileVersion = getFileVersion(plugin)
pluginId = getInstalledPlugin(fileName, fileVersion) pluginId = getInstalledPlugin(fileName, fileVersion)
latestVersion = getLatestPluginVersion(pluginId) latestVersion = getLatestPluginVersion(pluginId)
print(fileName)
print(fileVersion)
except TypeError: except TypeError:
continue continue
except ValueError: except ValueError:
@ -147,7 +150,7 @@ def updateInstalledPackage(inputSelectedObject='all'):
if pluginId == None: if pluginId == None:
print(oColors.brightRed + "Couldn't find plugin id. Sorry :(" + oColors.standardWhite) print(oColors.brightRed + "Couldn't find plugin id. Sorry :(" + oColors.standardWhite)
continue continue
print(INSTALLEDPLUGINLIST[i])
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" [{indexNumberUpdated+1}]".ljust(8), end='') print(f" [{indexNumberUpdated+1}]".ljust(8), end='')
@ -161,7 +164,7 @@ def updateInstalledPackage(inputSelectedObject='all'):
pluginPath = checkConfig().sftp_pathToSeperateDownloadPath pluginPath = checkConfig().sftp_pathToSeperateDownloadPath
else: else:
pluginPath = checkConfig().sftp_folderPath pluginPath = checkConfig().sftp_folderPath
pluginPath = f"{pluginPath}\\{plugin}" pluginPath = Path(f"{pluginPath}/{plugin}")
sftp = createSFTPConnection() sftp = createSFTPConnection()
indexNumberUpdated += 1 indexNumberUpdated += 1
pluginsUpdated += 1 pluginsUpdated += 1
@ -173,13 +176,13 @@ def updateInstalledPackage(inputSelectedObject='all'):
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite) print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
pluginsUpdated -= 1 pluginsUpdated -= 1
except FileNotFoundError: except FileNotFoundError:
print(oColors.brightRed + f"Error: Old plugin file coulnd't be deleted" + oColors.standardWhite) print(oColors.brightRed + "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 = Path(f"{pluginPath}/{plugin}")
indexNumberUpdated += 1 indexNumberUpdated += 1
pluginsUpdated += 1 pluginsUpdated += 1
try: try:
@ -211,7 +214,7 @@ def updateInstalledPackage(inputSelectedObject='all'):
else: else:
pluginPath = checkConfig().sftp_folderPath pluginPath = checkConfig().sftp_folderPath
pluginPath = checkConfig().sftp_folderPath pluginPath = checkConfig().sftp_folderPath
pluginPath = f"{pluginPath}\\{plugin}" pluginPath = f"{pluginPath}/{plugin}"
sftp = createSFTPConnection() sftp = createSFTPConnection()
indexNumberUpdated += 1 indexNumberUpdated += 1
pluginsUpdated += 1 pluginsUpdated += 1
@ -230,7 +233,7 @@ def updateInstalledPackage(inputSelectedObject='all'):
pluginPath = checkConfig().pathToSeperateDownloadPath pluginPath = checkConfig().pathToSeperateDownloadPath
else: else:
pluginPath = checkConfig().pathToPluginFolder pluginPath = checkConfig().pathToPluginFolder
pluginPath = f"{pluginPath}\\{plugin}" pluginPath = Path(f"{pluginPath}/{plugin}")
indexNumberUpdated += 1 indexNumberUpdated += 1
pluginsUpdated += 1 pluginsUpdated += 1
try: try:
@ -254,13 +257,13 @@ def updateInstalledPackage(inputSelectedObject='all'):
def getInstalledPlugin(localFileName, localFileVersion): def getInstalledPlugin(localFileName, localFileVersion):
url = "https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name&sort=-downloads" url = "https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name&sort=-downloads"
packageName = doAPIRequest(url) packageName = doAPIRequest(url)
i = 1 #i = 1
plugin_match_found = False plugin_match_found = False
pluginID = None pluginID = None
for ressource in packageName: for ressource in packageName:
if plugin_match_found == True: if plugin_match_found == True:
plugin_match_found = False
break break
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)
@ -273,23 +276,19 @@ def getInstalledPlugin(localFileName, localFileVersion):
plugin_latest_version = getLatestPluginVersion(pID) plugin_latest_version = getLatestPluginVersion(pID)
plugin_is_outdated = compareVersions(plugin_latest_version, updateVersion) plugin_is_outdated = compareVersions(plugin_latest_version, updateVersion)
addToPluginList(pID, updateId, plugin_latest_version , plugin_is_outdated) addToPluginList(pID, updateId, plugin_latest_version , plugin_is_outdated)
break print("in if")
print(plugin_match_found)
return pluginID # just testing
#break
i = i + 1 else: # TODO fix duplicate entrys when update all
else:
if plugin_match_found != True: if plugin_match_found != True:
pID = None pID = None
updateId = None updateId = None
plugin_latest_version = None plugin_latest_version = None
plugin_is_outdated = None plugin_is_outdated = None
addToPluginList(pID, updateId, plugin_latest_version , plugin_is_outdated) addToPluginList(pID, updateId, plugin_latest_version , plugin_is_outdated)
print("in else")
print(plugin_match_found)
return pluginID return pluginID
# start query
# get id
# search with id for all version upates
# get version that matches installed version
# if match then download latest update
# else get second query

View File

View File

@ -1,6 +1,7 @@
import os import os
import sys import sys
from urllib.error import HTTPError from urllib.error import HTTPError
from pathlib import Path
from handlers.handle_sftp import createSFTPConnection, sftp_listFilesInServerRoot from handlers.handle_sftp import createSFTPConnection, sftp_listFilesInServerRoot
from handlers.handle_config import checkConfig from handlers.handle_config import checkConfig
@ -14,7 +15,6 @@ def checkInstalledServerjar():
serverRootList = sftp_listFilesInServerRoot(sftp) serverRootList = sftp_listFilesInServerRoot(sftp)
else: else:
serverRootList = os.path.dirname(checkConfig().pathToPluginFolder) serverRootList = os.path.dirname(checkConfig().pathToPluginFolder)
os.chdir('..')
serverRootList = os.listdir(serverRootList) serverRootList = os.listdir(serverRootList)
installedServerjarFullName = None installedServerjarFullName = None
try: try:
@ -44,16 +44,31 @@ def checkInstalledServerjar():
def updateServerjar(serverJarBuild='latest'): def updateServerjar(serverJarBuild='latest'):
try:
if serverJarBuild == None: if serverJarBuild == None:
serverJarBuild = 'latest' serverJarBuild = 'latest'
if not checkConfig().localPluginFolder: if not checkConfig().localPluginFolder:
sftp = createSFTPConnection() sftp = createSFTPConnection()
serverRootPath = checkConfig().sftp_folderPath
serverRootPath = Path(str(serverRootPath).replace(r'/plugins', ''))
serverRootList = sftp_listFilesInServerRoot(sftp) serverRootList = sftp_listFilesInServerRoot(sftp)
else: else:
serverRoot = os.path.dirname(checkConfig().pathToPluginFolder) serverRoot = os.path.dirname(checkConfig().pathToPluginFolder)
os.chdir('..')
serverRootList = os.listdir(serverRoot) serverRootList = os.listdir(serverRoot)
serverRootPath = checkConfig().pathToPluginFolder
helpPath = Path('/plugins')
helpPathstr = str(helpPath)
serverRootPath = Path(str(serverRootPath).replace(helpPathstr, ''))
installedServerjarFullName = None installedServerjarFullName = None
except FileNotFoundError:
print(oColors.brightRed + "Path couldn't be found!" + oColors.standardWhite)
print(oColors.brightRed + "Check your config!" + oColors.standardWhite)
print(oColors.brightRed + "Aborting the process." + oColors.standardWhite)
input("Press any key + enter to exit...")
sys.exit()
try: try:
for files in serverRootList: for files in serverRootList:
try: try:
@ -72,12 +87,27 @@ def updateServerjar(serverJarBuild='latest'):
input("Press any key + enter to exit...") input("Press any key + enter to exit...")
sys.exit() sys.exit()
serverJarPath = Path(f"{serverRootPath}/{installedServerjarFullName}")
if 'paper' in installedServerjarFullName: if 'paper' in installedServerjarFullName:
print(serverJarBuild) print(f"Updating Paper to build: {serverJarBuild}")
if not checkConfig().localPluginFolder:
try: try:
papermc_downloader(serverJarBuild, installedServerjarFullName) papermc_downloader(serverJarBuild, installedServerjarFullName)
sftp.remove(serverJarPath)
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)
except FileNotFoundError:
print(oColors.brightRed + "Error: Old serverjar file coulnd't be deleted" + oColors.standardWhite)
else:
try:
papermc_downloader(serverJarBuild, installedServerjarFullName)
os.remove(serverJarPath)
except HTTPError as err:
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
except FileNotFoundError:
print(oColors.brightRed + "Error: Old serverjar file coulnd't be deleted" + oColors.standardWhite)
else: else:
print(oColors.brightRed + f"{installedServerjarFullName} isn't supported.") print(oColors.brightRed + f"{installedServerjarFullName} isn't supported.")

View File

@ -2,14 +2,13 @@ import os
import sys import sys
import re import re
import urllib.request import urllib.request
from pathlib import Path
from utils.consoleoutput import oColors from utils.consoleoutput import oColors
from utils.web_request import doAPIRequest from utils.web_request import doAPIRequest
from handlers.handle_sftp import sftp_upload_server_jar, sftp_cdPluginDir, createSFTPConnection from handlers.handle_sftp import sftp_upload_server_jar, sftp_cdPluginDir, createSFTPConnection
from handlers.handle_config import checkConfig from handlers.handle_config import checkConfig
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder from utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calculateFileSizeMb
from plugin.plugin_downloader import calculateFileSize
# = 1.16.5 # = 1.16.5
@ -50,12 +49,29 @@ def findVersionGroup(mcVersion):
if versionGroup == mcVersion: if versionGroup == mcVersion:
versionGroupFound = True versionGroupFound = True
paperVersionGroup = versionGroup paperVersionGroup = versionGroup
print(versionGroup)
break break
return paperVersionGroup return paperVersionGroup
def findBuildVersion(wantedPaperBuild):
versionGroups = ['1.16', '1.15']
paperBuildFound = 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
def findLatestBuild(paperVersionGroup): def findLatestBuild(paperVersionGroup):
url = f"https://papermc.io/api/v2/projects/paper/version_group/{paperVersionGroup}/builds" url = f"https://papermc.io/api/v2/projects/paper/version_group/{paperVersionGroup}/builds"
papermcbuilds = doAPIRequest(url) papermcbuilds = doAPIRequest(url)
@ -63,6 +79,13 @@ def findLatestBuild(paperVersionGroup):
return latestPaperBuild return latestPaperBuild
def findLatestBuildForVersion(mcVersion):
url = f"https://papermc.io/api/v2/projects/paper/versions/{mcVersion}"
papermcbuilds = doAPIRequest(url)
latestPaperBuild = papermcbuilds["builds"][-1]
return latestPaperBuild
def versionBehind(installedPaperBuild, latestPaperBuild): def versionBehind(installedPaperBuild, latestPaperBuild):
installedPaperBuildint = int(installedPaperBuild) installedPaperBuildint = int(installedPaperBuild)
latestPaperBuildint = int(latestPaperBuild) latestPaperBuildint = int(latestPaperBuild)
@ -70,7 +93,6 @@ def versionBehind(installedPaperBuild, latestPaperBuild):
return versionsBehind return versionsBehind
def getDownloadFileName(paperMcVersion, paperBuild): def getDownloadFileName(paperMcVersion, paperBuild):
url = f"https://papermc.io/api/v2/projects/paper/versions/{paperMcVersion}/builds/{paperBuild}" url = f"https://papermc.io/api/v2/projects/paper/versions/{paperMcVersion}/builds/{paperBuild}"
buildDetails = doAPIRequest(url) buildDetails = doAPIRequest(url)
@ -86,9 +108,9 @@ def paperCheckForUpdate(installedServerjarFullName):
paperVersionBehind = versionBehind(paperInstalledBuild, paperLatestBuild) paperVersionBehind = versionBehind(paperInstalledBuild, paperLatestBuild)
print(f"Paper for {mcVersion}") print(f"Paper for {mcVersion}")
print("Index | Name | Old V. | New V. | Versions behind ") print("Index | Name | Installed V. | Latest V. | Versions behind ")
print(f" [1]".ljust(8), end='') print(f" [1]".ljust(8), end='')
print(f"paper".ljust(24), end='') print(f"paper".ljust(21), end='')
print(f"{paperInstalledBuild}".ljust(8), end='') print(f"{paperInstalledBuild}".ljust(8), end='')
print(" ", end='') print(" ", end='')
print(f"{paperLatestBuild}".ljust(8), end='') print(f"{paperLatestBuild}".ljust(8), end='')
@ -102,27 +124,30 @@ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersi
downloadPath = createTempPluginFolder() downloadPath = createTempPluginFolder()
else: else:
downloadPath = checkConfig().pathToPluginFolder downloadPath = checkConfig().pathToPluginFolder
downloadPath = downloadPath.replace(r'\plugins', '') helpPath = Path('/plugins')
helpPathstr = str(helpPath)
downloadPath = Path(str(downloadPath).replace(helpPathstr, ''))
if mcVersion == None: if mcVersion == None:
if paperBuild == 'latest':
mcVersion = '1.16.5' mcVersion = '1.16.5'
else:
mcVersion = findBuildVersion(paperBuild)
if installedServerjarName != None: if installedServerjarName != None:
mcVersion = getInstalledPaperMinecraftVersion(installedServerjarName) mcVersion = getInstalledPaperMinecraftVersion(installedServerjarName)
if paperBuild == 'latest': if paperBuild == 'latest':
versionGroup = findVersionGroup(mcVersion) paperBuild = findLatestBuildForVersion(mcVersion)
paperBuild = findLatestBuild(versionGroup)
try: try:
downloadFileName = getDownloadFileName(mcVersion, paperBuild) downloadFileName = getDownloadFileName(mcVersion, paperBuild)
except KeyError: except KeyError:
print(oColors.brightRed + f"This version wasn't found for {mcVersion}" + oColors.standardWhite) print(oColors.brightRed + f"This version wasn't found for {mcVersion}" + oColors.standardWhite)
print(oColors.brightRed + f"Reverting to latest version for {mcVersion}" + oColors.standardWhite) print(oColors.brightRed + f"Reverting to latest version for {mcVersion}" + oColors.standardWhite)
versionGroup = findVersionGroup(mcVersion) paperBuild = findLatestBuildForVersion(mcVersion)
paperBuild = findLatestBuild(versionGroup)
downloadFileName = getDownloadFileName(mcVersion, paperBuild) downloadFileName = getDownloadFileName(mcVersion, paperBuild)
downloadPackagePath = f"{downloadPath}\\{downloadFileName}" downloadPackagePath = Path(f"{downloadPath}/{downloadFileName}")
if checkConfig().localPluginFolder == False: if checkConfig().localPluginFolder == False:
downloadPath = createTempPluginFolder() downloadPath = createTempPluginFolder()
@ -130,13 +155,16 @@ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersi
url = f"https://papermc.io/api/v2/projects/paper/versions/{mcVersion}/builds/{paperBuild}/downloads/{downloadFileName}" url = f"https://papermc.io/api/v2/projects/paper/versions/{mcVersion}/builds/{paperBuild}/downloads/{downloadFileName}"
remotefile = urllib.request.urlopen(url) remotefile = urllib.request.urlopen(url)
filesize = remotefile.info()['Content-Length'] filesize = remotefile.info()['Content-Length']
print(f"Starting paper-{paperBuild} download for {mcVersion}...") print(f"Starting Paper-{paperBuild} download for {mcVersion}...")
urllib.request.urlretrieve(url, downloadPackagePath) urllib.request.urlretrieve(url, downloadPackagePath)
filesizeData = calculateFileSize(filesize) filesizeData = calculateFileSizeMb(filesize)
print(f"Downloadsize: {filesizeData} KB") print(f"Downloadsize: {filesizeData} MB")
print(f"File downloaded here: {downloadPackagePath}") print(f"File downloaded here: {downloadPackagePath}")
if not checkConfig().localPluginFolder: if not checkConfig().localPluginFolder:
sftpSession = createSFTPConnection() sftpSession = createSFTPConnection()
sftp_upload_server_jar(sftpSession, downloadPackagePath) sftp_upload_server_jar(sftpSession, downloadPackagePath)
deleteTempPluginFolder(downloadPath) deleteTempPluginFolder(downloadPath)
print(oColors.brightGreen + "Downloaded successfully " + oColors.standardWhite + f"Paper-{paperBuild}" + \
oColors.brightGreen + " for " + oColors.standardWhite + f"{mcVersion}" + oColors.standardWhite)

View File

@ -3,6 +3,7 @@ import os
import sys import sys
import shutil import shutil
import requests import requests
from pathlib import Path
from utils.consoleoutput import oColors from utils.consoleoutput import oColors
from handlers.handle_config import checkConfig from handlers.handle_config import checkConfig
@ -59,7 +60,7 @@ def check_requirements():
def createTempPluginFolder(): def createTempPluginFolder():
tempPluginFolder = ".\\TempSFTPUploadFolder" tempPluginFolder = Path("./TempSFTPUploadFolder")
if not os.path.isdir(tempPluginFolder): if not os.path.isdir(tempPluginFolder):
try: try:
os.mkdir(tempPluginFolder) os.mkdir(tempPluginFolder)
@ -76,3 +77,10 @@ def deleteTempPluginFolder(tempPluginFolder):
shutil.rmtree(tempPluginFolder) shutil.rmtree(tempPluginFolder)
except OSError as e: except OSError as e:
print ("Error: %s - %s." % (e.filename, e.strerror)) print ("Error: %s - %s." % (e.filename, e.strerror))
def calculateFileSizeMb(downloadFileSize):
fileSizeDownload = int(downloadFileSize)
fileSizeMb = fileSizeDownload / 1024 / 1024
roundedFileSize = round(fileSizeMb, 2)
return roundedFileSize