1
|
from sys import exit
|
2
|
from configparser import RawConfigParser
|
3
|
|
4
|
|
5
|
class Config:
|
6
|
|
7
|
def __init__(self, filepath):
|
8
|
self.config = RawConfigParser()
|
9
|
if not self.config.read(filepath):
|
10
|
print(f"Failed to parse the config file {filepath}. Make sure you entered a valid path.")
|
11
|
exit(1)
|
12
|
|
13
|
self._parse_usb_detector_section()
|
14
|
self._parse_server_section()
|
15
|
self._parse_logger_section()
|
16
|
self._parse_cache_section()
|
17
|
|
18
|
def _parse_usb_detector_section(self):
|
19
|
section_name = "usb_detector"
|
20
|
self.scan_period_seconds = float(self.config[section_name]["scan_period_seconds"])
|
21
|
self.connected_devices_filename = self.config[section_name]["connected_devices_filename"]
|
22
|
|
23
|
def _parse_server_section(self):
|
24
|
section_name = "server"
|
25
|
self.server_url = self.config[section_name]["url"]
|
26
|
self.server_port = self.config[section_name]["port"]
|
27
|
self.server_endpoint = self.config[section_name]["end_point"]
|
28
|
|
29
|
def _parse_logger_section(self):
|
30
|
section_name = "logger"
|
31
|
self.logger_config_file = self.config[section_name]["config_file"]
|
32
|
|
33
|
def _parse_cache_section(self):
|
34
|
section_name = "cache"
|
35
|
self.cache_dir = self.config[section_name]["directory"]
|
36
|
self.cache_max_entries = int(self.config[section_name]["max_entries"])
|
37
|
self.cache_max_retries = int(self.config[section_name]["max_retries"])
|
38
|
self.cache_retry_period_seconds = float(self.config[section_name]["retry_period_seconds"])
|