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