[ms] script to drop external entities from an external source
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 25 Oct 2010 17:15:54 +0200
changeset 6636 dbc9cce53c11
parent 6635 4e560631f36d
child 6637 6bbfc628555b
[ms] script to drop external entities from an external source
misc/scripts/drop_external_entities.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/scripts/drop_external_entities.py	Mon Oct 25 17:15:54 2010 +0200
@@ -0,0 +1,23 @@
+from cubicweb import UnknownEid
+source, = __args__
+
+sql("DELETE FROM entities WHERE type='Int'")
+
+ecnx = session.pool.connection(source)
+for e in rql('Any X WHERE X cw_source S, S name %(name)s', {'name': source}).entities():
+    meta = e.cw_metainformation()
+    assert meta['source']['uri'] == source
+    try:
+        suri = ecnx.describe(meta['extid'])[1]
+    except UnknownEid:
+        print 'cant describe', e.__regid__, e.eid, meta
+        continue
+    if suri != 'system':
+        try:
+            print 'deleting', e.__regid__, e.eid, suri, e.dc_title().encode('utf8')
+            repo.delete_info(session, e, suri, meta['extid'], scleanup=True)
+        except UnknownEid:
+            print '  cant delete', e.__regid__, e.eid, meta
+
+
+commit()