forked from simons-public/protonfixes
-
Notifications
You must be signed in to change notification settings - Fork 74
/
config.py
executable file
·45 lines (35 loc) · 962 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
""" Load configuration settings for protonfixes
"""
import os
from configparser import ConfigParser
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))
# pylint: disable=W0703
except Exception:
log.debug('Unable to read config file ' + CONF_FILE)
def opt_bool(opt):
""" Convert bool ini strings to actual boolean values
"""
return opt.lower() in ['yes', 'y', 'true', '1']
# pylint: disable=E1101
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