Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 6b5427e6

Přidáno uživatelem Jakub Šilhavý před více než 2 roky(ů)

re #9422 Commented config_manager.py and main.py

Zobrazit rozdíly:

client/src/config_manager.py
3 3

  
4 4

  
5 5
class Config:
6
    """This class holds the configuration values of the application.
7

  
8
    It reads the configuration file passed in through the constructor
9
    and stores the values into class variables.
10
    """
6 11

  
7 12
    def __init__(self, filepath):
13
        """Constructor of the class.
14

  
15
        It instantiates the class, reads the configuration file,
16
        and parses all sections defined in it.
17

  
18
        :param filepath: path to the configuration file
19
        """
20
        # Create a new ConfigParser
8 21
        self.config = RawConfigParser()
22

  
23
        # Try to parse the configuration file. If it fails,
24
        # terminate the application.
9 25
        if not self.config.read(filepath):
10 26
            print(f"Failed to parse the config file {filepath}. Make sure you entered a valid path.")
11 27
            exit(1)
12 28

  
29
        # Parse the 'usb detector' section.
13 30
        self._parse_usb_detector_section()
31

  
32
        # Parse the 'server' section (API).
14 33
        self._parse_server_section()
34

  
35
        # Parse the 'logger' section.
15 36
        self._parse_logger_section()
37

  
38
        # Parse the 'cache' section.
16 39
        self._parse_cache_section()
17 40

  
18 41
    def _parse_usb_detector_section(self):
42
        """Parse the 'usb detector' section of the configuration file.
43
        """
19 44
        section_name = "usb_detector"
20 45
        self.scan_period_seconds = float(self.config[section_name]["scan_period_seconds"])
21 46
        self.connected_devices_filename = self.config[section_name]["connected_devices_filename"]
22 47

  
23 48
    def _parse_server_section(self):
49
        """Parse the 'server' section of the configuration file.
50
        """
24 51
        section_name = "server"
25 52
        self.server_url = self.config[section_name]["url"]
26 53
        self.server_port = self.config[section_name]["port"]
27 54
        self.server_endpoint = self.config[section_name]["end_point"]
28 55

  
29 56
    def _parse_logger_section(self):
57
        """Parse the 'logger' section of the configuration file.
58
        """
30 59
        section_name = "logger"
31 60
        self.logger_config_file = self.config[section_name]["config_file"]
32 61

  
33 62
    def _parse_cache_section(self):
63
        """Parse the 'cache' section of the configuration file.
64
        """
34 65
        section_name = "cache"
35 66
        self.cache_dir = self.config[section_name]["directory"]
36 67
        self.cache_max_entries = int(self.config[section_name]["max_entries"])

Také k dispozici: Unified diff