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

@ -1,14 +1,14 @@
from utils.consoleoutput import consoleTitle, clearConsole, printMainMenu from utils.consoleoutput import consoleTitle, clearConsole, printMainMenu
from utils.utilities import check_requirements from utils.utilities import check_requirements
from handlers.handle_input import createInputLists, getInput from handlers.handle_input import createInputLists, getInput
from handlers.handle_config import checkConfig, configurationValues from handlers.handle_config import checkConfig
def mainFunction(): def mainFunction():
consoleTitle() consoleTitle()
clearConsole() clearConsole()
#checkConfig() checkConfig()
#check_requirements() check_requirements()
createInputLists() createInputLists()
printMainMenu() printMainMenu()
getInput() getInput()

View File

@ -7,43 +7,41 @@ from utils.consoleoutput import oColors
class configurationValues: class configurationValues:
def __init__(self): config = configparser.ConfigParser()
config = configparser.ConfigParser() config.sections()
config.sections() config.read("config.ini")
config.read("config.ini") localPluginFolder = config['General']['LocalPluginFolder']
localPluginFolder = config['General']['LocalPluginFolder'] pathToPluginFolder = Path(config['General']['PathToPluginFolder'])
self.pathToPluginFolder = Path(config['General']['PathToPluginFolder']) seperateDownloadPath = config['General']['SeperateDownloadPath']
seperateDownloadPath = config['General']['SeperateDownloadPath'] pathToSeperateDownloadPath = Path(config['General']['PathToSeperateDownloadPath'])
self.pathToSeperateDownloadPath = Path(config['General']['PathToSeperateDownloadPath'])
self.sftp_server = config['SFTP - Remote Server']['Server'] sftp_server = config['SFTP - Remote Server']['Server']
self.sftp_user = config['SFTP - Remote Server']['Username'] sftp_user = config['SFTP - Remote Server']['Username']
self.sftp_password = config['SFTP - Remote Server']['Password'] sftp_password = config['SFTP - Remote Server']['Password']
sftp_port = config['SFTP - Remote Server']['Port'] sftp_port = config['SFTP - Remote Server']['Port']
self.sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer'] sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer']
sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath'] sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath']
self.sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath'] sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath']
self.sftp_port = int(sftp_port) sftp_port = int(sftp_port)
if localPluginFolder == 'True': if localPluginFolder == 'True':
self.localPluginFolder = True localPluginFolder = True
else: else:
self.localPluginFolder = False localPluginFolder = False
if seperateDownloadPath == 'True': if seperateDownloadPath == 'True':
self.seperateDownloadPath = True seperateDownloadPath = True
else: else:
self.seperateDownloadPath = False seperateDownloadPath = False
if sftp_seperateDownloadPath == 'True':
self.sftp_seperateDownloadPath = True
else:
self.sftp_seperateDownloadPath = False
if sftp_seperateDownloadPath == 'True':
sftp_seperateDownloadPath = True
else:
sftp_seperateDownloadPath = False
def checkConfig(): def checkConfig():
currentFolder = os.getcwd() #currentFolder = os.getcwd()
configAvailable = os.path.isfile("config.ini") configAvailable = os.path.isfile("config.ini")
if not configAvailable: if not configAvailable:
@ -51,42 +49,7 @@ def checkConfig():
print(oColors.brightRed + "Config created. Edit config before executing again!" + oColors.standardWhite) print(oColors.brightRed + "Config created. Edit config before executing again!" + oColors.standardWhite)
input("Press any key + enter to exit...") input("Press any key + enter to exit...")
sys.exit() sys.exit()
#os.chdir(currentFolder)
#class configValues:
# config = configparser.ConfigParser()
# config.sections()
# config.read("config.ini")
# localPluginFolder = config['General']['LocalPluginFolder']
# pathToPluginFolder = Path(config['General']['PathToPluginFolder'])
# seperateDownloadPath = config['General']['SeperateDownloadPath']
# pathToSeperateDownloadPath = Path(config['General']['PathToSeperateDownloadPath'])
# sftp_server = config['SFTP - Remote Server']['Server']
# sftp_user = config['SFTP - Remote Server']['Username']
# sftp_password = config['SFTP - Remote Server']['Password']
# sftp_port = config['SFTP - Remote Server']['Port']
# sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer']
# sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath']
# sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath']
# sftp_port = int(sftp_port)
# if localPluginFolder == 'True':
# localPluginFolder = True
# else:
# localPluginFolder = False
# if seperateDownloadPath == 'True':
# seperateDownloadPath = True
# else:
# seperateDownloadPath = False
# if sftp_seperateDownloadPath == 'True':
# sftp_seperateDownloadPath = True
# else:
# sftp_seperateDownloadPath = False
os.chdir(currentFolder)
#return configValues
def createConfig(): def createConfig():

