]> git.armaanb.net Git - lightcards.git/blob - lightcards/config.py
Add menu keybindings to config
[lightcards.git] / lightcards / config.py
1 # Parse lightcards config file
2 # Armaan Bhojwani 2021
3
4 import sys
5 from pathlib import Path
6 import os
7
8
9 class ConfigException(BaseException):
10     def __init__(self, message):
11         self.message = message
12         print(f"lightcards: {self.message}")
13         sys.exit(4)
14
15
16 def read_file(file):
17     config = {}
18     file = str(file)
19     files = []
20     local_xdg = f"{os.path.expanduser('~')}/{os.environ.get('XDG_CACHE_HOME')}/lightcards/config.py"
21     local = f"{os.path.expanduser('~')}/.config/lightcards/config.py"
22     world = "/etc/lightcards/config.py"
23
24     if os.path.exists(world):
25         files.append(world)
26     if os.path.exists(local_xdg):
27         files.append(local_xdg)
28     if os.path.exists(local):
29         files.append(local)
30     if os.path.exists(file):
31         files.append(file)
32
33     for f in files:
34         exec(Path(str(f)).read_text(), {}, config)
35
36     return config