Improved parsing of files for pulling out data

On branch feat/godot-configurator
 Changes to be committed:
	modified:   main.gd
	modified:   res/pixel_ui_theme/RetroDECKTheme.tres
	modified:   scripts/class_functions.gd
	modified:   tk_about.gd
	modified:   tk_about.txt
This commit is contained in:
monkeyx-net 2024-07-31 20:45:58 +01:00
parent d59dad1c19
commit 1dc99e39d3
5 changed files with 95 additions and 73 deletions

View file

@ -22,15 +22,11 @@ func _ready():
_get_nodes() _get_nodes()
_connect_signals() _connect_signals()
_play_main_animations() _play_main_animations()
var file_path = "../../tools/configurator.sh" var emulator_list = class_functions.get_text_file_from_system_path("../../tools/configurator.sh","sed -n '/local emulator_list=(/,/)/{s/.*local emulator_list=\\(.*\\)/\\1/; /)/q; p}' ","emulist")
var command = "sed -n '/local emulator_list=(/,/)/{s/.*local emulator_list=\\(.*\\)/\\1/; /)/q; p}' "
var emulator_list = class_functions.get_text_file_from_system_path(file_path,command)
file_path = "/var/config/retrodeck/retrodeck.cfg"
command = "sed -n '/\\[abxy_button_swap\\]/,/^\\s*$/p' "
var abxy_button_list = class_functions.get_text_file_from_system_path(file_path,command)
print(abxy_button_list)
print (emulator_list) print (emulator_list)
var abxy_button_list = class_functions.get_text_file_from_system_path("/var/config/retrodeck/retrodeck.cfg","sed -n '/\\[abxy_button_swap\\]/,/^$/p' ","normal")
print(abxy_button_list)
# set current startup tab to match IDE # set current startup tab to match IDE
tab_container.current_tab = 3 tab_container.current_tab = 3
add_child(class_functions) # Needed for threaded results add_child(class_functions) # Needed for threaded results

File diff suppressed because one or more lines are too long

View file