View File

@ -2,7 +2,7 @@ import sys
from utils.consoleoutput import oColors from utils.consoleoutput import oColors
from utils.utilities import getHelp, getCommandHelp from utils.utilities import getHelp, getCommandHelp
from handlers.handle_config import checkConfig from handlers.handle_config import configurationValues
from plugin.plugin_downloader import searchPackage, getSpecificPackage from plugin.plugin_downloader import searchPackage, getSpecificPackage
from plugin.plugin_updatechecker import updateInstalledPackage, checkInstalledPackage from plugin.plugin_updatechecker import updateInstalledPackage, checkInstalledPackage
from plugin.plugin_remover import removePlugin from plugin.plugin_remover import removePlugin
@ -30,21 +30,22 @@ def createInputLists():
def handleInput(inputCommand, inputSelectedObject, inputParams): def handleInput(inputCommand, inputSelectedObject, inputParams):
configValues = configurationValues()
while True: while True:
if inputCommand == 'get': if inputCommand == 'get':
if inputSelectedObject.isdigit(): if inputSelectedObject.isdigit():
if not checkConfig().localPluginFolder: if not configValues.localPluginFolder:
if checkConfig().sftp_seperateDownloadPath is True: if configValues.sftp_seperateDownloadPath is True:
pluginPath = checkConfig().sftp_pathToSeperateDownloadPath pluginPath = configValues.sftp_pathToSeperateDownloadPath
else: else:
pluginPath = checkConfig().sftp_folderPath pluginPath = configValues.sftp_folderPath
getSpecificPackage(inputSelectedObject, pluginPath, inputParams) getSpecificPackage(inputSelectedObject, pluginPath, inputParams)
break break
else: else:
if checkConfig().seperateDownloadPath is True: if configValues.seperateDownloadPath is True:
pluginPath = checkConfig().pathToSeperateDownloadPath pluginPath = configValues.pathToSeperateDownloadPath
else: else:
pluginPath = checkConfig().pathToPluginFolder pluginPath = configValues.pathToPluginFolder
getSpecificPackage(inputSelectedObject, pluginPath, inputParams) getSpecificPackage(inputSelectedObject, pluginPath, inputParams)
break break
else: else:

View File

@ -6,7 +6,7 @@ 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 utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calculateFileSizeKb, calculateFileSizeMb from utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calculateFileSizeKb, calculateFileSizeMb
from handlers.handle_config import checkConfig, configurationValues from handlers.handle_config import configurationValues
from handlers.handle_sftp import sftp_upload_file, sftp_cdPluginDir, createSFTPConnection from handlers.handle_sftp import sftp_upload_file, sftp_cdPluginDir, createSFTPConnection
@ -51,6 +51,7 @@ def getVersionName(packageId, versionId):
def searchPackage(ressourceName): def searchPackage(ressourceName):
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/{ressourceName}?field=name&sort=-downloads"
packageName = doAPIRequest(url) packageName = doAPIRequest(url)
i = 1 i = 1
@ -71,14 +72,14 @@ def searchPackage(ressourceName):
if ressourceSelected != 0: if ressourceSelected != 0:
ressourceSelected = ressourceSelected - 1 ressourceSelected = ressourceSelected - 1
ressourceId = packageName[ressourceSelected]["id"] ressourceId = packageName[ressourceSelected]["id"]
if not checkConfig().localPluginFolder: if not configValues.localPluginFolder:
try: try:
getSpecificPackage(ressourceId, checkConfig().sftp_folderPath) getSpecificPackage(ressourceId, configValues.sftp_folderPath)
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)
else: else:
try: try:
getSpecificPackage(ressourceId, checkConfig().pathToPluginFolder) getSpecificPackage(ressourceId, configValues.pathToPluginFolder)
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)
@ -109,7 +110,8 @@ def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'):
def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'): def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
if checkConfig().localPluginFolder == False: configValues = configurationValues()
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/{ressourceId}"
packageDetails = doAPIRequest(url) packageDetails = doAPIRequest(url)
@ -119,13 +121,13 @@ def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
packageVersion = getVersionName(ressourceId, versionId) packageVersion = getVersionName(ressourceId, versionId)
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar" packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
downloadPackagePath = Path(f"{downloadPath}/{packageDownloadName}") downloadPackagePath = Path(f"{downloadPath}/{packageDownloadName}")
if checkConfig().localPluginFolder: if configValues.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)
else: else:
downloadSpecificVersion(ressourceId, downloadPackagePath, versionId) downloadSpecificVersion(ressourceId, downloadPackagePath, versionId)
if not checkConfig().localPluginFolder: if not configValues.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)
deleteTempPluginFolder(downloadPath) deleteTempPluginFolder(downloadPath)

