misc/scripts/detect_cycle.py
author patwat
Wed, 08 Feb 2012 14:32:35 +0100
branchstable
changeset 8200 182d47d87a5c
parent 6198 f8dea560703f
child 10589 7c23b7de2b8d
permissions -rw-r--r--
[windows service] Copied the 3 lines from etwist/twctl into etwist/service in order to also clean the cache in Windows service mode. Could be factorised with etwist/server.run


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)