Projekt

Obecné

Profil

Stáhnout (1.27 KB) Statistiky
| Větev: | Revize:
1
import yaml
2

    
3
# Path to dataset configuration files
4
CONFIG_FILES_PATH = "DatasetConfigs/"
5
# Config file type
6
CONFIG_FILE_TYPE = ".yaml"
7

    
8

    
9
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
        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
def update_configuration(dataset_name, new_devices):
34
    """
35
    Open dataset and appends new_devices to the end
36

    
37
    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
        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")
(1-1/3)