author | Rémi Cardona <remi.cardona@logilab.fr> |
Wed, 13 May 2015 17:12:40 +0200 | |
changeset 10421 | 9bbb35f52d4b |
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) |