Index: suite_leahi/shared/scripts/configuration/application_init.py =================================================================== diff -u -r9f922977ecbe83f170f8d6be296539d8242a2fc8 -r23037797e0ceee499a15eabb33154da323d904f6 --- suite_leahi/shared/scripts/configuration/application_init.py (.../application_init.py) (revision 9f922977ecbe83f170f8d6be296539d8242a2fc8) +++ suite_leahi/shared/scripts/configuration/application_init.py (.../application_init.py) (revision 23037797e0ceee499a15eabb33154da323d904f6) @@ -7,6 +7,8 @@ from leahi_dialin.ui import utils from configuration import config from configuration import utility +from typing import Dict +from typing import Optional # WARNING: these variables has to match with the ones in the run.sh and in UI code POSTMSG_POSTFIX_PASSED = " passed" @@ -227,4 +229,95 @@ # Write back to .conf with open(target_file, 'w') as f: f.writelines(updated_lines) + +def get_section_text(section_name: str = '[Installation^Pressure Lines and Dialyzer]'): + """ + Reads the configuration file and extracts key-value pairs + from the specified section. + """ + location = '/home/denali/Public/luis/config/configurations/Instructions/Instructions.conf' + result = {} + + # Check if file exists to prevent FileNotFoundError + if not os.path.exists(location): + return result + + with open(location, 'r', encoding='utf-8') as f: + in_target_section = False + + for line in f: + # Remove leading/trailing whitespace + stripped_line = line.strip() + + # Skip empty lines + if not stripped_line: + continue + + # Check for Section Header, for example: [Section Name] + if stripped_line.startswith('[') and stripped_line.endswith(']'): + if stripped_line == section_name: + in_target_section = True + else: + # If already inside target section and a new section starts, stop reading + if in_target_section: + break + in_target_section = False + + continue + + # Parse key-value pairs inside the target section + if in_target_section and '=' in stripped_line: + # Split only on the first '=' to preserve '=' inside the value + key, value = stripped_line.split('=', 1) + result[key.strip()] = value.strip() + + return result + +def get_instructions_title(section_name: str = '[Installation^Pressure Lines and Dialyzer]'): + """ + Reads the configuration file and extracts the 'Title' value + from the specified section. + + Args: + section_name: The section header to search for in the config file. + + Returns: + The Title value if found, otherwise None. + """ + location = '/home/denali/Public/luis/config/configurations/Instructions/Instructions.conf' + + # Check if file exists before opening + if not os.path.exists(location): + return None + + with open(location, 'r', encoding='utf-8') as f: + in_target_section = False + + for line in f: + # Remove leading/trailing whitespace + stripped_line = line.strip() + + # Skip empty lines + if not stripped_line: + continue + + # Check for section header + if stripped_line.startswith('[') and stripped_line.endswith(']'): + if stripped_line == section_name: + in_target_section = True + else: + # If already in target section and a new section starts, stop reading + if in_target_section: + break + in_target_section = False + + continue + + # If inside the target section, look for Title + if in_target_section and stripped_line.startswith('Title'): + if '=' in stripped_line: + _, value = stripped_line.split('=', 1) + return value.strip() + + return None \ No newline at end of file