summaryrefslogtreecommitdiff
path: root/modules/config.py
blob: 609e4d1ca081d04413b2fdee0843fb048e65f08e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import __main__
import os.path

import yaml

class Config:
    def __init__(self):
        self.intents_dir = ""
        self.applications_dir = ""

        self.lock = ""

    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