-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
59 lines (41 loc) · 1.27 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
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/python3.6
from dotenv import load_dotenv
import yaml
import os
class Config():
"""
Class that holds the configuration.
"""
def __init__(self, yaml_file="config.yaml"):
"""
The class requires the configuration file (default: config.yaml).
"""
load_dotenv()
with open(yaml_file) as yaml_content:
self.__config = yaml.full_load(yaml_content)
def get_configs(self):
"""
Returns all the libchecker configurations.
"""
return self.__config
def get_config(self, index=0):
"""
Returns the configuration by index.
"""
return self.__config[index]
def len(self):
"""
Returns how many configurations exist.
"""
return len(self.__config)
@staticmethod
def get_value(node, key, default=None):
"""
Returns the parameter value, or the default, based on the key.
If the value starts with "env.", returns the value of the
environment variable defined right after.
"""
value = node.get(key, default)
if value and isinstance(value, str) and value.startswith("env."):
value = os.environ.get(value.split(".")[1], default)
return value