From 58d23f1f010e5d58b8d9296dae27988c939a53b1 Mon Sep 17 00:00:00 2001 From: Botond Hende Date: Tue, 22 Oct 2024 21:00:40 +0200 Subject: default config file and user override --- modules/config.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 modules/config.py (limited to 'modules') diff --git a/modules/config.py b/modules/config.py new file mode 100644 index 0000000..602ec8d --- /dev/null +++ b/modules/config.py @@ -0,0 +1,27 @@ +import __main__ +import os.path + +import yaml + +class Config: + def __init__(self): + self.intents_dir = "" + self.applications_dir = "" + + def update(self, **entries): + self.__dict__.update(entries) + + if not self.intents_dir.startswith("/"): + self.intents_dir = os.path.join(os.path.dirname(__main__.__file__), self.intents_dir) + +def load_config(): + config = Config() + with open(os.path.join(os.path.dirname(__main__.__file__), "config.yaml")) as stream: + config.update(**yaml.safe_load(stream)) + + user_config = os.path.join(os.environ["HOME"], ".config", "hestia", "config.yaml") + if os.path.exists(user_config): + with open(user_config) as stream: + config.update(**yaml.safe_load(stream)) + + return config \ No newline at end of file -- cgit v1.2.3-70-g09d2