1 |
70e660a8
|
petrh
|
import yaml
|
2 |
|
|
|
3 |
04a2b5a4
|
petrh
|
# Path to dataset configuration files
|
4 |
|
|
CONFIG_FILES_PATH = "DatasetConfigs/"
|
5 |
|
|
# Config file type
|
6 |
|
|
CONFIG_FILE_TYPE = ".yaml"
|
7 |
70e660a8
|
petrh
|
|
8 |
|
|
|
9 |
04a2b5a4
|
petrh
|
def load_configuration(dataset_name):
|
10 |
|
|
"""
|
11 |
|
|
Loads yaml configuration file into memory
|
12 |
|
|
|
13 |
|
|
Args:
|
14 |
|
|
dataset_name: name of dataset that has existing configuration file
|
15 |
|
|
|
16 |
|
|
Returns:
|
17 |
|
|
yaml configuration file as dictionary
|
18 |
|
|
"""
|
19 |
|
|
with open(CONFIG_FILES_PATH + dataset_name + CONFIG_FILE_TYPE, "r") as f:
|
20 |
70e660a8
|
petrh
|
data = yaml.load(f, Loader=yaml.FullLoader)
|
21 |
|
|
|
22 |
|
|
devices_dic = dict()
|
23 |
|
|
|
24 |
|
|
if data["devices"] is not None:
|
25 |
|
|
for item in data["devices"]:
|
26 |
|
|
devices_dic.update(item)
|
27 |
|
|
|
28 |
|
|
data["devices"] = devices_dic
|
29 |
|
|
|
30 |
|
|
return data
|
31 |
|
|
|
32 |
|
|
|
33 |
04a2b5a4
|
petrh
|
def update_configuration(dataset_name, new_devices):
|
34 |
|
|
"""
|
35 |
|
|
Open dataset and appends new_devices to the end
|
36 |
70e660a8
|
petrh
|
|
37 |
04a2b5a4
|
petrh
|
Args:
|
38 |
|
|
dataset_name: name of dataset that has existing configuration file
|
39 |
|
|
new_devices: list or set of new devices for dataset
|
40 |
|
|
"""
|
41 |
|
|
with open(CONFIG_FILES_PATH + dataset_name + CONFIG_FILE_TYPE, "a") as file:
|
42 |
70e660a8
|
petrh
|
for device in new_devices:
|
43 |
|
|
file.write(" - "+device+":\n")
|
44 |
|
|
file.write(" x: UNKNOWN!\n")
|
45 |
|
|
file.write(" y: UNKNOWN!\n")
|
46 |
|
|
file.write("\n")
|