From 53d8f4bcf2e7c916e88db215b1df542a477a40d2 Mon Sep 17 00:00:00 2001 From: Daniel Ehlers Date: Sun, 29 Dec 2013 20:20:33 +0100 Subject: [PATCH 1/2] Fix exception handling and remove debug output --- nodedb.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/nodedb.py b/nodedb.py index 3812379..8685c81 100644 --- a/nodedb.py +++ b/nodedb.py @@ -34,14 +34,14 @@ class NodeDB: if mac.lower() in node.macs: return node - raise + raise KeyError def maybe_node_by_id(self, mac): for node in self._nodes: if mac.lower() == node.id: return node - raise + raise KeyError def parse_vis_data(self,vis_data): for x in vis_data: @@ -221,7 +221,6 @@ class NodeDB: if node.flags['client']: node.macs = set() clientIds[node.id] = None - sys.stderr.write("client:" + node.id) for link in self._links: ids = link.source.interface @@ -241,7 +240,6 @@ class NodeDB: globalIdCounter += 1 elif ids in clientIds: - sys.stderr.write("passed ids") newId = generateId(idt) clientIds[ids] = newId ids = newId @@ -250,7 +248,6 @@ class NodeDB: node_source.id = ids; elif idt in clientIds: - sys.stderr.write("passed idt") newId = generateId(ids,nodeCounters) clientIds[idt] = newId idt = newId @@ -261,7 +258,7 @@ class NodeDB: link.id = ids + "-" + idt except: - raise + pass # extends node id by incremented node counter def generateId(nodeId,nodeCounters): From 33d7b3aefc9622bba732268ea65440e7cc444894 Mon Sep 17 00:00:00 2001 From: Daniel Ehlers Date: Wed, 1 Jan 2014 18:59:33 +0100 Subject: [PATCH 2/2] Write new file to a temporary and move it afterwards. --- bat2nodes.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bat2nodes.py b/bat2nodes.py index 8204ce7..af1f10f 100755 --- a/bat2nodes.py +++ b/bat2nodes.py @@ -67,6 +67,10 @@ rrd.update_images() m = D3MapBuilder(db) -nodes_json = open(options['destination_directory'] + '/nodes.json','w') +#Write nodes json +nodes_json = open(options['destination_directory'] + '/nodes.json.new','w') nodes_json.write(m.build()) nodes_json.close() + +#Move to destination +os.rename(options['destination_directory'] + '/nodes.json.new',options['destination_directory'] + '/nodes.json')