config_path = '/gs/config/' def is_config_existing(): return is_file_existing(config_path + 'device_config.json') def is_initial_config_existing(): return is_file_existing(config_path + 'initial_config.py') def is_file_existing(filepath): try: f = open(filepath, "r") f.close() # continue with the file. return True except OSError: # open failed # handle the file open cas return False def replace_value(filepath, prop, newvalue): with open(filepath, 'r') as file: config_lines = file.readlines() file.close() # Parse the config data into a dictionary config_dict = {} for line in config_lines: if '=' in line: key, value = line.strip().split('=') config_dict[key.strip()] = value.strip() # Add or Update the value of the property config_dict[prop] = newvalue # Write the modified data back to the file with open(filepath, 'w') as file: for key, value in config_dict.items(): file.write(f"{key} = {value}\n")