Projekt

Obecné

Profil

« Předchozí | Další » 

Revize af7609b5

Přidáno uživatelem Tomáš Ballák před více než 3 roky(ů)

Re #8193 - refactoring crawler

Zobrazit rozdíly:

modules/crawler/Utilities/configure_functions.py
1 1
import yaml
2 2
import os
3
from typing import Dict, Set
4
from shared_types import StringSetType
3 5
from Utilities.Database import database_record_logs
4 6
from Utilities.helpers import should_skip
5 7

  
......
9 11
CONFIG_FILE_TYPE = ".yaml"
10 12

  
11 13

  
12
def load_configuration(dataset_name):
14
def load_configuration(dataset_name: str) -> Dict[str, any]:
13 15
    """
14 16
    Loads yaml configuration file into memory
15 17

  
......
22 24
    with open(CONFIG_FILES_PATH + dataset_name + CONFIG_FILE_TYPE, "r") as f:
23 25
        data = yaml.load(f, Loader=yaml.FullLoader)
24 26

  
25
    devices_dic = dict()
27
    devices_dic = {}
26 28

  
27 29
    if data["devices"] is not None:
28 30
        for item in data["devices"]:
......
33 35
    return data
34 36

  
35 37

  
36
def update_configuration(dataset_name, new_devices):
38
def update_configuration(dataset_name: str,
39
                         new_devices: StringSetType) -> None:
37 40
    """
38 41
    Open dataset and appends new_devices to the end
39 42

  
......
53 56
            file.write("\n")
54 57

  
55 58

  
56
def check_if_there_is_a_config_file(dataset_name):
59
def check_if_there_is_a_config_file(dataset_name: str) -> bool:
57 60
    """
58 61
    Goes trough all config files (represeting valid dataset in database)
59 62
    and checks if dataset_name is there
......
75 78
    return False
76 79

  
77 80

  
78
def return_dictionary_of_valid_devices(devices):
81
def return_dictionary_of_valid_devices(
82
        devices: Dict[str, any]) -> Dict[str, Dict[str, any]]:
79 83
    """
80 84
    Iterates over all devices specified in config file
81 85

  
......
87 91
    Returns:   
88 92
        Dictonary containing only valid devices
89 93
    """
90
    valid_devices = dict()
94
    valid_devices = {}
91 95

  
92 96
    for device in devices.keys():
93 97
        if not should_skip(devices[device]):

Také k dispozici: Unified diff