2012-06-05 17:40:21 +02:00
|
|
|
#!/usr/bin/env python3
|
2012-02-17 02:09:21 +01:00
|
|
|
|
2012-04-28 23:06:34 +02:00
|
|
|
import json
|
2012-02-17 02:09:21 +01:00
|
|
|
import fileinput
|
|
|
|
import argparse
|
2013-11-18 10:59:49 +01:00
|
|
|
import os
|
2012-02-17 02:09:21 +01:00
|
|
|
|
2013-11-12 00:28:11 +01:00
|
|
|
from batman import batman
|
2014-01-24 02:53:17 +01:00
|
|
|
from alfred import alfred
|
2013-11-18 10:59:49 +01:00
|
|
|
from rrd import rrd
|
2012-05-11 18:39:26 +02:00
|
|
|
from nodedb import NodeDB
|
|
|
|
from d3mapbuilder import D3MapBuilder
|
2012-05-11 14:12:41 +02:00
|
|
|
|
2012-06-15 18:27:51 +02:00
|
|
|
# Force encoding to UTF-8
|
|
|
|
import locale # Ensures that subsequent open()s
|
2013-11-18 21:35:40 +01:00
|
|
|
locale.getpreferredencoding = lambda _=None: 'UTF-8' # are UTF-8 encoded.
|
2012-06-15 18:27:51 +02:00
|
|
|
|
|
|
|
import sys
|
2013-03-11 09:24:57 +01:00
|
|
|
#sys.stdin = open('/dev/stdin', 'r')
|
|
|
|
#sys.stdout = open('/dev/stdout', 'w')
|
|
|
|
#sys.stderr = open('/dev/stderr', 'w')
|
2012-06-15 18:27:51 +02:00
|
|
|
|
2012-02-17 02:09:21 +01:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
|
|
|
parser.add_argument('-a', '--aliases',
|
|
|
|
help='read aliases from FILE',
|
2013-02-02 00:44:46 +01:00
|
|
|
action='append',
|
2012-02-17 02:09:21 +01:00
|
|
|
metavar='FILE')
|
|
|
|
|
2013-11-12 00:28:11 +01:00
|
|
|
parser.add_argument('-m', '--mesh', action='append',
|
|
|
|
help='batman mesh interface')
|
2012-02-17 02:09:21 +01:00
|
|
|
|
2013-12-29 04:15:40 +01:00
|
|
|
parser.add_argument('-o', '--obscure', action='store_true',
|
|
|
|
help='obscure client macs')
|
|
|
|
|
2014-01-24 02:53:17 +01:00
|
|
|
parser.add_argument('-A', '--alfred', action='store_true',
|
|
|
|
help='retrieve aliases from alfred')
|
|
|
|
|
2013-11-18 10:58:12 +01:00
|
|
|
parser.add_argument('-d', '--destination-directory', action='store',
|
|
|
|
help='destination directory for generated files',required=True)
|
|
|
|
|
2012-02-17 02:09:21 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
options = vars(args)
|
|
|
|
|
2012-05-11 18:39:26 +02:00
|
|
|
db = NodeDB()
|
2013-11-12 00:28:11 +01:00
|
|
|
if options['mesh']:
|
|
|
|
for mesh_interface in options['mesh']:
|
|
|
|
bm = batman(mesh_interface)
|
2014-01-30 22:21:15 +01:00
|
|
|
db.parse_vis_data(bm.vis_data(options['alfred']))
|
2013-11-12 00:28:11 +01:00
|
|
|
for gw in bm.gateway_list():
|
|
|
|
db.mark_gateways(gw.mac)
|
|
|
|
else:
|
|
|
|
bm = batman()
|
2014-01-30 22:21:15 +01:00
|
|
|
db.parse_vis_data(bm.vis_data(options['alfred']))
|
2013-11-12 00:28:11 +01:00
|
|
|
for gw in bm.gateway_list():
|
|
|
|
db.mark_gateways([gw['mac']])
|
2012-02-17 02:09:21 +01:00
|
|
|
|
|
|
|
if options['aliases']:
|
2013-02-02 00:44:46 +01:00
|
|
|
for aliases in options['aliases']:
|
|
|
|
db.import_aliases(json.load(open(aliases)))
|
2012-02-17 02:09:21 +01:00
|
|
|
|
2014-01-24 02:53:17 +01:00
|
|
|
if options['alfred']:
|
|
|
|
af = alfred()
|
|
|
|
db.import_aliases(af.aliases())
|
|
|
|
|
2013-12-29 04:15:40 +01:00
|
|
|
if options['obscure']:
|
|
|
|
db.obscure_clients()
|
|
|
|
|
2013-11-18 10:59:49 +01:00
|
|
|
scriptdir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
2012-05-11 18:39:26 +02:00
|
|
|
m = D3MapBuilder(db)
|
2012-02-17 02:09:21 +01:00
|
|
|
|
2014-01-01 18:59:33 +01:00
|
|
|
#Write nodes json
|
|
|
|
nodes_json = open(options['destination_directory'] + '/nodes.json.new','w')
|
2013-11-18 10:58:12 +01:00
|
|
|
nodes_json.write(m.build())
|
|
|
|
nodes_json.close()
|
2014-01-01 18:59:33 +01:00
|
|
|
|
|
|
|
#Move to destination
|
|
|
|
os.rename(options['destination_directory'] + '/nodes.json.new',options['destination_directory'] + '/nodes.json')
|
2014-02-11 11:36:05 +01:00
|
|
|
|
|
|
|
rrd = rrd(scriptdir + "/nodedb/", options['destination_directory'] + "/nodes")
|
|
|
|
rrd.update_database(db)
|
|
|
|
rrd.update_images()
|