misc/scripts/detect_cycle.py
author David Douard <david.douard@logilab.fr>
Tue, 19 Jul 2016 19:30:10 +0200
branch3.22
changeset 11438 828483a88825
parent 10589 7c23b7de2b8d
permissions -rw-r--r--
[webctl] set uid of file produced by gen-static-datadir (closes #11298794)

from __future__ import print_function

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))