changeset 11057 | 0b59724cb3f2 |
parent 10589 | 7c23b7de2b8d |
11052:058bb3dc685f | 11057:0b59724cb3f2 |
---|---|
1 from __future__ import print_function |
|
2 |
|
3 try: |
|
4 rtype, = __args__ |
|
5 except ValueError: |
|
6 print('USAGE: cubicweb-ctl shell <instance> detect_cycle.py -- <relation type>') |
|
7 print() |
|
8 |
|
9 graph = {} |
|
10 for fromeid, toeid in rql('Any X,Y WHERE X %s Y' % rtype): |
|
11 graph.setdefault(fromeid, []).append(toeid) |
|
12 |
|
13 from logilab.common.graph import get_cycles |
|
14 |
|
15 for cycle in get_cycles(graph): |
|
16 print('cycle', '->'.join(str(n) for n in cycle)) |