Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/1.7.1 #53

Merged
merged 3 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/handlers/handle_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
"""

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_updatechecker import check_installed_plugins, update_installed_plugins
from src.serverjar.serverjar_updatechecker import \
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_purpur import serverjar_purpur_update


# check
Expand All @@ -16,10 +19,11 @@
# get-paper
# get-waterfall
# get-velocity
# get-purpur ???
# get-purpur
# exit
# remove
# search
# help


def handle_input(
Expand Down Expand Up @@ -57,6 +61,15 @@ def handle_input(
case _:
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":
match input_selected_object:
case "serverjar":
Expand All @@ -73,21 +86,15 @@ def handle_input(

case "search":
search_specific_plugin_spiget(input_selected_object)
# TODO add remover
#case "remove":
# print("remove package")
# #removePlugin(inputSelectedObject)
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 "remove":
delete_plugin(input_selected_object)
case "help":
get_command_help(input_selected_object)
case "exit":
return
case _:
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
if arguments_from_console:
Expand All @@ -114,7 +121,7 @@ def get_input() -> str:
continue
else:
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:
return
input_parameter = input_parameter[0] if input_parameter else None
Expand Down
56 changes: 56 additions & 0 deletions src/plugin/plugin_remover.py
Original file line number Diff line number Diff line change
@@ -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
27 changes: 2 additions & 25 deletions src/serverjar/serverjar_paper_velocity_waterfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@
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:
"""
Gets the installed version of the installed serverjar
Expand All @@ -50,6 +34,7 @@ def get_installed_serverjar_version(file_server_jar_full_name) -> str:
except AttributeError:
serverjar_version = serverjar_version_full
serverjar_version = serverjar_version.replace('.jar', '')

return serverjar_version


Expand Down Expand Up @@ -130,14 +115,6 @@ def serverjar_papermc_check_update(file_server_jar_full_name) -> 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)
if serverjar_version == None:
rich_print_error("Error: An error occured while checking the installed serverjar version")
Expand Down Expand Up @@ -224,6 +201,7 @@ def serverjar_papermc_update(
if server_jar_version == "latest" or server_jar_version == None:
server_jar_version = find_latest_available_version(papermc_serverjar, mc_version)

# use rich console for nice colors
rich_console = Console()
rich_console.print(
f"\n [not bold][bright_white]● [bright_magenta]{papermc_serverjar.capitalize()}" + \
Expand Down Expand Up @@ -282,7 +260,6 @@ def serverjar_papermc_update(
progress.update(download_task, advance=len(data))
#f.flush()

# use rich console for nice colors

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) + \
Expand Down
Loading