author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 18 Feb 2011 17:11:00 +0100 | |
changeset 7023 | 50defc197448 |
parent 6955 | a6c32edabc8d |
child 7026 | 2c65dd2cbfff |
permissions | -rw-r--r-- |
6955
a6c32edabc8d
[entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
1 |
if confirm('fix existing cwuri?'): |
a6c32edabc8d
[entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
2 |
from logilab.common.shellutils import ProgressBar |
a6c32edabc8d
[entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
from cubicweb.server.session import hooks_control |
a6c32edabc8d
[entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
4 |
rset = rql('Any X, XC WHERE X cwuri XC, X cwuri ~= "%/eid/%"') |
a6c32edabc8d
[entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
pb = ProgressBar(nbops=rset.rowcount, size=70) |
a6c32edabc8d
[entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
6 |
with hooks_control(session, session.HOOKS_DENY_ALL, 'integrity'): |
a6c32edabc8d
[entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
7 |
for i, e in enumerate(rset.entities()): |
a6c32edabc8d
[entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
e.set_attributes(cwuri=e.cwuri.replace('/eid', '')) |
a6c32edabc8d
[entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
9 |
if i % 100: # commit every 100 entities to limit memory consumption |
a6c32edabc8d
[entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
10 |
commit(ask_confirm=False) |
a6c32edabc8d
[entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
11 |
pb.update() |
a6c32edabc8d
[entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
12 |
commit(ask_confirm=False) |