summaryrefslogtreecommitdiff
path: root/graph.py
diff options
context:
space:
mode:
authorEmile Anclin <emile.anclin@logilab.fr>2009-04-09 17:40:02 +0200
committerEmile Anclin <emile.anclin@logilab.fr>2009-04-09 17:40:02 +0200
commit927b5f276b0e9096dcba3d5848408add53783158 (patch)
tree0b61ae9b5e26511821373eae63c9adfd8e93e506 /graph.py
parent772779bf41d22b056120ff1d9fd6fe56bcabfabc (diff)
downloadlogilab-common-927b5f276b0e9096dcba3d5848408add53783158.tar.gz
fix typos; little code _get_cycle simplification
Diffstat (limited to 'graph.py')
-rw-r--r--graph.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/graph.py b/graph.py
index c6469ef..e4f3c65 100644
--- a/graph.py
+++ b/graph.py
@@ -99,17 +99,15 @@ class DotBackend:
self.lines.append(line)
def emit_edge(self, name1, name2, **props):
- """Emits edge from <name1> to <name2>.
-
- Authorized props: see http://www.graphviz.org/doc/info/attrs.html
- """
+ """emit an edge from <name1> to <name2>."""
+ #edge properties: see http://www.graphviz.org/doc/info/attrs.html
attrs = ['%s="%s"' % (prop, value) for prop, value in props.items()]
n_from, n_to = normalize_node_id(name1), normalize_node_id(name2)
self.emit('%s -> %s [%s];' % (n_from, n_to, ", ".join(attrs)) )
def emit_node(self, name, **props):
- """Authorized props: see http://www.graphviz.org/doc/info/attrs.html
- """
+ """emit a node with given properties"""
+ # node properties: see http://www.graphviz.org/doc/info/attrs.html
attrs = ['%s="%s"' % (prop, value) for prop, value in props.items()]
self.emit('%s [%s];' % (normalize_node_id(name), ", ".join(attrs)))
@@ -119,12 +117,12 @@ def normalize_node_id(nid):
class GraphGenerator:
def __init__(self, backend):
- # the backend is responsible to output the graph is a particular format
+ # the backend is responsible to output the graph in a particular format
self.backend = backend
def generate(self, visitor, propshdlr, outputfile=None):
# the visitor
- # the properties handler is used to get nodes and edges properties
+ # the property handler is used to get node and edge properties
# according to the graph and to the backend
self.propshdlr = propshdlr
for nodeid, node in visitor.nodes():
@@ -138,7 +136,7 @@ class GraphGenerator:
def get_cycles(graph_dict, vertices=None):
- '''given a dictionnary representing an ordered graph (i.e. key are vertices
+ '''given a dictionary representing an ordered graph (i.e. key are vertices
and values is a list of destination vertices representing edges), return a
list of detected cycles
'''
@@ -155,8 +153,7 @@ def _get_cycles(graph_dict, vertice=None, path=None, result=None):
"""recursive function doing the real work for get_cycles"""
if vertice in path:
cycle = [vertice]
- for i in range(len(path)-1, 0, -1):
- node = path[i]
+ for node in path[::-1]:
if node == vertice:
break
cycle.insert(0, node)