mirror of
				https://github.com/Neocky/pluGET.git
				synced 2024-04-29 16:12:30 +00:00 
			
		
		
		
	Added plugin remover
This commit is contained in:
		| @@ -3,6 +3,7 @@ Handles the input through the pluGET command line | ||||
| """ | ||||
|  | ||||
| from src.utils.console_output import rich_print_error | ||||
| 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 \ | ||||
| @@ -17,7 +18,7 @@ from src.serverjar.serverjar_purpur import serverjar_purpur_update | ||||
| # get-paper | ||||
| # get-waterfall | ||||
| # get-velocity | ||||
| # get-purpur ??? | ||||
| # get-purpur | ||||
| # exit | ||||
| # remove | ||||
| # search | ||||
| @@ -58,6 +59,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": | ||||
| @@ -74,18 +84,8 @@ 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 "get-purpur": | ||||
|                 serverjar_purpur_update(input_selected_object, input_parameter, None) | ||||
|             case "remove": | ||||
|                 delete_plugin(input_selected_object) | ||||
|             case "exit": | ||||
|                 return | ||||
|             case _: | ||||
|   | ||||
							
								
								
									
										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 | ||||
		Reference in New Issue
	
	Block a user
	 Jan-Luca Bogdan | BEL NET GmbH
					Jan-Luca Bogdan | BEL NET GmbH