# HG changeset patch # User Sylvain Thénault # Date 1258650124 -3600 # Node ID addc715f4fcdf35ac88e28545e4cd127be469376 # Parent a192bc3c13b7c773ed433f82d557cf62e083c0ff backported from confman diff -r a192bc3c13b7 -r addc715f4fcd 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.