misc/scripts/detect_cycle.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 08 Apr 2011 09:02:55 +0200
branchstable
changeset 7200 81fd6e40a6a8
parent 6198 f8dea560703f
child 10589 7c23b7de2b8d
permissions -rw-r--r--
[entity creation] ensure this is a relation and not an attribute before moving things into pending_relations because value is a list Using a list for attributes may be used for later type specific casting (e.g. timeseries)


try:
    rtype, = __args__
except ValueError:
    print 'USAGE: cubicweb-ctl shell <instance> detect_cycle.py -- <relation type>'
    print

graph = {}
for fromeid, toeid in rql('Any X,Y WHERE X %s Y' % rtype):
    graph.setdefault(fromeid, []).append(toeid)

from logilab.common.graph import get_cycles

for cycle in get_cycles(graph):
    print 'cycle', '->'.join(str(n) for n in cycle)