Added first serverjar handling

This commit is contained in:
Jan-Luca Bogdan | BEL NET GmbH 2022-06-30 16:45:28 +02:00
parent 0b10a76a3b
commit 9e74d480dd
7 changed files with 88 additions and 7 deletions

View File

@ -31,7 +31,6 @@ if __name__ == "__main__":
validate_config() validate_config()
api_test_spiget() api_test_spiget()
check_requirements() check_requirements()
print(args)
if args["mode"] is not None and args["object"] is not None: if args["mode"] is not None and args["object"] is not None:
# arguments were used so call the handle_input function to get the right function call # arguments were used so call the handle_input function to get the right function call

View File

@ -5,6 +5,7 @@ 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.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 check_update_available_installed_server_jar
# check # check
@ -27,6 +28,14 @@ def handle_input(
) -> None: ) -> None:
""" """
Manages the correct function calling from the given input Manages the correct function calling from the given input
:param input_command: Command of main function
:param input_selected_object: Name of plugin/serverjar
:param: input_parameter: Optional parameters
:param no_confirmation: If plugins should be updated without no confirmation message
:param arguments_from_console: If arguments were given on script call
:returns None:
""" """
while True: while True:
# when arguemnts were not passed from console ask for input # when arguemnts were not passed from console ask for input
@ -56,8 +65,7 @@ def handle_input(
case "check": case "check":
match input_selected_object: match input_selected_object:
case "serverjar": case "serverjar":
print("check serverjar") check_update_available_installed_server_jar()
#checkInstalledServerjar()
case _: case _:
check_installed_plugins(input_selected_object, input_parameter) check_installed_plugins(input_selected_object, input_parameter)
@ -81,9 +89,13 @@ def handle_input(
return None return None
def get_input() -> None: def get_input() -> str:
""" """
Gets command line input and calls the handle input function Gets command line input and calls the handle input function
:returns: Main command to execute
:returns: Selected Object to work with
:returns: Optional parameter
""" """
input_command = None input_command = None
print("\n'STRG + C' to exit") print("\n'STRG + C' to exit")

View File

@ -139,7 +139,7 @@ def download_specific_plugin_version_spiget(plugin_id, download_path, version_id
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))
console.print(" [not bold][bright_green]Downloaded[bright_magenta] " + (str(file_size_data)).rjust(9) + \ console.print(" [not bold][bright_green]Downloaded[bright_magenta] " + (str(file_size_data)).rjust(9) + \
f" MB [cyan]→ [white]{download_path}") f" MB [cyan]→ [white]{download_path}")
elif file_size < 1000000: else:
file_size_data = convert_file_size_down(file_size) file_size_data = convert_file_size_down(file_size)
console.print(" [not bold][bright_green]Downloaded[bright_magenta] " + (str(file_size_data)).rjust(9) + \ console.print(" [not bold][bright_green]Downloaded[bright_magenta] " + (str(file_size_data)).rjust(9) + \
f" KB [cyan]→ [white]{download_path}") f" KB [cyan]→ [white]{download_path}")

View File

View File

@ -0,0 +1,70 @@
"""
Checks the installed serverjar for updates
"""
import os
from rich.console import Console
from src.utils.console_output import rich_print_error
from src.handlers.handle_config import config_value
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
def get_installed_server_jar_file(config_values) -> str:
"""
Gets the file name of the installed server jar
:param config_values: Configuration values from pluGET config
:returns: Full file name of installed server jar
"""
match config_values.connection:
case "sftp":
connection = sftp_create_connection()
file_list_server_root = sftp_list_files_in_server_root(connection)
case "ftp":
connection = ftp_create_connection()
file_list_server_root = ftp_list_files_in_server_root(connection)
case _:
file_list_server_root = os.path.dirname(config_values.path_to_plugin_folder)
file_list_server_root = os.listdir(file_list_server_root)
file_server_jar_full_name = None
try:
for file in file_list_server_root:
try:
if ".jar" in file:
file_server_jar_full_name = file
break
except TypeError:
continue
except TypeError:
rich_print_error("Error: Serverjar couldn't be found")
return None
return file_server_jar_full_name
def check_update_available_installed_server_jar() -> None:
"""
Handles the checking of available updates of the installed server jar
:params: None
"""
config_values = config_value()
rich_console = Console()
file_server_jar_full_name = get_installed_server_jar_file(config_values)
if file_server_jar_full_name == None:
# print error and exit function
rich_print_error("Error: Serverjar couldn't be found")
return None
rich_console.print(f"[not bold][cyan]Checking: [bright_magenta]{file_server_jar_full_name}")
# TODO: Add other serverjars here
if "paper" in file_server_jar_full_name:
print("paper check update")
print(file_server_jar_full_name)
else:
rich_print_error(f"{file_server_jar_full_name} isn't supported")

View File

@ -5,4 +5,4 @@ PLUGETVERSION = current version of pluGET
""" """
# constant values # constant values
PLUGETVERSION = "1.6.8" PLUGETVERSION = "1.7.0"