From fb52973cf644834c2aeb4db7696bf3f1f1fad19d Mon Sep 17 00:00:00 2001 From: Jan-Luca Bogdan | BEL NET GmbH Date: Wed, 22 Jun 2022 15:26:45 +0200 Subject: [PATCH] Added seperate download function for sftp/ftp --- src/plugin/plugin_downloader.py | 2 +- src/plugin/plugin_updatechecker.py | 55 +++++++++++++++++++----------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/plugin/plugin_downloader.py b/src/plugin/plugin_downloader.py index d381713..f00e578 100644 --- a/src/plugin/plugin_downloader.py +++ b/src/plugin/plugin_downloader.py @@ -241,5 +241,5 @@ def search_specific_plugin(plugin_name) -> None: rich_print_error("Error: Number was out of range! Please try again!") return None selected_plugin_name = handle_regex_plugin_name(plugin_search_results[plugin_selected]["name"]) - rich_console.print(f"\n [bright_white]● [bright_magenta]{selected_plugin_name} [bright_green]latest") + rich_console.print(f"\n [not bold][bright_white]● [bright_magenta]{selected_plugin_name} [bright_green]latest") get_specific_plugin(plugin_selected_id) diff --git a/src/plugin/plugin_updatechecker.py b/src/plugin/plugin_updatechecker.py index 48c5854..2b64805 100644 --- a/src/plugin/plugin_updatechecker.py +++ b/src/plugin/plugin_updatechecker.py @@ -278,6 +278,7 @@ def check_installed_plugins(input_selected_object : str="all", input_parameter : rich_console = Console() rich_console.print(rich_table) + rich_console.print() if plugins_with_udpates != 0: rich_console.print( "[not bold][bright_yellow]Plugins with available updates: [bright_green]" + @@ -325,6 +326,7 @@ def update_installed_plugins(input_selected_object : str="all", no_confirmation :returns: None """ + rich_console = Console() config_values = config_value() match config_values.connection: case "sftp": @@ -348,19 +350,26 @@ def update_installed_plugins(input_selected_object : str="all", no_confirmation return None # used later for output as stats - plugins_updated = 0 + plugins_updated = plugins_skipped = 0 #for plugin in track(INSTALLEDPLUGINLIST, description="[cyan]Updating...", transient=True, style="bright_yellow"): for plugin in INSTALLEDPLUGINLIST: # supports command 'update pluginname' and skip the updating of every other plugin to speed things up a bit if input_selected_object != "all" and input_selected_object != "*": if not re.search(input_selected_object, plugin.plugin_file_name, re.IGNORECASE): + plugins_skipped += 1 continue if plugin.plugin_is_outdated == False: + plugins_skipped += 1 continue - + rich_console.print( + "\n [not bold][bright_white]● [bright_magenta]" + + f"{plugin.plugin_name} [bright_green]{plugin.plugin_latest_version}" + ) + + plugins_updated += 1 plugin_path = get_download_path(config_values) match config_values.connection: # local plugin folder @@ -368,7 +377,6 @@ def update_installed_plugins(input_selected_object : str="all", no_confirmation match (plugin.plugin_repository): case "spigot": try: - plugins_updated += 1 get_specific_plugin(plugin.plugin_repository_data[0]) except HTTPError as err: rich_print_error(f"HTTPError: {err.code} - {err.reason}") @@ -382,11 +390,12 @@ def update_installed_plugins(input_selected_object : str="all", no_confirmation case _: rich_print_error("Error: Plugin repository wasn't found") return None - - try: - os.remove(Path(f"{plugin_path}/{plugin.plugin_file_name}")) - except FileNotFoundError: - rich_print_error("Error: Old plugin file couldn't be deleted") + # don't delete files if they are downloaded to a seperate download path + if config_values.local_seperate_download_path == False: + try: + os.remove(Path(f"{plugin_path}/{plugin.plugin_file_name}")) + except FileNotFoundError: + rich_print_error("Error: Old plugin file couldn't be deleted") @@ -396,7 +405,6 @@ def update_installed_plugins(input_selected_object : str="all", no_confirmation match (plugin.plugin_repository): case "spigot": try: - plugins_updated += 1 get_specific_plugin(plugin.plugin_repository_data[0]) except HTTPError as err: rich_print_error(f"HTTPError: {err.code} - {err.reason}") @@ -410,17 +418,24 @@ def update_installed_plugins(input_selected_object : str="all", no_confirmation case _: rich_print_error("Error: Plugin repository wasn't found") return None - match config_values.connection: - case "sftp": - try: - connection.remove(plugin_path) - except FileNotFoundError: - rich_print_error("Error: Old plugin file couldn't be deleted") - case "ftp": - try: - connection.delete(plugin_path) - except FileNotFoundError: - rich_print_error("Error: Old plugin file couldn't be deleted") + # don't delete old plugin files if they are downloaded to a seperate download path + if config_values.remote_seperate_download_path == False: + match config_values.connection: + case "sftp": + try: + connection.remove(plugin_path) + except FileNotFoundError: + rich_print_error("Error: Old plugin file couldn't be deleted") + case "ftp": + try: + connection.delete(plugin_path) + except FileNotFoundError: + rich_print_error("Error: Old plugin file couldn't be deleted") + + rich_console.print( + f"\n[not bold][bright_green]Plugins updated: {plugins_updated}/{(len(INSTALLEDPLUGINLIST) - plugins_skipped)}" + ) + return None def search_plugin_spigot(plugin_file : str, plugin_file_name : str, plugin_file_version : str) -> int: