Skip to content

Commit

Permalink
Fixed config versioning and backup creating config (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
billzee authored Aug 5, 2023
1 parent 4123326 commit 9a9fde6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ logs/
backups/
datastore/datastore.yml
config.yml
config.yml.bak
config/.ssh/

# VSCode
Expand Down
5 changes: 3 additions & 2 deletions openct/setup/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
if user_input not in {"yes", "y"}:
print("Config file not overwritten. Exiting.")
sys.exit()
os.rename(CONFIG_FILE, CONFIG_FILE + ".bak")

mt_backup_config = {
starting_config_values = {
"config_version": {
"version": "0.1.0",
"comments": "Inital config verion."
Expand All @@ -38,4 +39,4 @@
}

with open(file="config.yml", mode="w", encoding="utf-8") as file:
yaml.dump(mt_backup_config, file, default_flow_style=False)
yaml.dump(starting_config_values, file, default_flow_style=False)
14 changes: 10 additions & 4 deletions openct/setup/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ def load_config_from_file(config_file: str) -> Config:
with open(file=config_file, mode="r", encoding="utf-8") as conf_file:
config_data = yaml.safe_load(conf_file)

config_version = ConfigVersion(
version=config_data["config"]["version"],
comments=config_data["config"]["comments"],
)
if "config_version" in config_data:
config_version = ConfigVersion(
version=config_data["config_version"]["version"],
comments=config_data["config_version"]["comments"],
)
else:
config_version = ConfigVersion(
version="0.0.0",
comments="Pre-versioning configuration file.",
)

identity = ConfigIdentity(
username=config_data["identity"]["username"],
Expand Down

0 comments on commit 9a9fde6

Please sign in to comment.