author | Julien Cristau <julien.cristau@logilab.fr> |
Tue, 16 Feb 2016 10:52:38 +0100 | |
changeset 11114 | 468b91aabd9d |
parent 6198 | f8dea560703f |
child 10589 | 7c23b7de2b8d |
permissions | -rw-r--r-- |
6198
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
1 |
|
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
2 |
try: |
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
rtype, = __args__ |
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
4 |
except ValueError: |
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
print 'USAGE: cubicweb-ctl shell <instance> detect_cycle.py -- <relation type>' |
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
6 |
print |
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
7 |
|
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
graph = {} |
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
9 |
for fromeid, toeid in rql('Any X,Y WHERE X %s Y' % rtype): |
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
10 |
graph.setdefault(fromeid, []).append(toeid) |
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
11 |
|
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
12 |
from logilab.common.graph import get_cycles |
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
13 |
|
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
14 |
for cycle in get_cycles(graph): |
f8dea560703f
add a small c-c shell script to detect cycle for a given relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
15 |
print 'cycle', '->'.join(str(n) for n in cycle) |