Browse Source

add getStruct

Marcus Scharf 6 years ago
parent
commit
7939a6e950
6 changed files with 13 additions and 14 deletions
  1. 3 3
      ext-respondd.py
  2. 1 1
      lib/neighbours.py
  3. 1 1
      lib/nodeinfo.py
  4. 7 5
      lib/respondd.py
  5. 0 3
      lib/respondd_client.py
  6. 1 1
      lib/statistics.py

+ 3 - 3
ext-respondd.py

@@ -26,9 +26,9 @@ if options["test"]:
   from lib.nodeinfo import Nodeinfo
   from lib.statistics import Statistics
   from lib.neighbours import Neighbours
-  print(json.dumps(Nodeinfo(config).get(), sort_keys=True, indent=4))
-  print(json.dumps(Statistics(config).get(), sort_keys=True, indent=4))
-  print(json.dumps(Neighbours(config).get(), sort_keys=True, indent=4))
+  print(json.dumps(Nodeinfo(config).getStruct(), sort_keys=True, indent=4))
+  print(json.dumps(Statistics(config).getStruct(), sort_keys=True, indent=4))
+  print(json.dumps(Neighbours(config).getStruct(), sort_keys=True, indent=4))
   sys.exit(1)
 
 extResponddClient = ResponddClient(config)

+ 1 - 1
lib/neighbours.py

@@ -48,7 +48,7 @@ class Neighbours(Respondd):
 
     return j
 
-  def get(self):
+  def _get(self):
     j = {"batadv": {}}
     stationDump = None
     if 'mesh-wlan' in self._config:

+ 1 - 1
lib/nodeinfo.py

@@ -73,7 +73,7 @@ class Nodeinfo(Respondd):
           j[ml.group(1)] = ml.group(2)
     return j
 
-  def get(self):
+  def _get(self):
     j = {
       "hostname": socket.gethostname(),
       "network": {

+ 7 - 5
lib/respondd.py

@@ -22,15 +22,17 @@ class Respondd:
     else:
       return lib.helper.getDevice_MAC(self._config["batman"]).replace(':', '')
 
-  def getJSON(self, root=None):
-    print(root)
-    j = self.get()
+  def getStruct(self, root=None):
+    j = self._get()
     j['node_id'] = self.getNode_ID()
     if not root is None:
       j_tmp = j
       j = {}
       j[root] = j_tmp
-    return bytes(json.dumps(j, separators=(',', ':')), 'UTF-8')
+    return j
+
+  def getJSON(self, root=None):
+    return bytes(json.dumps(self.getStruct(), separators=(',', ':')), 'UTF-8')
 
   def getJSONCompressed(self, root=None):
     return self.compress(self.getJSON(root))
@@ -41,6 +43,6 @@ class Respondd:
     gzip_data = gzip_data + encoder.flush()
     return gzip_data
 
-  def get(self):
+  def _get(self):
     return {}
   pass

+ 0 - 3
lib/respondd_client.py

@@ -72,9 +72,6 @@ class ResponddClient:
       print("unknown command: " + request)
       return
 
-    print(response.getJSON(request))
-    return
-
     if compress:
       sock.sendto(response.getJSONCompressed(request), sender)
     else:

+ 1 - 1
lib/statistics.py

@@ -113,7 +113,7 @@ class Statistics(Respondd):
 
     return j
 
-  def get(self):
+  def _get(self):
     j = {
       "clients":  self.getClients(),
       "traffic": self.getTraffic(),