misc/scripts/detect_cycle.py
author Rémi Cardona <remi.cardona@logilab.fr>
Fri, 23 May 2014 18:17:44 +0200
changeset 9818 e3d2012adcd0
parent 6198 f8dea560703f
child 10589 7c23b7de2b8d
permissions -rw-r--r--
[request] Ensure base_url() always has a trailing '/' (closes #3955093) Just as an example, cubicweb.ajax.js is clearly written under the assumption that BASE_URL/baseuri() - which simply contains req.base_url() - has a trailing /.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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)