-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
42 lines (34 loc) · 1.31 KB
/
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
import os
import yaml
_SCRIPT_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
_USER_CONFIG = os.path.join(os.getenv("HOME"), ".config")
_APP_NAME = "WebsiteIndicator"
_CONFIG_FILE = "config.yml"
if os.path.isdir(os.path.join(_USER_CONFIG, _APP_NAME)):
_CONFIG_DIR = os.path.join(_USER_CONFIG, _APP_NAME)
else:
_CONFIG_DIR = os.path.join(_SCRIPT_DIR)
if os.path.isfile(os.path.join(_CONFIG_DIR, _CONFIG_FILE)):
with open(os.path.join(_CONFIG_DIR, _CONFIG_FILE), "r") as file:
config = yaml.safe_load(file)
# If config file is empty, make an empty dictionary
if not config:
config = {}
else:
config = {}
config['dir'] = _CONFIG_DIR
config['script_dir'] = _SCRIPT_DIR
# Default value
if 'general' not in config:
config['general'] = {}
if 'filter' not in config:
config['filter'] = {}
if 'file_name' not in config['general']:
config['general']['file_name'] = "lesezeichen.xml"
if 'image_dir' not in config['general']:
config['general']['image_dir'] = os.path.join(_CONFIG_DIR, "logos")
else:
config['general']['image_dir'] = config['general']['image_dir']\
.replace("${CONFIG_DIR}", _CONFIG_DIR)\
.replace("${HOME}", os.getenv("HOME"))
config['general']['file_path'] = os.path.join(_CONFIG_DIR, config['general']['file_name'])