Use tempfiles when updating JSON
This commit is contained in:
parent
b343748fe8
commit
209271cbf7
15
backend.py
15
backend.py
|
@ -27,8 +27,13 @@ def main(params):
|
|||
os.makedirs(params['dest_dir'], exist_ok=True)
|
||||
|
||||
nodes_fn = os.path.join(params['dest_dir'], 'nodes.json')
|
||||
tmp_nodes_fn = os.path.join(params['dest_dir'], 'nodes.json.tmp')
|
||||
|
||||
graph_fn = os.path.join(params['dest_dir'], 'graph.json')
|
||||
tmp_graph_fn = os.path.join(params['dest_dir'], 'graph.json.tmp')
|
||||
|
||||
nodelist_fn = os.path.join(params['dest_dir'], 'nodelist.json')
|
||||
tmp_nodelist_fn = os.path.join(params['dest_dir'], 'nodelist.json.tmp')
|
||||
|
||||
now = datetime.utcnow().replace(microsecond=0)
|
||||
|
||||
|
@ -137,18 +142,22 @@ def main(params):
|
|||
batadv_graph = graph.to_undirected(batadv_graph)
|
||||
|
||||
# write processed data to dest dir
|
||||
with open(nodes_fn, 'w') as f:
|
||||
with open(tmp_nodes_fn, 'w') as f:
|
||||
json.dump(nodedb, f)
|
||||
|
||||
graph_out = {'batadv': json_graph.node_link_data(batadv_graph),
|
||||
'version': GRAPH_VERSION}
|
||||
|
||||
with open(graph_fn, 'w') as f:
|
||||
with open(tmp_graph_fn, 'w') as f:
|
||||
json.dump(graph_out, f)
|
||||
|
||||
with open(nodelist_fn, 'w') as f:
|
||||
with open(tmp_nodelist_fn, 'w') as f:
|
||||
json.dump(export_nodelist(now, nodedb), f)
|
||||
|
||||
os.rename(tmp_nodes_fn, nodes_fn)
|
||||
os.rename(tmp_graph_fn, graph_fn)
|
||||
os.rename(tmp_nodelist_fn, nodelist_fn)
|
||||
|
||||
# optional rrd graphs (trigger with --rrd)
|
||||
if params['rrd']:
|
||||
script_directory = os.path.dirname(os.path.realpath(__file__))
|
||||
|
|
2
mkmap.sh
2
mkmap.sh
|
@ -3,4 +3,4 @@ FFMAPPATH='/opt/ffmap-backend/'
|
|||
PEERS="/etc/fastd/ffhh-mesh-vpn/peers"
|
||||
|
||||
python2 $FFMAPPATH/generate_aliases.py $PEERS > $FFMAPPATH/aliases.json
|
||||
python3 $FFMAPPATH/backend.py -d /var/www/meshviewer/ --aliases $FFMAPPATH/aliases.json $FFMAPPATH/gateway.json -m bat0:/var/run/alfred.sock -p 30 --vpn de:ad:be:ff:01:01 --vpn de:ad:be:ff:05:05 --vpn de:ad:be:ff:05:06 --vpn de:ad:be:ff:03:03 --vpn de:ad:be:ff:22:22 --vpn de:ad:be:ff:22:23 --vpn de:ad:be:ff:88:88 --vpn de:ad:be:ff:88:89 --vpn de:ad:bf:ff:88:88 --vpn de:ad:bf:ff:22:22 --vpn de:ad:bf:ff:03:03 --vpn de:ad:bf:ff:05:05 --vpn de:ad:bf:ff:01:01
|
||||
python3 $FFMAPPATH/backend.py -d /var/www/meshviewer/ --aliases $FFMAPPATH/aliases.json $FFMAPPATH/gateway.json -m bat0:/var/run/alfred.sock -p 30 --vpn de:ad:be:ff:01:01 --vpn de:ad:be:ff:05:05 --vpn de:ad:be:ff:05:06 --vpn de:ad:be:ff:03:03 --vpn de:ad:be:ff:22:22 --vpn de:ad:be:ff:22:23 --vpn de:ad:be:ff:88:88 --vpn de:ad:be:ff:88:89 --vpn de:ad:bf:ff:88:88 --vpn de:ad:bf:ff:22:22 --vpn de:ad:bf:ff:03:03 --vpn de:ad:bf:ff:05:05 --vpn de:ad:bf:ff:01:01 --vpn de:ad:be:fc:03:03 --vpn 00:16:3e:53:75:0d --vpn de:ad:be:fc:05:05 --vpn de:ad:be:fc:01:01 --vpn de:ad:be:ef:03:03 --vpn de:ad:be:ef:01:01 --vpn de:ad:be:ef:05:05
|
||||
|
|
Loading…
Reference in a new issue