|
@@ -1,6 +1,7 @@
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
from __future__ import print_function
|
|
|
+from copy import deepcopy
|
|
|
import io
|
|
|
import json
|
|
|
import socket
|
|
@@ -8,7 +9,22 @@ import subprocess
|
|
|
import time
|
|
|
import StringIO
|
|
|
|
|
|
+def dict_merge(a, b):
|
|
|
+ '''recursively merges dict's. not just simple a['key'] = b['key'], if
|
|
|
+ both a and bhave a key who's value is a dict then dict_merge is called
|
|
|
+ on both values and the result stored in the returned dictionary.'''
|
|
|
+ if not isinstance(b, dict):
|
|
|
+ return b
|
|
|
+ result = deepcopy(a)
|
|
|
+ for k, v in b.iteritems():
|
|
|
+ if k in result and isinstance(result[k], dict):
|
|
|
+ result[k] = dict_merge(result[k], v)
|
|
|
+ else:
|
|
|
+ result[k] = deepcopy(v)
|
|
|
+ return result
|
|
|
+
|
|
|
class AlfredParser:
|
|
|
+ alfred_datatypes = [ 158, 159 ]
|
|
|
prefix = "ffpb.nodes."
|
|
|
target_host = "fdca:ffee:ff12:a254::da7a"
|
|
|
target_port = 2003
|
|
@@ -16,14 +32,17 @@ class AlfredParser:
|
|
|
whitelist = [ "24:a4:3c:f8:5e:fa", "24:a4:3c:f8:5e:db", "24:a4:3c:d9:4f:69", "24:a4:3c:a3:67:f0", "24:a4:3c:a3:68:07", "24:a4:3c:d2:21:d5" ]
|
|
|
|
|
|
def execute(self):
|
|
|
- rawdata = subprocess.check_output(['alfred-json', '-z', '-r', '158'])
|
|
|
-
|
|
|
- data = json.loads(rawdata)
|
|
|
+ data = { }
|
|
|
ts = int(time.time())
|
|
|
|
|
|
+ for datatype in self.alfred_datatypes:
|
|
|
+ rawdata = subprocess.check_output(['alfred-json', '-z', '-r', int(datatype)])
|
|
|
+ newdata = json.loads(rawdata)
|
|
|
+ data = dict_merge(data, newdata)
|
|
|
+
|
|
|
if not self.alfred_dump is None:
|
|
|
f = io.open(self.alfred_dump, 'w')
|
|
|
- f.write(unicode(rawdata))
|
|
|
+ f.write(unicode(data))
|
|
|
f.close()
|
|
|
|
|
|
output = StringIO.StringIO()
|