diff options
author | root <root@srv.freifunk.in-kiel.de> | 2014-12-29 17:53:41 +0100 |
---|---|---|
committer | root <root@srv.freifunk.in-kiel.de> | 2014-12-29 17:53:41 +0100 |
commit | 5f4b213b24930ab948f53d05a9ea0eef6ec02afd (patch) | |
tree | c716ecf29ea7521caa92cdf1c67a344f87448424 | |
parent | 6cf55b922b8067635b015e32c1b665f1a9034f41 (diff) |
Dies sind die alle aenderungen seit 29.09.2014
das ist nicht gut, bitte immer alle kleinen aenderungen zumindest lokal committen!
-rwxr-xr-x[-rw-r--r--] | alfred.py | 12 | ||||
-rwxr-xr-x | bat2nodes.py | 46 | ||||
-rwxr-xr-x | batman.py | 42 | ||||
-rw-r--r-- | crontab | 8 | ||||
-rwxr-xr-x | mkmap.sh | 7 | ||||
-rw-r--r-- | nodedb.py | 2 |
6 files changed, 62 insertions, 55 deletions
diff --git a/alfred.py b/alfred.py index b956026..f85888f 100644..100755 --- a/alfred.py +++ b/alfred.py @@ -3,12 +3,10 @@ import subprocess import json class alfred: - def __init__(self,request_data_type = 158): - self.request_data_type = request_data_type + def __init__(self): + pass - def aliases(self): - output = subprocess.check_output(["alfred-json","-r",str(self.request_data_type),"-f","json","-z"]) - alfred_data = json.loads(output.decode("utf-8")) + def aliases(alfred_data): alias = {} for mac,node in alfred_data.items(): node_alias = {} @@ -37,6 +35,6 @@ class alfred: return alias if __name__ == "__main__": - ad = alfred() - al = ad.aliases() + import sys + al = alfred.aliases(sys.argv[1]) print(al) diff --git a/bat2nodes.py b/bat2nodes.py index 73329bc..ea78aaa 100755 --- a/bat2nodes.py +++ b/bat2nodes.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# bitte immer alle kleinen aenderungen zumindest lokat committen! import json import fileinput @@ -23,19 +24,29 @@ import sys parser = argparse.ArgumentParser() +parser.add_argument('-A', '--alfred', + help='retrieve aliases from alfred', + action='append', + metavar='FILE', + ) + parser.add_argument('-a', '--aliases', help='read aliases from FILE', action='append', - metavar='FILE') + metavar='FILE', + ) -parser.add_argument('-m', '--mesh', action='append', - help='batman mesh interface') +parser.add_argument('-d', '--destination-directory', + help='destination directory for generated files', + action='store', + required=True, + ) -parser.add_argument('-A', '--alfred', action='store_true', - help='retrieve aliases from alfred') - -parser.add_argument('-d', '--destination-directory', action='store', - help='destination directory for generated files',required=True) +parser.add_argument('-m', '--mesh', + help='read batman vis data from FILE', + action='append', + metavar='FILE', + ) args = parser.parse_args() @@ -44,24 +55,19 @@ options = vars(args) db = NodeDB(int(time.time())) if options['mesh']: - for mesh_interface in options['mesh']: - bm = batman(mesh_interface) + for f in options['mesh']: + bm = batman(json.load(open(f,encoding='utf-8',errors='replace'))) db.parse_vis_data(bm.vis_data(options['alfred'])) for gw in bm.gateway_list(): - db.mark_gateways(gw['mac']) -else: - bm = batman() - db.parse_vis_data(bm.vis_data(options['alfred'])) - for gw in bm.gateway_list(): - db.mark_gateways([gw['mac']]) + db.mark_gateways([gw['mac']]) if options['aliases']: - for aliases in options['aliases']: - db.import_aliases(json.load(open(aliases,encoding='utf-8',errors='replace'))) + for f in options['aliases']: + db.import_aliases(json.load(open(f,encoding='utf-8',errors='replace'))) if options['alfred']: - af = alfred() - db.import_aliases(af.aliases()) + for f in options['alfred']: + db.import_aliases(alfred.aliases(json.load(open(f,encoding='utf-8',errors='replace')))) db.load_state("json/state.json") @@ -2,13 +2,14 @@ import subprocess import json import re +import base64 +import gzip class batman: """ Bindings for B.A.T.M.A.N. advanced batctl tool """ - def __init__(self, mesh_interface = "bat0", batctl = "/usr/sbin/batctl"): - self.mesh_interface = mesh_interface - self.batctl = batctl + def __init__(self, mesh_data): + self.mesh_data = mesh_data def vis_data(self,batadv_vis=False): vds = self.vis_data_batctl_legacy() @@ -20,34 +21,35 @@ class batman: vd = [] for line in lines: try: - utf8_line = line.decode("utf-8") - vd.append(json.loads(utf8_line)) - except e: + vd.append(json.loads(line)) + except: + print("error in vd.append(): '%s'" % line) pass return vd def vis_data_batctl_legacy(self): - """ Parse "batctl -m <mesh_interface> vd json -n" into an array of dictionaries. - """ - output = subprocess.check_output(["batctl","-m",self.mesh_interface,"vd","json","-n"]) - lines = output.splitlines() + output = self.mesh_data["vd"] + output = base64.b64decode(output) + output = gzip.decompress(output) + output_utf8 = output.decode("utf-8") + lines = output_utf8.splitlines() vds = self.vis_data_helper(lines) return vds def vis_data_batadv_vis(self): - """ Parse "batadv-vis -i <mesh_interface> -f json" into an array of dictionaries. - """ - output = subprocess.check_output(["batadv-vis","-i",self.mesh_interface,"-f","json"]) - lines = output.splitlines() + output = self.mesh_data["vis"] + output = base64.b64decode(output) + output = gzip.decompress(output) + output_utf8 = output.decode("utf-8") + lines = output_utf8.splitlines() return self.vis_data_helper(lines) def gateway_list(self): - """ Parse "batctl -m <mesh_interface> gwl -n" into an array of dictionaries. - """ - output = subprocess.check_output([self.batctl,"-m",self.mesh_interface,"gwl","-n"]) + output = self.mesh_data["gwl"] + output = base64.b64decode(output) output_utf8 = output.decode("utf-8") - # TODO Parse information lines = output_utf8.splitlines() + # TODO Parse information own_mac = re.match(r"^.*MainIF/MAC: [^/]+/([0-9a-f:]+).*$",lines[0]).group(1) # Remove header line del lines[0] @@ -67,8 +69,8 @@ class batman: def gateway_mode(self): """ Parse "batctl -m <mesh_interface> gw" """ - output = subprocess.check_output([self.batctl,"-m",self.mesh_interface,"gw"]) - elements = output.decode("utf-8").split() + output_utf8 = self.mesh_data["gw"] + elements = output_utf8.split() mode = elements[0] if mode == "server": return {'mode': 'server', 'bandwidth': elements[3]} @@ -2,13 +2,9 @@ MAILTO=ffki-noc@in-kiel.de # Freifunk Map Updates -PATH=/opt/alfred/vis:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - -* * * * * root (DEBUG=1 /opt/ffmap-backend/get-nodes.pl && /usr/local/sbin/fastd-update > /dev/null ) ; /opt/ffmap-backend/mkmap.sh /opt/ffmap-backend/ -* * * * * root (DEBUG=1 /usr/local/sbin/fastd-update > /dev/null ) ; /opt/ffmap-backend/mkmap.sh /opt/ffmap-backend/ - -* * * * * root /usr/local/bin/check-gateway +PATH=/usr/sbin:/usr/bin:/sbin:/bin +* * * * * root /opt/ffmap-backend/mkmap.sh /opt/ffmap-backend/ > /dev/null 2>&1 0 0 * * * root find /opt/ffmap-backend/nodedb/ -name '*.rrd' -ctime 8 -execdir rm '{}' + 0 1 * * * root find /opt/ffmap-backend/nodeplots/ -name '*.png' -ctime 1 -execdir rm '{}' + @@ -9,4 +9,9 @@ cd "$(dirname "$0")"/ #./ffhlwiki.py http://freifunk.metameute.de/wiki/Knoten > aliases_hl.json #./ffhlwiki.py http://freifunk.metameute.de/wiki/Moelln:Knoten > aliases_moelln.json -./bat2nodes.py -A -a json/aliases.json -d $DEST +wget -q -O json/alfred.158.json "http://vpn0.freifunk.in-kiel.de/alfred.cgi?158" +wget -q -O json/alfred.159.json "http://vpn0.freifunk.in-kiel.de/alfred.cgi?159" +wget -q -O json/batman.json "http://vpn0.freifunk.in-kiel.de/batman.cgi" + +./bat2nodes.py --alfred json/alfred.158.json --aliases json/aliases.json --mesh json/batman.json -d $DEST + @@ -225,7 +225,7 @@ class NodeDB: try: node = self.maybe_node_by_mac((gateway, )) except: - print("WARNING: did not find gateway '",gateway,"' in node list") + print("WARNING: did not find gateway '%s' in node list" % gateway) continue node.flags['gateway'] = True |