@ -3,9 +3,10 @@ class_name ClassFunctions extends Control
# This should be looked at again when GoDot 4.3 ships as has new OS.execute_with_pipe # This should be looked at again when GoDot 4.3 ships as has new OS.execute_with_pipe
func array_to_string(arr: Array) -> String: func array_to_string(arr: Array) -> String:
var text = "" var text: String
for line in arr: for line in arr:
text += line + "\n" #text += line + "\n"
text = line.strip_edges() + "\n"
return text return text
func execute_command(command: String, parameters: Array, console: bool) -> Dictionary: func execute_command(command: String, parameters: Array, console: bool) -> Dictionary:
@ -14,6 +15,8 @@ func execute_command(command: String, parameters: Array, console: bool) -> Dicti
var exit_code = OS.execute(command, parameters, output, console) ## add if exit == 0 etc var exit_code = OS.execute(command, parameters, output, console) ## add if exit == 0 etc
result["output"] = array_to_string(output) result["output"] = array_to_string(output)
result["exit_code"] = exit_code result["exit_code"] = exit_code
#print (array_to_string(output))
#print (result["exit_code"])
return result return result
func run_command_in_thread(command: String, paramaters: Array, _console: bool) -> Dictionary: func run_command_in_thread(command: String, paramaters: Array, _console: bool) -> Dictionary:
@ -30,17 +33,39 @@ func _threaded_command_execution(command: String, parameters: Array, console: bo
return result return result
# Make this generic for command, path and naming # Make this generic for command, path and naming
func get_text_file_from_system_path(file_path: String, command: String) -> Dictionary: func get_text_file_from_system_path(file_path: String, command: String, etype: String) -> Dictionary:
var output = [] var output: Array
var data_dict: Dictionary
command += file_path command += file_path
var exit_code = OS.execute("sh", ["-c", command], output) var exit_code = OS.execute("sh", ["-c", command], output)
if exit_code == 0: if exit_code == 0:
var content = array_to_string(output) var content = array_to_string(output)
return parse_file_list(content) if etype == "emulist":
data_dict = parse_file_list(content)
elif etype == "normal":
data_dict = parse_imported_string(content)
else:
print ("Error in get text function")
return data_dict
else: else:
print("Error reading file: ", exit_code) print("Error reading file: ", exit_code)
return {} return {}
func parse_imported_string(input_string: String) -> Dictionary:
var result: Dictionary
var current_dict_key: String
var lines = input_string.strip_edges().split("\n", false)
if lines.size() > 0:
lines = lines.slice(1, lines.size()) # Skip the first line
for line in lines:
current_dict_key = line
var parts = line.split("=", false)
if parts.size() == 2:
var key = parts[0]
var value_str = parts[1]
result[key] = {"KEY": key, "Value": value_str}
return result
func parse_file_list(content: String) -> Dictionary: func parse_file_list(content: String) -> Dictionary:
var file_dict = {} var file_dict = {}
var regex = RegEx.new() var regex = RegEx.new()
@ -64,14 +89,14 @@ func launch_help(url: String) -> void:
func import_csv_data(file_path: String) -> Dictionary: func import_csv_data(file_path: String) -> Dictionary:
# check if file exists # check if file exists
var data_dict: Dictionary = {} var data_dict: Dictionary
var file = FileAccess.open(file_path,FileAccess.READ) var file = FileAccess.open(file_path,FileAccess.READ)
if file: if file:
var csv_lines: PackedStringArray = file.get_as_text().strip_edges().split("\n") var csv_lines: PackedStringArray = file.get_as_text().strip_edges().split("\n")
for i in range(1, csv_lines.size()): # Start from 1 to skip the header for i in range(1, csv_lines.size()): # Start from 1 to skip the header
var line = csv_lines[i] var line = csv_lines[i]
var columns = line.split(",") var columns = line.split(",")
if columns.size() >= 3: # Ensure there are at least 2 elements (URL and Description) if columns.size() >= 3:
var id = columns[0] var id = columns[0]
var url = columns[1] var url = columns[1]
var description = columns[2] var description = columns[2]

View file

@ -68,27 +68,28 @@ func _connect_signals() -> void:
licenses_button.pressed.connect(_about_button_pressed.bind("rd_licenses")) licenses_button.pressed.connect(_about_button_pressed.bind("rd_licenses"))
func _about_button_pressed(id: String) -> void: func _about_button_pressed(id: String) -> void:
print (id) var entry: Dictionary
match id: match id:
"rd_web": "rd_web":
var entry = tk_about["rd_web"] entry = tk_about[id]
OS.shell_open(%website_button.editor_description) OS.shell_open(%website_button.editor_description)
"rd_changelog": "rd_changelog":
var entry = tk_about["rd_changelog"] entry = tk_about[id]
OS.shell_open(%changelog_button.editor_description) OS.shell_open(%changelog_button.editor_description)
"rd_wiki": "rd_wiki":
var entry = tk_about["rd_wiki"] entry = tk_about[id]
OS.shell_open(%wiki_button.editor_description) OS.shell_open(%wiki_button.editor_description)
"rd_credits": "rd_credits":
var entry = tk_about["rd_credits"] entry = tk_about[id]
OS.shell_open(%credits_button.editor_description) OS.shell_open(%credits_button.editor_description)
"rd_donate": "rd_donate":
var entry = tk_about["rd_donate"] entry = tk_about[id]
OS.shell_open(%donate_button.editor_description) OS.shell_open(%donate_button.editor_description)
"rd_contactus": "rd_contactus":
var entry = tk_about["rd_contactus"] entry = tk_about[id]
OS.shell_open(%contactus_button.editor_description) OS.shell_open(%contactus_button.editor_description)
"rd_licenses": "rd_licenses":
var entry = tk_about["rd_licenses"] entry = tk_about[id]
OS.shell_open(%licenses_button.editor_description) OS.shell_open(%licenses_button.editor_description)
# print ("ID not found") _:
print ("ID not found")

View file

@ -2,7 +2,7 @@ ID,URL,Description
rd_web,https://retrodeck.net/,Opens the RetroDECK Website in your default browser rd_web,https://retrodeck.net/,Opens the RetroDECK Website in your default browser
rd_changelog,https://retrodeck.readthedocs.io/en/latest/wiki_rd_versions/version-history/,Opens the RetroDECK change log in your default browser rd_changelog,https://retrodeck.readthedocs.io/en/latest/wiki_rd_versions/version-history/,Opens the RetroDECK change log in your default browser
rd_wiki,https://retrodeck.readthedocs.io/en/latest/,Opens the RetroDECK Wiki in your default browser rd_wiki,https://retrodeck.readthedocs.io/en/latest/,Opens the RetroDECK Wiki in your default browser
rd_credits,https://retrodeck.readthedocs.io/en/latest/,Opens the RetroDECK Credits in your default browser rd_credits,https://retrodeck.readthedocs.io/en/latest/wiki_credits/donations-licenses/,Opens the RetroDECK Credits in your default browser
rd_donate,https://retrodeck.readthedocs.io/en/latest/wiki_credits/donations-licenses/,Opens Donations in your default browser rd_donate,https://retrodeck.readthedocs.io/en/latest/wiki_credits/donations-licenses/,Opens Donations in your default browser
rd_contactus,https://github.com/XargonWan/RetroDECK,Opens the RetroDECK contact us section in your default browser rd_contactus,https://github.com/XargonWan/RetroDECK,Opens the RetroDECK contact us section in your default browser
rd_licenses,https://retrodeck.readthedocs.io/en/latest/wiki_credits/donations-licenses/,Opens the RetroDECK licenses in your default browser rd_licenses,https://retrodeck.readthedocs.io/en/latest/wiki_credits/donations-licenses/,Opens the RetroDECK licenses in your default browser