-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
38 lines (30 loc) · 1.23 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
import os
import yaml
import sys
from typing import List, Any
class Config(object):
def __init__(self, filepath):
# Load in the config file at the given filepath
with open(filepath) as file_stream:
self.config = yaml.safe_load(file_stream.read())
#account setup
self.user_id = self.get_config(["matrix", "user_id"], required=True)
self.user_password = self.get_config(["matrix", "user_password"], required=True)
self.homeserver_url = self.get_config(["matrix", "homeserver_url"], required=True)
#database setup
self.name = self.get_config(["database", "name"], required=True)
self.user = self.get_config(["database", "user"], required=True)
self.password = self.get_config(["database", "password"], required=True)
self.host = self.get_config(["database", "host"], required=True)
self.port = self.get_config(["database", "port"], required=True)
def get_config(
self,
path: List[str],
default: Any = None,
required: bool = True,
) -> Any:
#get fitting option
config = self.config
for name in path:
config = config.get(name)
return config