Mercurial > hg > svgsitemap
changeset 10:1329127709de
remove orphans in a unique function
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sun, 02 Jan 2011 11:43:27 -0800 |
parents | aa4eab6dc994 |
children | 1ff7b363e89e |
files | svgsitemap/middleware.py |
diffstat | 1 files changed, 11 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/svgsitemap/middleware.py Sun Jan 02 11:39:45 2011 -0800 +++ b/svgsitemap/middleware.py Sun Jan 02 11:43:27 2011 -0800 @@ -87,16 +87,13 @@ if self.exclude(edge[0], edge[1]): self.graph.remove_edge(edge[0], edge[1]) continue + count = int(edge.attr['label']) self.edges[(edge[0], edge[1])] = count if count > self.max: self.max = count - for node in self.graph.nodes(): - if not self.graph.neighbors(node) or self.exclude(node): - self.graph.remove_node(node) + self.remove_orphans() self.set_widths() - self.graph.write(self.file) - self.graph.draw(self.output, prog='neato') else: self.graph = AGraph(name=self.name, splines=False, directed=True) @@ -208,3 +205,12 @@ self.graph.write(self.file) if self.output: self.graph.draw(self.output, prog='neato') + + def remove_orphans(self): + flag = True + while flag: + flag = False + for node in self.graph.nodes(): + if not self.graph.neighbors(node) or self.exclude(node): + flag = True + self.graph.remove_node(node)