fix(generateDefaultConfig.py): fixed quotes around strings and improper floating point parsing

This commit is contained in:
2025-03-26 10:56:22 -04:00
parent 8d3db04469
commit 30990ba868
2 changed files with 48 additions and 13 deletions

View File

@@ -1,11 +1,22 @@
opac: EOS:
lowTemp: Helm:
numeric: LogFile: "log"
maxIter: 10 Network:
Approx8:
NonStiff:
AbsTol: 1.0e-06
RelTol: 1.0e-06
Stiff:
AbsTol: 1.0e-06
RelTol: 1.0e-06
Probe: Probe:
GLVis: GLVis:
Visualization: true Host: "localhost"
Host: localhost Port: 19916
Port: '19916' Visualization: true
LogManager: LogManager:
DefaultLogName: 4DSSE.log DefaultLogName: "4DSSE.log"
opac:
lowTemp:
numeric:
maxIter: 10

View File

@@ -14,12 +14,14 @@ def parse_value(value, type_hint):
return int(value) return int(value)
elif type_hint in {"float", "double"}: elif type_hint in {"float", "double"}:
return float(value) return float(value)
elif value == "defaultDataDir":
return "data" # special case for defaultDataDir
elif type_hint == "bool": elif type_hint == "bool":
return value.lower() in {"true", "1"} return value.lower() in {"true", "1"}
elif value.startswith('"') and value.endswith('"'):
return value.strip('"') # Remove quotes for string literals
elif value.startswith("'") and value.endswith("'"): elif value.startswith("'") and value.endswith("'"):
return value.strip("'") # Remove single quotes return value.strip("'") # Remove single quotes
elif value.startswith('"') and value.endswith('"'):
return value.strip('"') # Remove quotes for string literals
return value # Return as-is if unsure return value # Return as-is if unsure
@@ -47,14 +49,36 @@ def scan_files(directory):
if match: if match:
type_hint, hierarchy, value = match.groups() type_hint, hierarchy, value = match.groups()
keys = hierarchy.split(":") keys = hierarchy.split(":")
if keys[0] == "Data" and keys[1] == "Dir":
continue # Skip Data:Dir as it is a special case
insert_into_dict(hierarchy_dict, keys, value, type_hint) insert_into_dict(hierarchy_dict, keys, value, type_hint)
return hierarchy_dict return hierarchy_dict
class QuotedString(str):
pass
def represent_quoted_string(dumper, data):
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='"')
def save_yaml(data, output_file): def save_yaml(data, output_file):
"""Saves the nested dictionary to a YAML file.""" """Saves the nested dictionary to a YAML file."""
yaml.add_representer(QuotedString, represent_quoted_string)
def quote_strings(data):
if isinstance(data, dict):
return {k: quote_strings(v) for k, v in data.items()}
elif isinstance(data, list):
return [quote_strings(item) for item in data]
elif isinstance(data, str):
return QuotedString(data)
else:
return data
data = quote_strings(data)
with open(output_file, 'w', encoding='utf-8') as f: with open(output_file, 'w', encoding='utf-8') as f:
yaml.dump(data, f, default_flow_style=False, sort_keys=False, indent=4) yaml.dump(data, f, default_flow_style=False, sort_keys=True, indent=2)
if __name__ == "__main__": if __name__ == "__main__":
import argparse import argparse