misc/scripts/drop_external_entities.py
author Julien Jehannet <julien.jehannet@logilab.fr>
Fri, 28 Jan 2011 16:08:40 +0100
branchstable
changeset 6919 8fd6921f3e7c
parent 6636 dbc9cce53c11
child 7398 26695dd703d8
permissions -rw-r--r--
[selectors] modify workflow selectors: is_in_state, on_transition - factorize `is_on_state` selector - add new `on_transition` selector Especially useful to match pending transitions to enable notifications when your workflow allows several transition to the same states. Note that if workflow `change_state` adapter method is used, this selector will not be triggered. In debug mode: These both selectors will check against the entity current workflow if expected values given in selector argument are valid. ValueError exception will be raised for unmatching state/transition names against the current workflow (generic etype workflow). (check against custom workflow is not implemented)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6636
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
from cubicweb import UnknownEid
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
source, = __args__
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
sql("DELETE FROM entities WHERE type='Int'")
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
ecnx = session.pool.connection(source)
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
for e in rql('Any X WHERE X cw_source S, S name %(name)s', {'name': source}).entities():
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
    meta = e.cw_metainformation()
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
    assert meta['source']['uri'] == source
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
    try:
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
        suri = ecnx.describe(meta['extid'])[1]
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
    except UnknownEid:
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
        print 'cant describe', e.__regid__, e.eid, meta
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    14
        continue
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    15
    if suri != 'system':
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    16
        try:
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
            print 'deleting', e.__regid__, e.eid, suri, e.dc_title().encode('utf8')
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
            repo.delete_info(session, e, suri, meta['extid'], scleanup=True)
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
        except UnknownEid:
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
            print '  cant delete', e.__regid__, e.eid, meta
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
dbc9cce53c11 [ms] script to drop external entities from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
commit()