-
Notifications
You must be signed in to change notification settings - Fork 47
/
settings.py
37 lines (32 loc) · 1.34 KB
/
settings.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
import configparser
import netaddr
from os import path
from collections import defaultdict
applicationDir = path.dirname(path.abspath(__file__))
settingsINI = path.join(applicationDir, 'settings.ini')
settings = configparser.ConfigParser()
settings.read(settingsINI)
DiscoverTimeout = GlobalTimeout = 5
if settings.has_option('General', 'Timeout'):
DiscoverTimeout = GlobalTimeout = int(settings.get('General', 'Timeout').strip())
DevList = []
Dev = defaultdict(dict)
for section in settings.sections():
if section == 'General' or 'Commands' in section or 'Status' in section:
continue
print ("Reading device configuration for %s" % section)
Dev[section,'IPAddress'] = settings.get(section,'IPAddress').strip()
Dev[section,'MACAddress'] = netaddr.EUI(settings.get(section, 'MACAddress'))
if settings.has_option(section,'Timeout'):
Dev[section,'Timeout'] = int(settings.get(section, 'Timeout').strip())
else:
Dev[section,'Timeout'] = 8
if settings.has_option(section,'Device'):
Dev[section,'Device'] = int(settings.get(section, 'Device').strip(),16)
else:
Dev[section,'Device'] = None
if settings.has_option(section,'Type'):
Dev[section,'Type'] = settings.get(section,'Type').strip()
else:
Dev[section,'Type'] = section.strip()[-2:]
DevList.append(section.strip())