backported from confman stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 19 Nov 2009 18:02:04 +0100
branchstable
changeset 3882 addc715f4fcd
parent 3881 a192bc3c13b7
child 3883 b3b3bebdb406
backported from confman
utils.py
--- a/utils.py	Thu Nov 19 18:01:57 2009 +0100
+++ b/utils.py	Thu Nov 19 18:02:04 2009 +0100
@@ -148,6 +148,20 @@
     return dict1
 
 
+# use networkX instead ?
+# http://networkx.lanl.gov/reference/algorithms.traversal.html#module-networkx.algorithms.traversal.astar
+def transitive_closure_of(entity, relname, _seen=None):
+    if _seen is None:
+        _seen = set()
+    _seen.add(entity.eid)
+    yield entity
+    for child in getattr(entity, relname):
+        if child.eid in _seen:
+            continue
+        for subchild in transitive_closure_of(child, relname, _seen):
+            yield subchild
+
+
 class SizeConstrainedList(list):
     """simple list that makes sure the list does not get bigger
     than a given size.