mirror of
https://github.com/Neocky/pluGET.git
synced 2024-04-29 16:12:30 +00:00
Optimized config handling & beautified output
Changes: - optimized config handling - added spinner to paper download - changed progress bar colors - better output for updating paper version - misc code cleanup
This commit is contained in:
parent
fddc0c252c
commit
205a13ee94
@ -7,49 +7,47 @@ 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'])
|
||||||
|
|
||||||
sftp_server = config['SFTP - Remote Server']['Server']
|
self.sftp_server = config['SFTP - Remote Server']['Server']
|
||||||
sftp_user = config['SFTP - Remote Server']['Username']
|
self.sftp_user = config['SFTP - Remote Server']['Username']
|
||||||
sftp_password = config['SFTP - Remote Server']['Password']
|
self.sftp_password = config['SFTP - Remote Server']['Password']
|
||||||
sftp_port = config['SFTP - Remote Server']['Port']
|
sftp_port = config['SFTP - Remote Server']['Port']
|
||||||
sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer']
|
self.sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer']
|
||||||
sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath']
|
sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath']
|
||||||
sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath']
|
self.sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath']
|
||||||
|
|
||||||
sftp_port = int(sftp_port)
|
self.sftp_port = int(sftp_port)
|
||||||
if localPluginFolder == 'True':
|
if localPluginFolder == 'True':
|
||||||
localPluginFolder = True
|
self.localPluginFolder = True
|
||||||
else:
|
else:
|
||||||
localPluginFolder = False
|
self.localPluginFolder = False
|
||||||
|
|
||||||
if seperateDownloadPath == 'True':
|
if seperateDownloadPath == 'True':
|
||||||
seperateDownloadPath = True
|
self.seperateDownloadPath = True
|
||||||
else:
|
else:
|
||||||
seperateDownloadPath = False
|
self.seperateDownloadPath = False
|
||||||
|
|
||||||
if sftp_seperateDownloadPath == 'True':
|
if sftp_seperateDownloadPath == 'True':
|
||||||
sftp_seperateDownloadPath = True
|
self.sftp_seperateDownloadPath = True
|
||||||
else:
|
else:
|
||||||
sftp_seperateDownloadPath = False
|
self.sftp_seperateDownloadPath = False
|
||||||
|
|
||||||
|
|
||||||
def checkConfig():
|
def checkConfig():
|
||||||
#currentFolder = os.getcwd()
|
|
||||||
configAvailable = os.path.isfile("config.ini")
|
configAvailable = os.path.isfile("config.ini")
|
||||||
|
|
||||||
if not configAvailable:
|
if not configAvailable:
|
||||||
createConfig()
|
createConfig()
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
def createConfig():
|
def createConfig():
|
||||||
|
@ -85,6 +85,7 @@ def searchPackage(ressourceName):
|
|||||||
|
|
||||||
|
|
||||||
def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'):
|
def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'):
|
||||||
|
configValues = configurationValues()
|
||||||
if versionID != 'latest':
|
if versionID != 'latest':
|
||||||
#url = f"https://spigotmc.org/resources/{ressourceId}/download?version={versionID}"
|
#url = f"https://spigotmc.org/resources/{ressourceId}/download?version={versionID}"
|
||||||
print(oColors.brightRed + "Sorry but specific version downloads aren't supported because of cloudflare protection. :(" + oColors.standardWhite)
|
print(oColors.brightRed + "Sorry but specific version downloads aren't supported because of cloudflare protection. :(" + oColors.standardWhite)
|
||||||
@ -104,7 +105,7 @@ def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'):
|
|||||||
else:
|
else:
|
||||||
filesizeData = calculateFileSizeKb(filesize)
|
filesizeData = calculateFileSizeKb(filesize)
|
||||||
print("Downloaded " + (str(filesizeData)).rjust(9) + f" KB here {downloadPath}")
|
print("Downloaded " + (str(filesizeData)).rjust(9) + f" KB here {downloadPath}")
|
||||||
if not configurationValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
sftpSession = createSFTPConnection()
|
sftpSession = createSFTPConnection()
|
||||||
sftp_upload_file(sftpSession, downloadPath)
|
sftp_upload_file(sftpSession, downloadPath)
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ def checkInstalledPackage(inputSelectedObject="all"):
|
|||||||
print("│ No. │ Name │ Installed V. │ Latest V. │ Update available │")
|
print("│ No. │ Name │ Installed V. │ Latest V. │ Update available │")
|
||||||
print("└─────┴────────────────────────────────┴──────────────┴──────────────┴───────────────────┘")
|
print("└─────┴────────────────────────────────┴──────────────┴──────────────┴───────────────────┘")
|
||||||
try:
|
try:
|
||||||
for plugin in track(pluginList, description="Checking for updates" ,transient=True, complete_style="cyan"):
|
for plugin in track(pluginList, description="Checking for updates" ,transient=True, complete_style="bright_yellow"):
|
||||||
try:
|
try:
|
||||||
fileName = getFileName(plugin)
|
fileName = getFileName(plugin)
|
||||||
fileVersion = getFileVersion(plugin)
|
fileVersion = getFileVersion(plugin)
|
||||||
@ -176,7 +176,7 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
print("│ No. │ Name │ Old V. │ New V. │")
|
print("│ No. │ Name │ Old V. │ New V. │")
|
||||||
print("└─────┴────────────────────────────────┴────────────┴──────────┘")
|
print("└─────┴────────────────────────────────┴────────────┴──────────┘")
|
||||||
try:
|
try:
|
||||||
for plugin in track(pluginList, description="Updating" ,transient=True, complete_style="red"):
|
for plugin in track(pluginList, description="Updating" ,transient=True, complete_style="bright_magenta"):
|
||||||
try:
|
try:
|
||||||
fileName = getFileName(plugin)
|
fileName = getFileName(plugin)
|
||||||
fileVersion = getFileVersion(plugin)
|
fileVersion = getFileVersion(plugin)
|
||||||
@ -197,9 +197,9 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
print(f" [{indexNumberUpdated+1}]".rjust(6), end='')
|
print(f" [{indexNumberUpdated+1}]".rjust(6), end='')
|
||||||
print(" ", end='')
|
print(" ", end='')
|
||||||
print(f"{fileName}".ljust(33), end='')
|
print(f"{fileName}".ljust(33), end='')
|
||||||
print(f"{fileVersion}".ljust(8), end='')
|
print(f"{fileVersion}".ljust(13), end='')
|
||||||
print(" ", end='')
|
#print(" ", end='')
|
||||||
print(f"{latestVersion}".ljust(8))
|
print(f"{latestVersion}".ljust(13))
|
||||||
|
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
if configValues.sftp_seperateDownloadPath is True:
|
if configValues.sftp_seperateDownloadPath is True:
|
||||||
@ -247,9 +247,9 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
print(f" [{indexNumberUpdated+1}]".rjust(6), end='')
|
print(f" [{indexNumberUpdated+1}]".rjust(6), end='')
|
||||||
print(" ", end='')
|
print(" ", end='')
|
||||||
print(f"{fileName}".ljust(33), end='')
|
print(f"{fileName}".ljust(33), end='')
|
||||||
print(f"{fileVersion}".ljust(8), end='')
|
print(f"{fileVersion}".ljust(13), end='')
|
||||||
print(" ", end='')
|
#print(" ", end='')
|
||||||
print(f"{latestVersion}".ljust(8))
|
print(f"{latestVersion}".ljust(13))
|
||||||
|
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
if configValues.sftp_seperateDownloadPath is True:
|
if configValues.sftp_seperateDownloadPath is True:
|
||||||
|
@ -92,7 +92,7 @@ def updateServerjar(serverJarBuild='latest'):
|
|||||||
serverJarPath = Path(f"{serverRootPath}/{installedServerjarFullName}")
|
serverJarPath = Path(f"{serverRootPath}/{installedServerjarFullName}")
|
||||||
|
|
||||||
if 'paper' in installedServerjarFullName:
|
if 'paper' in installedServerjarFullName:
|
||||||
print(f"Updating Paper to build: {serverJarBuild}")
|
print(oColors.brightBlack + f"Updating Paper to build: {serverJarBuild}" + oColors.standardWhite)
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
try:
|
try:
|
||||||
papermc_downloader(serverJarBuild, installedServerjarFullName)
|
papermc_downloader(serverJarBuild, installedServerjarFullName)
|
||||||
|
@ -3,6 +3,7 @@ import sys
|
|||||||
import re
|
import re
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from rich.console import Console
|
||||||
|
|
||||||
from utils.consoleoutput import oColors
|
from utils.consoleoutput import oColors
|
||||||
from utils.web_request import doAPIRequest
|
from utils.web_request import doAPIRequest
|
||||||
@ -116,6 +117,7 @@ def paperCheckForUpdate(installedServerjarFullName):
|
|||||||
print(f"{paperInstalledBuild}".ljust(15), end='')
|
print(f"{paperInstalledBuild}".ljust(15), end='')
|
||||||
print(f"{paperLatestBuild}".ljust(15), end='')
|
print(f"{paperLatestBuild}".ljust(15), end='')
|
||||||
print(f"{paperVersionBehind}".ljust(8))
|
print(f"{paperVersionBehind}".ljust(8))
|
||||||
|
print(oColors.brightYellow + f"Versions behind: [{paperVersionBehind}]" + oColors.standardWhite)
|
||||||
|
|
||||||
|
|
||||||
# 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#/
|
||||||
@ -156,16 +158,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"Getting Paper {paperBuild} for {mcVersion}")
|
||||||
|
console = Console()
|
||||||
|
with console.status("Downloading...", spinner='line', spinner_style='bright_magenta') as status:
|
||||||
urllib.request.urlretrieve(url, downloadPackagePath)
|
urllib.request.urlretrieve(url, downloadPackagePath)
|
||||||
filesizeData = calculateFileSizeMb(filesize)
|
filesizeData = calculateFileSizeMb(filesize)
|
||||||
|
print("Downloaded " + (str(filesizeData)).rjust(9) + f" MB here {downloadPackagePath}")
|
||||||
print(f"Downloadsize: {filesizeData} MB")
|
|
||||||
print(f"File downloaded here: {downloadPackagePath}")
|
|
||||||
if not configValues.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)
|
||||||
|
|
||||||
print(oColors.brightGreen + "Downloaded successfully " + oColors.standardWhite + f"Paper-{paperBuild}" + \
|
print(oColors.brightGreen + "Downloaded successfully " + oColors.standardWhite + f"Paper {paperBuild}" + \
|
||||||
oColors.brightGreen + " for " + oColors.standardWhite + f"{mcVersion}" + oColors.standardWhite)
|
oColors.brightGreen + " for " + oColors.standardWhite + f"{mcVersion}" + oColors.standardWhite)
|
||||||
|
Loading…
Reference in New Issue
Block a user