-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
101 lines (84 loc) · 2.75 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import configparser
from pathlib import Path
import pathlib
import os
class Config:
def __init__(self):
global config
try:
script_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
rel_path = "config.conf"
abs_file_path = os.path.join(script_dir, rel_path)
configFile = Path(abs_file_path)
assert os.path.exists(abs_file_path)
print(configFile)
config = configparser.ConfigParser()
print('name ' + configFile.name)
config.read(configFile.name)
print(config.sections())
mqttConfig = config['mqtt']
d = dict(mqttConfig)
print(d)
except IOError as e:
print("I/O error({0}): {1}".format(e.errno, e.strerror))
def reloadFile():
try:
configFile = Path("./config.conf")
except IOError as e:
print("I/O error({0}): {1}".format(e.errno, e.strerror))
config = configparser.ConfigParser()
config.read(configFile.name)
def getConfigTopic(self):
topic = config['mqtt']['topic']
return topic
def getConfigPort(self):
port = config['mqtt']['port']
return port
def getConfigServerMqtt(self):
serverMqtt = config['mqtt']['mqtt_server']
return serverMqtt
def getConfigMqtt(self):
try:
mqttConfig = config['mqtt']
return dict(mqttConfig)
except KeyError:
print("Errore file configurazione")
return ''
def getConfigDevice(self):
data = {}
try:
deviceConfig = config['device']['list']
l = deviceConfig.split(',')
for a in l:
l = a.split(':')
data[l[1]] = l[0]
return data
except KeyError:
print("Errore file configurazione Device")
return data
def getTimeNoData(self):
timeNoData = config['alert']['time_no_data']
return timeNoData
def getMinTemp(self):
deviceConfig = config['alert']['minTemp']
data = {}
l = deviceConfig.split(',')
for a in l:
l = a.split(':')
data[l[1]] = l[0]
return data
def getMaxTemp(self):
data = {}
try:
deviceConfig = config['alert']['maxTemp']
l = deviceConfig.split(',')
for a in l:
l = a.split(':')
data[l[1]] = l[0]
return data
except KeyError:
print("Errore file alert maxtremp")
return data
def getConfigUpdate(self):
updateConfig = config['update']
return updateConfig