-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
47 lines (36 loc) · 1.45 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
43
44
45
46
47
# -*- coding: utf-8 -*-
import os
import yaml
CONFIG_FILE_NAME = "config.yml"
class EmptyConfigFileError(Exception):
pass
class Config:
FIELD_MQTT_CONNECTION = "mqtt_connection"
FIELD_BG_DIR = "background_dir"
FIELD_COUNTERS = "counters"
FIELD_SHOW_TIME = "show_time"
FIELD_RECEIVERS = "receivers"
FIELD_AM_HOST = "am_host"
FIELD_COLORS = "colors"
def __init__(self):
config_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
CONFIG_FILE_NAME
)
if not os.path.exists(config_path) or not os.path.isfile(config_path):
raise FileNotFoundError("{} not found".format(config_path))
with open(config_path, 'r') as source:
yaml_content = yaml.safe_load(source.read())
if not yaml_content:
raise EmptyConfigFileError()
self.background_dir = yaml_content.get(self.FIELD_BG_DIR, None)
self.counters = yaml_content.get(self.FIELD_COUNTERS, [])
self.mqtt_connection = yaml_content.get(self.FIELD_MQTT_CONNECTION)
self.show_time = yaml_content.get(self.FIELD_SHOW_TIME)
self.am_host = yaml_content.get(self.FIELD_AM_HOST)
self.receivers = yaml_content.get(self.FIELD_RECEIVERS)
self.colors = yaml_content.get(self.FIELD_COLORS)
def get_color(self, severity):
if severity in self.colors.keys():
return self.colors.get(severity)
return "#707070"