-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
executable file
·57 lines (47 loc) · 1.39 KB
/
main.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
#!/usr/bin/env python3
import sys, json
from respondd.Neighbours import Neighbours
from respondd.Nodeinfo import Nodeinfo
from respondd.Statistics import Statistics
from respondd.Cache import Cache
from respondd.Net import Net
def getConfigFromFile(argv):
confFile = './config.json'
if len(argv) > 0:
confFile = argv[0]
try:
with open(confFile) as data_file:
try:
data = json.load(data_file)
except ValueError:
print("Could not load config file. File may contains invalid data (ValueError).", file=sys.stderr)
exit(1)
except FileNotFoundError:
print("Config file was not found (FileNotFoundError).", file=sys.stderr)
exit(1)
return data
def init(jsonData):
domains = {}
for domain in jsonData['domains']:
domains[domain['site_code']] = {
'neighbours' : Neighbours(domain),
'nodeinfo' : Nodeinfo(domain, jsonData['global']),
'statistics' : Statistics(domain)
}
return domains
def main(argv):
data = getConfigFromFile(argv)
handles = init(data)
Cache.setTimeout(data['global']['cache_time_s'])
net = Net(data, handles)
# for debugging purposes only:
# for k,v in handles.items():
# v['nodeinfo'].get()
# v['statistics'].get()
# v['neighbours'].get()
# print(handles['ffmsd01']['nodeinfo'].get())
# print(handles['ffmsd01']['statistics'].get())
# print(handles['ffmsd01']['neighbours'].get())
net.receiver()
if __name__ == '__main__':
main(sys.argv[1:])