Better config handling & better output for serverjar

Changes:
- better config handling
- better output for serverjar checking
This commit is contained in:
Neocky
2021-03-27 12:07:19 +01:00
parent 17611c741e
commit fddc0c252c
9 changed files with 100 additions and 127 deletions

View File

@@ -4,17 +4,18 @@ from urllib.error import HTTPError
from pathlib import Path
from handlers.handle_sftp import createSFTPConnection, sftp_listFilesInServerRoot
from handlers.handle_config import checkConfig
from handlers.handle_config import configurationValues
from utils.consoleoutput import oColors
from serverjar.serverjar_paper import paperCheckForUpdate, papermc_downloader
def checkInstalledServerjar():
if not checkConfig().localPluginFolder:
configValues = configurationValues()
if not configValues.localPluginFolder:
sftp = createSFTPConnection()
serverRootList = sftp_listFilesInServerRoot(sftp)
else:
serverRootList = os.path.dirname(checkConfig().pathToPluginFolder)
serverRootList = os.path.dirname(configValues.pathToPluginFolder)
serverRootList = os.listdir(serverRootList)
installedServerjarFullName = None
try:
@@ -34,7 +35,7 @@ def checkInstalledServerjar():
print(oColors.brightRed + "Aborting the process." + oColors.standardWhite)
input("Press any key + enter to exit...")
sys.exit()
print(oColors.brightBlack + f"Checking: {installedServerjarFullName}" + oColors.standardWhite)
if 'paper' in installedServerjarFullName:
paperCheckForUpdate(installedServerjarFullName)
@@ -44,19 +45,20 @@ def checkInstalledServerjar():
def updateServerjar(serverJarBuild='latest'):
configValues = configurationValues()
try:
if serverJarBuild == None:
serverJarBuild = 'latest'
if not checkConfig().localPluginFolder:
if not configValues.localPluginFolder:
sftp = createSFTPConnection()
serverRootPath = checkConfig().sftp_folderPath
serverRootPath = configValues.sftp_folderPath
serverRootPath = Path(str(serverRootPath).replace(r'/plugins', ''))
serverRootList = sftp_listFilesInServerRoot(sftp)
else:
serverRoot = os.path.dirname(checkConfig().pathToPluginFolder)
serverRoot = os.path.dirname(configValues.pathToPluginFolder)
serverRootList = os.listdir(serverRoot)
serverRootPath = checkConfig().pathToPluginFolder
serverRootPath = configValues.pathToPluginFolder
helpPath = Path('/plugins')
helpPathstr = str(helpPath)
serverRootPath = Path(str(serverRootPath).replace(helpPathstr, ''))
@@ -91,7 +93,7 @@ def updateServerjar(serverJarBuild='latest'):
if 'paper' in installedServerjarFullName:
print(f"Updating Paper to build: {serverJarBuild}")
if not checkConfig().localPluginFolder:
if not configValues.localPluginFolder:
try:
papermc_downloader(serverJarBuild, installedServerjarFullName)
sftp.remove(serverJarPath)

View File

@@ -7,7 +7,7 @@ from pathlib import Path
from utils.consoleoutput import oColors
from utils.web_request import doAPIRequest
from handlers.handle_sftp import sftp_upload_server_jar, sftp_cdPluginDir, createSFTPConnection
from handlers.handle_config import checkConfig
from handlers.handle_config import configurationValues
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calculateFileSizeMb
@@ -107,23 +107,24 @@ def paperCheckForUpdate(installedServerjarFullName):
paperLatestBuild = findLatestBuild(versionGroup)
paperVersionBehind = versionBehind(paperInstalledBuild, paperLatestBuild)
print(f"Paper for {mcVersion}")
print("Index | Name | Installed V. | Latest V. | Versions behind ")
print(f" [1]".ljust(8), end='')
print(f"paper".ljust(21), end='')
print(f"{paperInstalledBuild}".ljust(8), end='')
print(" ", end='')
print(f"{paperLatestBuild}".ljust(8), end='')
print(" ", end='')
print("┌─────┬────────────────────────────────┬──────────────┬──────────────┬───────────────────┐")
print("│ No. │ Name Installed V. Latest V. Versions behind ")
print("└─────┴────────────────────────────────┴──────────────┴──────────────┴───────────────────┘")
print(" [1]".rjust(6), end='')
print(" ", end='')
print("paper".ljust(33), end='')
print(f"{paperInstalledBuild}".ljust(15), end='')
print(f"{paperLatestBuild}".ljust(15), end='')
print(f"{paperVersionBehind}".ljust(8))
# https://papermc.io/api/docs/swagger-ui/index.html?configUrl=/api/openapi/swagger-config#/
def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersion=None):
if checkConfig().localPluginFolder == False:
configValues = configurationValues()
if configValues.localPluginFolder == False:
downloadPath = createTempPluginFolder()
else:
downloadPath = checkConfig().pathToPluginFolder
downloadPath = configValues.pathToPluginFolder
helpPath = Path('/plugins')
helpPathstr = str(helpPath)
downloadPath = Path(str(downloadPath).replace(helpPathstr, ''))
@@ -149,7 +150,7 @@ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersi
downloadPackagePath = Path(f"{downloadPath}/{downloadFileName}")
if checkConfig().localPluginFolder == False:
if configValues.localPluginFolder == False:
downloadPath = createTempPluginFolder()
url = f"https://papermc.io/api/v2/projects/paper/versions/{mcVersion}/builds/{paperBuild}/downloads/{downloadFileName}"
@@ -161,7 +162,7 @@ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersi
print(f"Downloadsize: {filesizeData} MB")
print(f"File downloaded here: {downloadPackagePath}")
if not checkConfig().localPluginFolder:
if not configValues.localPluginFolder:
sftpSession = createSFTPConnection()
sftp_upload_server_jar(sftpSession, downloadPackagePath)
deleteTempPluginFolder(downloadPath)