-
Notifications
You must be signed in to change notification settings - Fork 43
/
config.py
46 lines (31 loc) · 967 Bytes
/
config.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Load configuration settings for protonfixes"""
import os
from configparser import ConfigParser
try:
from .logger import log
except ImportError:
from logger import log
CONF_FILE = '~/.config/protonfixes/config.ini'
DEFAULT_CONF = """
[main]
enable_checks = true
enable_splash = false
enable_global_fixes = true
[path]
cache_dir = ~/.cache/protonfixes
"""
CONF = ConfigParser()
CONF.read_string(DEFAULT_CONF)
try:
CONF.read(os.path.expanduser(CONF_FILE))
except Exception:
log.debug('Unable to read config file ' + CONF_FILE)
def opt_bool(opt: str) -> bool:
"""Convert bool ini strings to actual boolean values"""
return opt.lower() in ['yes', 'y', 'true', '1']
locals().update({x: opt_bool(y) for x, y in CONF['main'].items() if 'enable' in x})
locals().update({x: os.path.expanduser(y) for x, y in CONF['path'].items()})
try:
[os.makedirs(os.path.expanduser(d)) for n, d in CONF['path'].items()]
except OSError:
pass