-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.py
36 lines (25 loc) · 988 Bytes
/
configuration.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
import os
import yaml
from paths import APP_DIR
from debug import get_logger
log = get_logger("arkbot")
with open(os.path.join(APP_DIR, 'config', 'config.yaml'), 'r', encoding='utf-8', errors='ignore') as f:
config = yaml.load(f.read())
class Server(object):
def __init__(self, config):
for key, value in config.items():
self.__dict__[key] = value
server = Server(config)
with open(os.path.join(APP_DIR, 'VERSION'), 'r', encoding='utf-8') as f:
version = f.read()
def read_config(name):
log.debug(f"Reading config {name}")
fp = os.path.join(APP_DIR, 'config', f"{name}.yaml")
if not os.path.exists(fp):
return None
with open(fp, 'r', encoding='utf-8') as f:
return yaml.load(f.read())
def write_config(name, data):
log.debug(f"Writing config {name}")
with open(os.path.join(APP_DIR, 'config', f"{name}.yaml"), 'w+', encoding='utf-8') as f:
return f.write(yaml.dump(data, default_flow_style=False))