Skip to content

Commit

Permalink
Merge pull request #2 from mathieu-lemay/create-config-directory
Browse files Browse the repository at this point in the history
Ensure config file directory exists before creating config file
  • Loading branch information
pommee authored Jun 23, 2024
2 parents 6eba20f + 7951248 commit f1a40f0
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions application/util/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

from pydantic import BaseModel
from yaml import dump, safe_load

Expand Down Expand Up @@ -39,13 +37,14 @@ def create_default_config():
"toggle-scroll": "s",
},
}
with open(CONFIG_PATH, "w") as file:
CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True)
with CONFIG_PATH.open("w") as file:
dump(default_config, file)


def load_config():
if not os.path.exists(CONFIG_PATH):
if not CONFIG_PATH.exists():
create_default_config()
with open(CONFIG_PATH, "r") as file:
with CONFIG_PATH.open() as file:
config_dict = safe_load(file)
return Config(**config_dict)

0 comments on commit f1a40f0

Please sign in to comment.