From c8c5e2ba41c50b4d10a32b363e10014a678bc064 Mon Sep 17 00:00:00 2001 From: WallK Date: Tue, 15 Oct 2024 16:35:11 +0300 Subject: [PATCH 1/2] GDScript Logger POC (#956) * GDScript Logger POC * Try to create log folder --- tools/configurator/scripts/class_functions.gd | 63 +++++++++++++++---- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/tools/configurator/scripts/class_functions.gd b/tools/configurator/scripts/class_functions.gd index a61ee1f4..72b4eea0 100644 --- a/tools/configurator/scripts/class_functions.gd +++ b/tools/configurator/scripts/class_functions.gd @@ -98,19 +98,58 @@ func multi_state(section: String, state: String) -> String: state = "mixed" return state +# func logger_bash(log_type: String, log_text: String) -> void: +# # Type of log messages: +# # log d - debug message: maybe in the future we can decide to hide them in main builds or if an option is toggled +# # log i - normal informational message +# # log w - waring: something is not expected but it's not a big deal +# # log e - error: something broke +# var log_header_text = "gdc_" +# log_header_text+=log_text +# log_parameters = ["log", log_type, log_header_text] +# log_result = await run_thread_command(wrapper_command,log_parameters, false) +# #log_result = await run_thread_command("find",["$HOME", "-name", "*.xml","-print"], false) +# #print (log_result["exit_code"]) +# #print (log_result["output"]) + func logger(log_type: String, log_text: String) -> void: - # Type of log messages: - # log d - debug message: maybe in the future we can decide to hide them in main builds or if an option is toggled - # log i - normal informational message - # log w - waring: something is not expected but it's not a big deal - # log e - error: something broke - var log_header_text = "gdc_" - log_header_text+=log_text - log_parameters = ["log", log_type, log_header_text] - log_result = await run_thread_command(wrapper_command,log_parameters, false) - #log_result = await run_thread_command("find",["$HOME", "-name", "*.xml","-print"], false) - #print (log_result["exit_code"]) - #print (log_result["output"]) + var log_dir_path: String = "/var/config/retrodeck/logs/" + var log_path: String = '/var/config/retrodeck/logs/gd_logs.log' + + var log_dir: DirAccess = DirAccess.open(log_dir_path) + var log_file: FileAccess = FileAccess.open(log_path, FileAccess.WRITE) + + var log_line: String = "GD " + match log_type: + 'w': + log_line += "Warning " + print("Warning, mate") + 'e': + log_line += "Error " + print("Error, mate") + 'i': + log_line += "Info " + print("Info, mate") + 'd': + log_line += "Debug " + print("Debug, mate") + _: + print("No idea, mate") + log_line += log_text + print(log_line) + + if not log_dir: + log_dir = DirAccess.open("res://") #open something valid to create an instance + if log_dir.make_dir_recursive(log_dir_path) != OK: + print("Something wrong with log directory") + return + + if log_file: + log_file.seek_end() + log_file.store_line(log_line) + log_file.close() + else: + print("Something wrong with log file") func array_to_string(arr: Array) -> String: var text: String From 880c4b821302b138741a18d754eefb721b1fcbeb Mon Sep 17 00:00:00 2001 From: icenine451 Date: Tue, 15 Oct 2024 12:03:58 -0400 Subject: [PATCH 2/2] Ensure all_systems array is empty every time build_preset_list_options() is run - This prevents all_systems array from having multiple copies of all systems when run multiple times in the same session, which would cause make_preset_changes() to run build_preset_config() multiple times. --- functions/presets.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/functions/presets.sh b/functions/presets.sh index 6b75ed3f..af077ac6 100644 --- a/functions/presets.sh +++ b/functions/presets.sh @@ -49,6 +49,7 @@ build_preset_list_options() { current_disabled_systems=() changed_systems=() changed_presets=() + all_systems=() local section_results=$(sed -n '/\['"$preset"'\]/, /\[/{ /\['"$preset"'\]/! { /\[/! p } }' $rd_conf | sed '/^$/d') while IFS= read -r config_line