View File

@ -3,18 +3,19 @@ import re
from pathlib import Path 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 configurationValues
from handlers.handle_sftp import createSFTPConnection, sftp_listAll from handlers.handle_sftp import createSFTPConnection, sftp_listAll
from plugin.plugin_updatechecker import getFileName, getFileVersion, getInstalledPlugin, createPluginList from plugin.plugin_updatechecker import getFileName, getFileVersion, getInstalledPlugin, createPluginList
def removePlugin(pluginToRemove): def removePlugin(pluginToRemove):
configValues = configurationValues()
createPluginList() createPluginList()
if not checkConfig().localPluginFolder: if not configValues.localPluginFolder:
sftp = createSFTPConnection() sftp = createSFTPConnection()
pluginList = sftp_listAll(sftp) pluginList = sftp_listAll(sftp)
else: else:
pluginList = os.listdir(checkConfig().pathToPluginFolder) pluginList = os.listdir(configValues.pathToPluginFolder)
i = 0 i = 0
try: try:
for plugin in pluginList: for plugin in pluginList:
@ -28,8 +29,8 @@ def removePlugin(pluginToRemove):
if pluginToRemove == pluginIdStr or re.search(pluginToRemove, fileName, re.IGNORECASE): if pluginToRemove == pluginIdStr or re.search(pluginToRemove, fileName, re.IGNORECASE):
print(f"Removing: {fileName}") print(f"Removing: {fileName}")
if not checkConfig().localPluginFolder: if not configValues.localPluginFolder:
pluginPath = checkConfig().sftp_folderPath pluginPath = configValues.sftp_folderPath
pluginPath = f"{pluginPath}/{plugin}" pluginPath = f"{pluginPath}/{plugin}"
sftp = createSFTPConnection() sftp = createSFTPConnection()
sftp.remove(pluginPath) sftp.remove(pluginPath)
@ -37,7 +38,7 @@ def removePlugin(pluginToRemove):
i += 1 i += 1
break break
else: else:
pluginPath = checkConfig().pathToPluginFolder pluginPath = configValues.pathToPluginFolder
pluginPath = Path(f"{pluginPath}/{plugin}") pluginPath = Path(f"{pluginPath}/{plugin}")
os.remove(pluginPath) os.remove(pluginPath)
print(f"Removed: {fileName}") print(f"Removed: {fileName}")

View File

@ -8,7 +8,7 @@ from rich.progress import track
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_config import checkConfig, configurationValues from handlers.handle_config import configurationValues
from handlers.handle_sftp import createSFTPConnection, sftp_listAll from handlers.handle_sftp import createSFTPConnection, sftp_listAll
from plugin.plugin_downloader import getSpecificPackage from plugin.plugin_downloader import getSpecificPackage
@ -64,10 +64,11 @@ def compareVersions(plugin_latest_version, pluginVersion):
def eggCrackingJar(localJarFileName): def eggCrackingJar(localJarFileName):
if not checkConfig().localPluginFolder: configValues = configurationValues()
pluginPath = checkConfig().sftp_folderPath if not configValues.localPluginFolder:
pluginPath = configValues.sftp_folderPath
else: else:
pluginPath = checkConfig().pathToPluginFolder pluginPath = configValues.pathToPluginFolder
pathToPluginJar = Path(f"{pluginPath}/{localJarFileName}") pathToPluginJar = Path(f"{pluginPath}/{localJarFileName}")
pluginVersion = '' pluginVersion = ''
with ZipFile(pathToPluginJar, 'r') as pluginJar: with ZipFile(pathToPluginJar, 'r') as pluginJar:
@ -139,8 +140,8 @@ def checkInstalledPackage(inputSelectedObject="all"):
print(" ", end='') print(" ", end='')
print(f"{fileName}".ljust(33), end='') print(f"{fileName}".ljust(33), end='')
print(f"{fileVersion}".ljust(15), end='') print(f"{fileVersion}".ljust(15), end='')
print(f"{pluginLatestVersion}".ljust(14), end='') print(f"{pluginLatestVersion}".ljust(15), end='')
print(f" {pluginIsOutdated}".ljust(5) + oColors.standardWhite) print(f"{pluginIsOutdated}".ljust(5) + oColors.standardWhite)
break break
else: else:
if pluginLatestVersion == 'N/A': if pluginLatestVersion == 'N/A':
@ -150,8 +151,8 @@ def checkInstalledPackage(inputSelectedObject="all"):
print(" ", end='') print(" ", end='')
print(f"{fileName}".ljust(33), end='') print(f"{fileName}".ljust(33), end='')
print(f"{fileVersion}".ljust(15), end='') print(f"{fileVersion}".ljust(15), end='')
print(f"{pluginLatestVersion}".ljust(14), end='') print(f"{pluginLatestVersion}".ljust(15), end='')
print(f" {pluginIsOutdated}".ljust(5) + oColors.standardWhite) print(f"{pluginIsOutdated}".ljust(5) + oColors.standardWhite)
i += 1 i += 1
except TypeError: except TypeError:
@ -290,7 +291,7 @@ def updateInstalledPackage(inputSelectedObject='all'):
i = i + 1 i = i + 1
except TypeError: except TypeError:
print(oColors.brightRed + "Error occured: Aborted updating for plugins." + oColors.standardWhite) print(oColors.brightRed + "Error occured: Aborted updating for plugins." + oColors.standardWhite)
print(oColors.brightYellow + f"[{pluginsUpdated}/{i}] Plugins updated" + oColors.standardWhite) print(oColors.brightYellow + f"Plugins updated: [{pluginsUpdated}/{i}]" + oColors.standardWhite)
if inputSelectedObject =='all' and pluginsUpdated == 0: if inputSelectedObject =='all' and pluginsUpdated == 0:
print(oColors.brightGreen + "All found plugins are on the latest version!" + oColors.standardWhite) print(oColors.brightGreen + "All found plugins are on the latest version!" + oColors.standardWhite)

View File

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

View File

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

View File

@ -6,7 +6,7 @@ import requests
from pathlib import Path from pathlib import Path
from utils.consoleoutput import oColors from utils.consoleoutput import oColors
from handlers.handle_config import checkConfig, configurationValues from handlers.handle_config import configurationValues
from handlers.handle_sftp import createSFTPConnection from handlers.handle_sftp import createSFTPConnection
@ -95,11 +95,12 @@ def getCommandHelp(optionalParams):
def check_local_plugin_folder(): def check_local_plugin_folder():
if checkConfig().localPluginFolder: configValues = configurationValues()
if checkConfig().seperateDownloadPath: if configValues.localPluginFolder:
pluginFolderPath = checkConfig().pathToSeperateDownloadPath if configValues.seperateDownloadPath:
pluginFolderPath = configValues.pathToSeperateDownloadPath
else: else:
pluginFolderPath = checkConfig().pathToPluginFolder pluginFolderPath = configValues.pathToPluginFolder
if not os.path.isdir(pluginFolderPath): if not os.path.isdir(pluginFolderPath):
print(oColors.brightRed + "Plugin folder coulnd*t be found. Creating one..." + oColors.standardWhite) print(oColors.brightRed + "Plugin folder coulnd*t be found. Creating one..." + oColors.standardWhite)
@ -129,9 +130,10 @@ def apiTest():
def check_requirements(): def check_requirements():
configValues = configurationValues()
apiTest() apiTest()
check_local_plugin_folder() check_local_plugin_folder()
if not checkConfig().localPluginFolder: if not configValues.localPluginFolder:
createSFTPConnection() createSFTPConnection()