misc/scripts/drop_external_entities.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 21 Jan 2013 18:01:25 +0100
changeset 8669 62213a34726e
parent 7884 35d2e2f4e10a
child 8900 010a59e12d89
permissions -rw-r--r--
[db-api/configuration] simplify db-api and configuration so that all the connection information is in the repository url, closes #2521848 eg no more specific option of pyro ns host, group, etc. This also fixes broken ZMQ sources. Changes: * dropped pyro-ns-host, pyro-instance-id, pyro-ns-group from client side config, in favor of repository-uri. No migration done, supposing there is **no web-only config** in the wild. Also stop discovering the connection method through the repo_method class attribute of the configuration, varying according to the configuration class. This is a first step on the way to a simpler configuration handling. Notice those pyro options are still available for repository only / all-in-one configurations as they are needed to configure the pyro server. * stop telling connection method using ConnectionProperties, this is so boring. Also, drop _cnxtype from Connection and cnxtype from Session. The former is replaced by a is_repo_in_memory property and the later is totaly useless. * deprecate in_memory_cnx which becomes useless, use _repo_connect instead
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
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6636
diff changeset
     6
ecnx = session.cnxset.connection(source)
6636
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')
7884
35d2e2f4e10a [repo] cleanup [_]delete_info prototype: extid argument isn't used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
    18
            repo.delete_info(session, e, suri, scleanup=e.eid)
6636
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()