Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Refactor update_config.py to handle missing sections and options from…
Browse files Browse the repository at this point in the history
… default config
  • Loading branch information
Heavybullets8 committed May 30, 2024
1 parent b8dfc0e commit 4fda946
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions utils/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def update_config():
print(f"Loading default config from: {default_config_path}")

# Load the existing config and default config
current_config = ConfigObj(config_file_path, encoding='utf-8', list_values=False, preserve_comments=True)
default_config = ConfigObj(default_config_path, encoding='utf-8', list_values=False, preserve_comments=True)
current_config = ConfigObj(config_file_path, encoding='utf-8', list_values=False)
default_config = ConfigObj(default_config_path, encoding='utf-8', list_values=False)

print("Current config sections:", list(current_config.keys()))
print("Default config sections:", list(default_config.keys()))
Expand All @@ -26,6 +26,7 @@ def update_config():
if section not in current_config:
print(f"Adding missing section: {section}")
current_config[section] = default_options
current_config.comments[section] = default_config.comments.get(section, [])
else:
# Remove keys not present in the default config
for key in list(current_config[section].keys()):
Expand All @@ -37,6 +38,9 @@ def update_config():
if key not in current_config[section]:
print(f"Adding missing key: {key} to section: {section}")
current_config[section][key] = value
current_config[section].comments[key] = default_config[section].comments.get(key, [])
if key in default_options.inline_comments:
current_config[section].inline_comments[key] = default_options.inline_comments[key]

# Write the updated config back to the file
current_config.write()
Expand Down

0 comments on commit 4fda946

Please sign in to comment.