mirror of
https://github.com/Neocky/pluGET.git
synced 2024-04-29 16:12:30 +00:00
commit
ede3557819
@ -3,11 +3,14 @@ Handles the input through the pluGET command line
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from src.utils.console_output import rich_print_error
|
from src.utils.console_output import rich_print_error
|
||||||
|
from src.utils.utilities import get_command_help
|
||||||
|
from src.plugin.plugin_remover import delete_plugin
|
||||||
from src.plugin.plugin_downloader import get_specific_plugin_spiget, search_specific_plugin_spiget
|
from src.plugin.plugin_downloader import get_specific_plugin_spiget, search_specific_plugin_spiget
|
||||||
from src.plugin.plugin_updatechecker import check_installed_plugins, update_installed_plugins
|
from src.plugin.plugin_updatechecker import check_installed_plugins, update_installed_plugins
|
||||||
from src.serverjar.serverjar_updatechecker import \
|
from src.serverjar.serverjar_updatechecker import \
|
||||||
check_update_available_installed_server_jar, update_installed_server_jar
|
check_update_available_installed_server_jar, update_installed_server_jar
|
||||||
from src.serverjar.serverjar_paper_velocity_waterfall import serverjar_papermc_update
|
from src.serverjar.serverjar_paper_velocity_waterfall import serverjar_papermc_update
|
||||||
|
from src.serverjar.serverjar_purpur import serverjar_purpur_update
|
||||||
|
|
||||||
|
|
||||||
# check
|
# check
|
||||||
@ -16,10 +19,11 @@ from src.serverjar.serverjar_paper_velocity_waterfall import serverjar_papermc_u
|
|||||||
# get-paper
|
# get-paper
|
||||||
# get-waterfall
|
# get-waterfall
|
||||||
# get-velocity
|
# get-velocity
|
||||||
# get-purpur ???
|
# get-purpur
|
||||||
# exit
|
# exit
|
||||||
# remove
|
# remove
|
||||||
# search
|
# search
|
||||||
|
# help
|
||||||
|
|
||||||
|
|
||||||
def handle_input(
|
def handle_input(
|
||||||
@ -57,6 +61,15 @@ def handle_input(
|
|||||||
case _:
|
case _:
|
||||||
search_specific_plugin_spiget(input_selected_object)
|
search_specific_plugin_spiget(input_selected_object)
|
||||||
|
|
||||||
|
case "get-paper":
|
||||||
|
serverjar_papermc_update(input_selected_object, input_parameter, None, "paper")
|
||||||
|
case "get-velocity":
|
||||||
|
serverjar_papermc_update(input_selected_object, input_parameter, None, "velocity")
|
||||||
|
case "get-waterfall":
|
||||||
|
serverjar_papermc_update(input_selected_object, input_parameter, None, "waterfall")
|
||||||
|
case "get-purpur":
|
||||||
|
serverjar_purpur_update(input_selected_object, input_parameter, None)
|
||||||
|
|
||||||
case "update":
|
case "update":
|
||||||
match input_selected_object:
|
match input_selected_object:
|
||||||
case "serverjar":
|
case "serverjar":
|
||||||
@ -73,21 +86,15 @@ def handle_input(
|
|||||||
|
|
||||||
case "search":
|
case "search":
|
||||||
search_specific_plugin_spiget(input_selected_object)
|
search_specific_plugin_spiget(input_selected_object)
|
||||||
# TODO add remover
|
case "remove":
|
||||||
#case "remove":
|
delete_plugin(input_selected_object)
|
||||||
# print("remove package")
|
case "help":
|
||||||
# #removePlugin(inputSelectedObject)
|
get_command_help(input_selected_object)
|
||||||
case "get-paper":
|
|
||||||
serverjar_papermc_update(input_selected_object, input_parameter, None, "paper")
|
|
||||||
case "get-velocity":
|
|
||||||
serverjar_papermc_update(input_selected_object, input_parameter, None, "velocity")
|
|
||||||
case "get-waterfall":
|
|
||||||
serverjar_papermc_update(input_selected_object, input_parameter, None, "waterfall")
|
|
||||||
case "exit":
|
case "exit":
|
||||||
return
|
return
|
||||||
case _:
|
case _:
|
||||||
rich_print_error("Error: Command not found. Please try again. :(")
|
rich_print_error("Error: Command not found. Please try again. :(")
|
||||||
rich_print_error("Use: 'help command' to get all available commands")
|
rich_print_error("Use [bright_blue]'help all' [bright_red]to get a list of all available commands.")
|
||||||
|
|
||||||
# return to break out of while loop if pluGET was started with arguments from console
|
# return to break out of while loop if pluGET was started with arguments from console
|
||||||
if arguments_from_console:
|
if arguments_from_console:
|
||||||
@ -114,7 +121,7 @@ def get_input() -> str:
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
rich_print_error("Wrong input! Use: > 'command' 'selectedObject' [optionalParams]")
|
rich_print_error("Wrong input! Use: > 'command' 'selectedObject' [optionalParams]")
|
||||||
rich_print_error("Use: 'help command' to get all available commands")
|
rich_print_error("Use: [bright_blue]'help all' [bright_red]to get a list of all available commands.")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
return
|
return
|
||||||
input_parameter = input_parameter[0] if input_parameter else None
|
input_parameter = input_parameter[0] if input_parameter else None
|
||||||
|
56
src/plugin/plugin_remover.py
Normal file
56
src/plugin/plugin_remover.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
"""
|
||||||
|
Removes the specified plugin file from the ./plugins folder
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
from rich.console import Console
|
||||||
|
|
||||||
|
from src.handlers.handle_config import config_value
|
||||||
|
from src.utils.console_output import rich_print_error
|
||||||
|
from src.handlers.handle_sftp import sftp_create_connection, sftp_list_all
|
||||||
|
from src.handlers.handle_ftp import ftp_create_connection, ftp_list_all
|
||||||
|
|
||||||
|
|
||||||
|
def delete_plugin(plugin_name: str) -> None:
|
||||||
|
"""
|
||||||
|
Deletes the specific plugin file
|
||||||
|
|
||||||
|
:param plugin_name: Name of plugin file to delete
|
||||||
|
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
config_values = config_value()
|
||||||
|
rich_console = Console()
|
||||||
|
match config_values.connection:
|
||||||
|
case "sftp":
|
||||||
|
connection = sftp_create_connection()
|
||||||
|
plugin_list = sftp_list_all()
|
||||||
|
case "ftp":
|
||||||
|
connection = ftp_create_connection()
|
||||||
|
plugin_list = ftp_list_all()
|
||||||
|
case "local":
|
||||||
|
plugin_list = os.listdir(config_values.path_to_plugin_folder)
|
||||||
|
for plugin_file in plugin_list:
|
||||||
|
# skip all other plugins
|
||||||
|
if not re.search(plugin_name, plugin_file, re.IGNORECASE):
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
match config_values.connection:
|
||||||
|
case "sftp":
|
||||||
|
plugin_path = f"{config_values.remote_plugin_folder_on_server}/{plugin_file}"
|
||||||
|
connection = sftp_create_connection()
|
||||||
|
connection.remove(plugin_path)
|
||||||
|
case "ftp":
|
||||||
|
plugin_path = f"{config_values.remote_plugin_folder_on_server}/{plugin_file}"
|
||||||
|
connection = ftp_create_connection()
|
||||||
|
connection.delete(plugin_path)
|
||||||
|
case "local":
|
||||||
|
pluginPath = Path(f"{config_values.path_to_plugin_folder}/{plugin_file}")
|
||||||
|
os.remove(pluginPath)
|
||||||
|
rich_console.print(f"[not bold][bright_green]Successfully removed: [bright_magenta]{plugin_file}")
|
||||||
|
except:
|
||||||
|
rich_print_error(f"[not bold]Error: Couldn't remove [bright_magenta]{plugin_file}")
|
||||||
|
return None
|
@ -20,22 +20,6 @@ from src.utils.utilities import \
|
|||||||
api_do_request, create_temp_plugin_folder, remove_temp_plugin_folder, convert_file_size_down
|
api_do_request, create_temp_plugin_folder, remove_temp_plugin_folder, convert_file_size_down
|
||||||
|
|
||||||
|
|
||||||
def get_installed_mc_version(file_server_jar_full_name) -> str:
|
|
||||||
"""
|
|
||||||
Gets the used minecraft version from the file name
|
|
||||||
|
|
||||||
:param file_server_jar_full_name: Full file name of the installed serverjar
|
|
||||||
|
|
||||||
:returns: Used minecraft version
|
|
||||||
"""
|
|
||||||
mc_version_full = re.search(r"(\d*\.*\d)+", file_server_jar_full_name)
|
|
||||||
try:
|
|
||||||
mc_version = mc_version_full.group()
|
|
||||||
except AttributeError:
|
|
||||||
mc_version = mc_version_full
|
|
||||||
return mc_version
|
|
||||||
|
|
||||||
|
|
||||||
def get_installed_serverjar_version(file_server_jar_full_name) -> str:
|
def get_installed_serverjar_version(file_server_jar_full_name) -> str:
|
||||||
"""
|
"""
|
||||||
Gets the installed version of the installed serverjar
|
Gets the installed version of the installed serverjar
|
||||||
@ -50,6 +34,7 @@ def get_installed_serverjar_version(file_server_jar_full_name) -> str:
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
serverjar_version = serverjar_version_full
|
serverjar_version = serverjar_version_full
|
||||||
serverjar_version = serverjar_version.replace('.jar', '')
|
serverjar_version = serverjar_version.replace('.jar', '')
|
||||||
|
|
||||||
return serverjar_version
|
return serverjar_version
|
||||||
|
|
||||||
|
|
||||||
@ -130,14 +115,6 @@ def serverjar_papermc_check_update(file_server_jar_full_name) -> None:
|
|||||||
|
|
||||||
:returns: None
|
:returns: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""
|
|
||||||
mc_version = get_installed_mc_version(file_server_jar_full_name)
|
|
||||||
if mc_version == None:
|
|
||||||
rich_print_error("Error: An error occured while checking the mc version of the serverjar")
|
|
||||||
return None
|
|
||||||
print(mc_version)
|
|
||||||
"""
|
|
||||||
serverjar_version = get_installed_serverjar_version(file_server_jar_full_name)
|
serverjar_version = get_installed_serverjar_version(file_server_jar_full_name)
|
||||||
if serverjar_version == None:
|
if serverjar_version == None:
|
||||||
rich_print_error("Error: An error occured while checking the installed serverjar version")
|
rich_print_error("Error: An error occured while checking the installed serverjar version")
|
||||||
@ -224,6 +201,7 @@ def serverjar_papermc_update(
|
|||||||
if server_jar_version == "latest" or server_jar_version == None:
|
if server_jar_version == "latest" or server_jar_version == None:
|
||||||
server_jar_version = find_latest_available_version(papermc_serverjar, mc_version)
|
server_jar_version = find_latest_available_version(papermc_serverjar, mc_version)
|
||||||
|
|
||||||
|
# use rich console for nice colors
|
||||||
rich_console = Console()
|
rich_console = Console()
|
||||||
rich_console.print(
|
rich_console.print(
|
||||||
f"\n [not bold][bright_white]● [bright_magenta]{papermc_serverjar.capitalize()}" + \
|
f"\n [not bold][bright_white]● [bright_magenta]{papermc_serverjar.capitalize()}" + \
|
||||||
@ -282,7 +260,6 @@ def serverjar_papermc_update(
|
|||||||
progress.update(download_task, advance=len(data))
|
progress.update(download_task, advance=len(data))
|
||||||
#f.flush()
|
#f.flush()
|
||||||
|
|
||||||
# use rich console for nice colors
|
|
||||||
|
|
||||||
file_size_data = convert_file_size_down(convert_file_size_down(file_size))
|
file_size_data = convert_file_size_down(convert_file_size_down(file_size))
|
||||||
rich_console.print(" [not bold][bright_green]Downloaded[bright_magenta] " + (str(file_size_data)).rjust(9) + \
|
rich_console.print(" [not bold][bright_green]Downloaded[bright_magenta] " + (str(file_size_data)).rjust(9) + \
|
||||||
|
208
src/serverjar/serverjar_purpur.py
Normal file
208
src/serverjar/serverjar_purpur.py
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
"""
|
||||||
|
Handles the update checking and downloading of these serverjars:
|
||||||
|
Purpur
|
||||||
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
|
import requests
|
||||||
|
from pathlib import Path
|
||||||
|
from rich.table import Table
|
||||||
|
from rich.console import Console
|
||||||
|
from rich.progress import Progress
|
||||||
|
|
||||||
|
from src.handlers.handle_config import config_value
|
||||||
|
from src.utils.console_output import rich_print_error
|
||||||
|
from src.handlers.handle_sftp import sftp_create_connection, sftp_upload_server_jar
|
||||||
|
from src.handlers.handle_ftp import ftp_create_connection, ftp_upload_server_jar
|
||||||
|
from src.utils.utilities import \
|
||||||
|
api_do_request, create_temp_plugin_folder, remove_temp_plugin_folder, convert_file_size_down
|
||||||
|
from src.serverjar.serverjar_paper_velocity_waterfall import \
|
||||||
|
get_installed_serverjar_version, get_version_group, get_versions_behind
|
||||||
|
|
||||||
|
|
||||||
|
def find_latest_available_version(version_group) -> int:
|
||||||
|
"""
|
||||||
|
Gets the latest available version of the installed serverjar version
|
||||||
|
|
||||||
|
:param version_group: Minecraft version group of the serverjar
|
||||||
|
|
||||||
|
:returns: Latest available version as int
|
||||||
|
"""
|
||||||
|
url = f"https://api.purpurmc.org/v2/purpur/{version_group}/"
|
||||||
|
versions = api_do_request(url)
|
||||||
|
if "status" in versions: # Checks if the API returns a status. This means that there was an error.
|
||||||
|
return None
|
||||||
|
latest_version = versions["builds"]["all"][-1]
|
||||||
|
return latest_version
|
||||||
|
|
||||||
|
|
||||||
|
def get_purpur_download_file_name(mc_version, serverjar_version) -> str:
|
||||||
|
"""
|
||||||
|
Gets the download name from the purpur api and merge it together in the right format
|
||||||
|
|
||||||
|
:param mc_version: Minecraft version
|
||||||
|
:param serverjar_version: Version of the serverjar
|
||||||
|
:param file_server_jar_full_name: Serverjar name
|
||||||
|
|
||||||
|
:returns: Download name of the file
|
||||||
|
"""
|
||||||
|
url = f"https://api.purpurmc.org/v2/purpur/{mc_version}/{serverjar_version}/"
|
||||||
|
build_details = api_do_request(url)
|
||||||
|
purpur_build_version = build_details["build"]
|
||||||
|
purpur_project_name = build_details["project"]
|
||||||
|
purpur_mc_version = build_details["version"]
|
||||||
|
download_name = f"{purpur_project_name}-{purpur_mc_version}-{purpur_build_version}.jar"
|
||||||
|
return download_name
|
||||||
|
|
||||||
|
|
||||||
|
def serverjar_purpur_check_update(file_server_jar_full_name) -> None:
|
||||||
|
"""
|
||||||
|
Checks the installed purpur serverjar if an update is available
|
||||||
|
|
||||||
|
:param file_server_jar_full_name: Full name of the purpu server jar file name
|
||||||
|
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
serverjar_version = get_installed_serverjar_version(file_server_jar_full_name)
|
||||||
|
if serverjar_version == None:
|
||||||
|
rich_print_error("Error: An error occured while checking the installed serverjar version")
|
||||||
|
return None
|
||||||
|
|
||||||
|
version_group = get_version_group(file_server_jar_full_name)
|
||||||
|
if version_group == None:
|
||||||
|
rich_print_error(
|
||||||
|
"Error: An error occured while checking the installed version group of the installed serverjar"
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
latest_version = find_latest_available_version(version_group)
|
||||||
|
if latest_version == None:
|
||||||
|
rich_print_error("Error: An error occured while checking for the latest available version of the serverjar")
|
||||||
|
return None
|
||||||
|
|
||||||
|
versions_behind = get_versions_behind(serverjar_version, latest_version)
|
||||||
|
|
||||||
|
rich_table = Table(box=None)
|
||||||
|
rich_table.add_column("Name", style="bright_magenta")
|
||||||
|
rich_table.add_column("Installed V.", justify="right", style="green")
|
||||||
|
rich_table.add_column("Latest V.", justify="right", style="bright_green")
|
||||||
|
rich_table.add_column("Versions behind", justify="right", style="cyan")
|
||||||
|
|
||||||
|
rich_table.add_row(
|
||||||
|
file_server_jar_full_name,
|
||||||
|
serverjar_version,
|
||||||
|
str(latest_version),
|
||||||
|
str(versions_behind)
|
||||||
|
)
|
||||||
|
rich_console = Console()
|
||||||
|
rich_console.print(rich_table)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def serverjar_purpur_update(
|
||||||
|
server_jar_version: str="latest",
|
||||||
|
mc_version: str=None,
|
||||||
|
file_server_jar_full_name: str=None
|
||||||
|
) -> bool:
|
||||||
|
"""
|
||||||
|
Handles the downloading of the papermc serverjar
|
||||||
|
|
||||||
|
:param server_jar_version: Version of the serverjar which should get downloaded
|
||||||
|
:param mc_version: Minecraft version
|
||||||
|
:param no_confirmation: If no confirmation message should pop up
|
||||||
|
:param file_server_jar_full_name: The old serverjar file
|
||||||
|
|
||||||
|
:returns: True/False if the serverjar was downloaded successfully
|
||||||
|
"""
|
||||||
|
config_values = config_value()
|
||||||
|
match config_values.connection:
|
||||||
|
case "local":
|
||||||
|
path_server_root = config_values.path_to_plugin_folder
|
||||||
|
# need help_path or else TypeError will be thrown
|
||||||
|
help_path = Path('/plugins')
|
||||||
|
help_path_str = str(help_path)
|
||||||
|
path_server_root = Path(str(path_server_root).replace(help_path_str, ''))
|
||||||
|
case _:
|
||||||
|
path_server_root = create_temp_plugin_folder()
|
||||||
|
|
||||||
|
# exit if the mc version can't be found
|
||||||
|
if file_server_jar_full_name == None and mc_version == None:
|
||||||
|
rich_print_error("Error: Please specifiy the minecraft version as third argument!")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if mc_version == None:
|
||||||
|
mc_version = get_version_group(file_server_jar_full_name)
|
||||||
|
|
||||||
|
if server_jar_version == "latest" or server_jar_version == None:
|
||||||
|
server_jar_version = find_latest_available_version(mc_version)
|
||||||
|
|
||||||
|
if file_server_jar_full_name == None:
|
||||||
|
serverjar_name = "purpur"
|
||||||
|
else:
|
||||||
|
serverjar_name = file_server_jar_full_name
|
||||||
|
|
||||||
|
# use rich console for nice colors
|
||||||
|
rich_console = Console()
|
||||||
|
rich_console.print(
|
||||||
|
f"\n [not bold][bright_white]● [bright_magenta]{serverjar_name.capitalize()}" + \
|
||||||
|
f" [cyan]→ [bright_green]{server_jar_version}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if file_server_jar_full_name != None:
|
||||||
|
serverjar_version = get_installed_serverjar_version(file_server_jar_full_name)
|
||||||
|
if get_versions_behind(serverjar_version, server_jar_version) == 0:
|
||||||
|
rich_console.print(" [not bold][bright_green]No updates currently available!")
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
download_file_name = get_purpur_download_file_name(mc_version, server_jar_version)
|
||||||
|
except KeyError:
|
||||||
|
rich_print_error(f" Error: This version wasn't found for {mc_version}")
|
||||||
|
rich_print_error(f" Reverting to latest version for {mc_version}")
|
||||||
|
try:
|
||||||
|
server_jar_version = find_latest_available_version(mc_version)
|
||||||
|
download_file_name = get_purpur_download_file_name(mc_version, server_jar_version)
|
||||||
|
except KeyError:
|
||||||
|
rich_print_error(
|
||||||
|
f" Error: Version {mc_version} wasn't found for {serverjar_name.capitalize()} in the purpur api"
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
|
url = f"https://api.purpurmc.org/v2/purpur/{mc_version}/{server_jar_version}/download/"
|
||||||
|
download_path = Path(f"{path_server_root}/{download_file_name}")
|
||||||
|
|
||||||
|
with Progress(transient=True) as progress:
|
||||||
|
header = {'user-agent': 'pluGET/1.0'}
|
||||||
|
r = requests.get(url, headers=header, stream=True)
|
||||||
|
try:
|
||||||
|
file_size = int(r.headers.get('Content-Length'))
|
||||||
|
# create progress bar
|
||||||
|
download_task = progress.add_task(" [cyan]Downloading...", total=file_size)
|
||||||
|
except TypeError:
|
||||||
|
# Content-lenght returned nothing
|
||||||
|
file_size = 0
|
||||||
|
with open(download_path, 'wb') as f:
|
||||||
|
# split downloaded data in chunks of 65536
|
||||||
|
for data in r.iter_content(chunk_size=65536):
|
||||||
|
f.write(data)
|
||||||
|
# don't show progress bar if no content-length was returned
|
||||||
|
if file_size == 0:
|
||||||
|
continue
|
||||||
|
progress.update(download_task, advance=len(data))
|
||||||
|
#f.flush()
|
||||||
|
|
||||||
|
|
||||||
|
file_size_data = convert_file_size_down(convert_file_size_down(file_size))
|
||||||
|
rich_console.print(" [not bold][bright_green]Downloaded[bright_magenta] " + (str(file_size_data)).rjust(9) + \
|
||||||
|
f" MB [cyan]→ [white]{download_path}")
|
||||||
|
|
||||||
|
if config_values.connection == "sftp":
|
||||||
|
sftp_session = sftp_create_connection()
|
||||||
|
sftp_upload_server_jar(sftp_session, download_path)
|
||||||
|
remove_temp_plugin_folder()
|
||||||
|
elif config_values.connection == "ftp":
|
||||||
|
ftp_session = ftp_create_connection()
|
||||||
|
ftp_upload_server_jar(ftp_session, download_path)
|
||||||
|
remove_temp_plugin_folder()
|
||||||
|
|
||||||
|
return True
|
@ -11,6 +11,7 @@ from src.utils.console_output import rich_print_error
|
|||||||
from src.handlers.handle_sftp import sftp_create_connection, sftp_list_files_in_server_root
|
from src.handlers.handle_sftp import sftp_create_connection, sftp_list_files_in_server_root
|
||||||
from src.handlers.handle_ftp import ftp_create_connection, ftp_list_files_in_server_root
|
from src.handlers.handle_ftp import ftp_create_connection, ftp_list_files_in_server_root
|
||||||
from src.serverjar.serverjar_paper_velocity_waterfall import serverjar_papermc_check_update, serverjar_papermc_update
|
from src.serverjar.serverjar_paper_velocity_waterfall import serverjar_papermc_check_update, serverjar_papermc_update
|
||||||
|
from src.serverjar.serverjar_purpur import serverjar_purpur_check_update, serverjar_purpur_update
|
||||||
|
|
||||||
|
|
||||||
def get_installed_server_jar_file(config_values) -> str:
|
def get_installed_server_jar_file(config_values) -> str:
|
||||||
@ -61,14 +62,19 @@ def check_update_available_installed_server_jar() -> None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# TODO: Add other serverjars here
|
# TODO: Add other serverjars here
|
||||||
|
# Paper / Velocity / Waterfall
|
||||||
if "paper" in file_server_jar_full_name or \
|
if "paper" in file_server_jar_full_name or \
|
||||||
"waterfall" in file_server_jar_full_name or \
|
"waterfall" in file_server_jar_full_name or \
|
||||||
"velocity" in file_server_jar_full_name:
|
"velocity" in file_server_jar_full_name:
|
||||||
serverjar_papermc_check_update(file_server_jar_full_name)
|
serverjar_papermc_check_update(file_server_jar_full_name)
|
||||||
|
|
||||||
|
# Purpur
|
||||||
|
elif "purpur" in file_server_jar_full_name:
|
||||||
|
serverjar_purpur_check_update(file_server_jar_full_name)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
rich_print_error(f"{file_server_jar_full_name} isn't supported")
|
rich_print_error(f"[not bold]Error: [bright_magenta]{file_server_jar_full_name} [bright_red]isn't supported")
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@ -99,27 +105,35 @@ def update_installed_server_jar(server_jar_version: str="latest") -> None:
|
|||||||
|
|
||||||
server_jar_path = f"{path_server_root}/{file_server_jar_full_name}"
|
server_jar_path = f"{path_server_root}/{file_server_jar_full_name}"
|
||||||
rich_console = Console()
|
rich_console = Console()
|
||||||
|
download_successfull = False
|
||||||
# TODO: Add other serverjars here
|
# TODO: Add other serverjars here
|
||||||
|
# Paper / Velocity / Waterfall
|
||||||
if "paper" in file_server_jar_full_name or \
|
if "paper" in file_server_jar_full_name or \
|
||||||
"waterfall" in file_server_jar_full_name or \
|
"waterfall" in file_server_jar_full_name or \
|
||||||
"velocity" in file_server_jar_full_name:
|
"velocity" in file_server_jar_full_name:
|
||||||
download_successfull = serverjar_papermc_update(server_jar_version, None, file_server_jar_full_name, None)
|
download_successfull = serverjar_papermc_update(server_jar_version, None, file_server_jar_full_name, None)
|
||||||
if download_successfull is True:
|
|
||||||
match config_values.connection:
|
# Purpur
|
||||||
case "local":
|
elif "purpur" in file_server_jar_full_name:
|
||||||
os.remove(Path(server_jar_path))
|
download_successfull = serverjar_purpur_update(server_jar_version, None, file_server_jar_full_name)
|
||||||
case "sftp":
|
|
||||||
connection = sftp_create_connection()
|
|
||||||
connection.remove(server_jar_path)
|
|
||||||
case "ftp":
|
|
||||||
connection = ftp_create_connection()
|
|
||||||
connection.delete(server_jar_path)
|
|
||||||
rich_console.print(
|
|
||||||
" [not bold][bright_green]Deleted old server file [cyan]→ [white]" +
|
|
||||||
f"{file_server_jar_full_name}"
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
rich_print_error(f"{file_server_jar_full_name} isn't supported")
|
rich_print_error(f"[not bold]Error: [bright_magenta]{file_server_jar_full_name} [bright_red]isn't supported")
|
||||||
|
|
||||||
|
# remove old serverjar when the serverjar was sucessfully updated
|
||||||
|
if download_successfull is True:
|
||||||
|
match config_values.connection:
|
||||||
|
case "local":
|
||||||
|
os.remove(Path(server_jar_path))
|
||||||
|
case "sftp":
|
||||||
|
connection = sftp_create_connection()
|
||||||
|
connection.remove(server_jar_path)
|
||||||
|
case "ftp":
|
||||||
|
connection = ftp_create_connection()
|
||||||
|
connection.delete(server_jar_path)
|
||||||
|
rich_console.print(
|
||||||
|
" [not bold][bright_green]Deleted old server file [cyan]→ [white]" +
|
||||||
|
f"{file_server_jar_full_name}"
|
||||||
|
)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
@ -5,4 +5,4 @@ PLUGETVERSION = current version of pluGET
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# constant values
|
# constant values
|
||||||
PLUGETVERSION = "1.7.0"
|
PLUGETVERSION = "1.7.1"
|
||||||
|
@ -3,14 +3,6 @@ import unittest
|
|||||||
from src.serverjar import serverjar_paper_velocity_waterfall
|
from src.serverjar import serverjar_paper_velocity_waterfall
|
||||||
|
|
||||||
class TestCases(unittest.TestCase):
|
class TestCases(unittest.TestCase):
|
||||||
def test_get_installed_mc_version(self):
|
|
||||||
# paper-1.19-40.jar -> 1.19
|
|
||||||
serverjar_file_name = "paper-1.19-40.jar"
|
|
||||||
mc_version = "1.19"
|
|
||||||
result = serverjar_paper_velocity_waterfall.get_installed_mc_version(serverjar_file_name)
|
|
||||||
self.assertEqual(result, mc_version)
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_installed_serverjar_version(self):
|
def test_get_installed_serverjar_version(self):
|
||||||
# paper-1.19-40.jar -> 40
|
# paper-1.19-40.jar -> 40
|
||||||
serverjar_file_name = "paper-1.19-40.jar"
|
serverjar_file_name = "paper-1.19-40.jar"
|
||||||
|
40
src/tests/test_serverjar_purpur.py
Normal file
40
src/tests/test_serverjar_purpur.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
from src.serverjar import serverjar_purpur
|
||||||
|
from src.serverjar import serverjar_paper_velocity_waterfall
|
||||||
|
|
||||||
|
class TestCases(unittest.TestCase):
|
||||||
|
def test_get_installed_serverjar_version(self):
|
||||||
|
# purpur-1.19-40.jar -> 40
|
||||||
|
serverjar_file_name = "purpur-1.19-40.jar"
|
||||||
|
serverjar_version = "40"
|
||||||
|
result = serverjar_paper_velocity_waterfall.get_installed_serverjar_version(serverjar_file_name)
|
||||||
|
self.assertEqual(result, serverjar_version)
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_version_group(self):
|
||||||
|
# 1.18.2 -> 1.18
|
||||||
|
mc_version = "1.18.2"
|
||||||
|
mc_version_group = "1.18.2"
|
||||||
|
result = serverjar_paper_velocity_waterfall.get_version_group(mc_version)
|
||||||
|
self.assertEqual(result, mc_version_group)
|
||||||
|
|
||||||
|
|
||||||
|
def test_find_latest_available_version(self):
|
||||||
|
# Get latest available purpur version for 1.15.2 which should be '606'
|
||||||
|
file_server_jar_full_name = "purpur-1.15.2-40.jar"
|
||||||
|
version_group = "1.15.2"
|
||||||
|
result = serverjar_purpur.find_latest_available_version(version_group)
|
||||||
|
self.assertEqual(result, str(606))
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_versions_behind(self):
|
||||||
|
# 161 - 157 = 4
|
||||||
|
serverjar_version = 157
|
||||||
|
latest_version = 161
|
||||||
|
result = serverjar_paper_velocity_waterfall.get_versions_behind(serverjar_version, latest_version)
|
||||||
|
self.assertEqual(result, 4)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
@ -9,6 +9,7 @@ import shutil
|
|||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
from rich.table import Table
|
||||||
from src.handlers.handle_sftp import sftp_create_connection
|
from src.handlers.handle_sftp import sftp_create_connection
|
||||||
from src.handlers.handle_ftp import ftp_create_connection
|
from src.handlers.handle_ftp import ftp_create_connection
|
||||||
|
|
||||||
@ -17,6 +18,72 @@ from src.handlers.handle_config import config_value
|
|||||||
from src.settings import PLUGETVERSION
|
from src.settings import PLUGETVERSION
|
||||||
|
|
||||||
|
|
||||||
|
def get_command_help(command: str) -> None:
|
||||||
|
"""
|
||||||
|
Prints the help page for all commands and individual commands
|
||||||
|
|
||||||
|
:param command: Console command which the help page should show
|
||||||
|
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
rich_console = Console()
|
||||||
|
rich_table = Table(box=None)
|
||||||
|
rich_table.add_column("Command", justify="left", style="bright_blue", no_wrap=True)
|
||||||
|
rich_table.add_column("Object", style="bright_magenta")
|
||||||
|
rich_table.add_column("Params", justify="left", style="cyan")
|
||||||
|
rich_table.add_column("Description", justify="left", style="white")
|
||||||
|
match command:
|
||||||
|
case "all":
|
||||||
|
rich_table.add_row("check", "Name/all", None, "Check for an update of an installed plugin")
|
||||||
|
rich_table.add_row("check", "serverjar", None, "Check for an update for the installed serverjar")
|
||||||
|
rich_table.add_row("exit", "./anything", None, "Exit pluGET")
|
||||||
|
rich_table.add_row("get", "Name/ID", None, "Downloads the latest version of a plugin")
|
||||||
|
rich_table.add_row("get-paper", "PaperVersion", "McVersion", "Downloads a specific PaperMc version")
|
||||||
|
rich_table.add_row("get-purpur", "PurpurVersion", "McVersion", "Downloads a specific Purpur version")
|
||||||
|
rich_table.add_row("get-velocity", "VelocityVersion", "McVersion", "Downloads a specific Velocity version")
|
||||||
|
rich_table.add_row(
|
||||||
|
"get-waterfall", "WaterfallVersion", "McVersion", "Downloads a specific waterfall version"
|
||||||
|
)
|
||||||
|
rich_table.add_row("help", "./anything", None, "Get specific help to the commands of pluGET")
|
||||||
|
rich_table.add_row("remove", "Name", None, "Delete an installed plugin from the plugin folder")
|
||||||
|
rich_table.add_row("search", "Name/all", None, "Search for a plugin and download the latest version")
|
||||||
|
rich_table.add_row("update", "Name/all", None, "Update installed plugins to the latest version")
|
||||||
|
rich_table.add_row("update", "serverjar", None, "Update the installed serverjar to the latest version")
|
||||||
|
case "check":
|
||||||
|
rich_table.add_row("check", "Name/all", None, "Check for an update of an installed plugin")
|
||||||
|
rich_table.add_row("check", "serverjar", None, "Check for an update for the installed serverjar")
|
||||||
|
case "exit":
|
||||||
|
rich_table.add_row("exit", "./anything", None, "Exit pluGET")
|
||||||
|
case "get":
|
||||||
|
rich_table.add_row("get", "Name/ID", None, "Downloads the latest version of a plugin")
|
||||||
|
case "get-paper":
|
||||||
|
rich_table.add_row("get-paper", "PaperVersion", "McVersion", "Downloads a specific PaperMc version")
|
||||||
|
case "get-purpur":
|
||||||
|
rich_table.add_row("get-purpur", "PurpurVersion", "McVersion", "Downloads a specific Purpur version")
|
||||||
|
case "get-velocity":
|
||||||
|
rich_table.add_row("get-velocity", "VelocityVersion", "McVersion", "Downloads a specific Velocity version")
|
||||||
|
case "get-waterfall":
|
||||||
|
rich_table.add_row(
|
||||||
|
"get-waterfall", "WaterfallVersion", "McVersion", "Downloads a specific Waterfall version"
|
||||||
|
)
|
||||||
|
case "help" | "all":
|
||||||
|
rich_table.add_row("help", "./anything", None, "Get specific help to the commands of pluGET")
|
||||||
|
case "remove":
|
||||||
|
rich_table.add_row("remove", "Name", None, "Delete an installed plugin from the plugin folder")
|
||||||
|
case "search":
|
||||||
|
rich_table.add_row("search", "Name/all", None, "Search for a plugin and download the latest version")
|
||||||
|
case "update":
|
||||||
|
rich_table.add_row("update", "Name/all", None, "Update installed plugins to the latest version")
|
||||||
|
rich_table.add_row("update", "serverjar", None, "Update the installed serverjar to the latest version")
|
||||||
|
case _:
|
||||||
|
rich_print_error(f"[not bold]Error: Help for command [bright_magenta]'{command}' [bright_red]not found!")
|
||||||
|
rich_print_error("Use [bright_blue]'help all' [bright_red]to get a list of all commands.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
rich_console.print(rich_table)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def check_for_pluGET_update() -> None:
|
def check_for_pluGET_update() -> None:
|
||||||
"""
|
"""
|
||||||
Check with the github api if there is a new version for pluGET available and print download message if this is
|
Check with the github api if there is a new version for pluGET available and print download message if this is
|
||||||
|
Loading…
Reference in New Issue
Block a user