misc/migration/3.10.9_Any.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 08 Mar 2011 16:00:25 +0100
branchstable
changeset 7050 3f2857704444
parent 7034 1ac9715876e3
child 7104 62c880e5d980
permissions -rw-r--r--
[3.10.9 migration] don't display progress bar if stdout is not a tty
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7026
2c65dd2cbfff [migration] missing future import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6955
diff changeset
     1
from __future__ import with_statement
7050
3f2857704444 [3.10.9 migration] don't display progress bar if stdout is not a tty
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7034
diff changeset
     2
import sys
7032
b712477ae286 [config] fix option group clash causing anonymous user configuration to end in the MAIN section instead of the WEB section if cubicweb-dev is installed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7026
diff changeset
     3
7034
1ac9715876e3 [migration] cleanup corrupted database, pb noticed on several instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7032
diff changeset
     4
# fix some corrupted entities noticed on several instances
1ac9715876e3 [migration] cleanup corrupted database, pb noticed on several instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7032
diff changeset
     5
rql('DELETE CWConstraint X WHERE NOT E constrained_by X')
1ac9715876e3 [migration] cleanup corrupted database, pb noticed on several instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7032
diff changeset
     6
rql('SET X is_instance_of Y WHERE X is Y, NOT X is_instance_of Y')
1ac9715876e3 [migration] cleanup corrupted database, pb noticed on several instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7032
diff changeset
     7
commit()
1ac9715876e3 [migration] cleanup corrupted database, pb noticed on several instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7032
diff changeset
     8
6955
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 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
    10
    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
    11
    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
    12
    rset = rql('Any X, XC WHERE X cwuri XC, X cwuri ~= "%/eid/%"')
7050
3f2857704444 [3.10.9 migration] don't display progress bar if stdout is not a tty
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7034
diff changeset
    13
    if sys.stdout.isatty():
3f2857704444 [3.10.9 migration] don't display progress bar if stdout is not a tty
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7034
diff changeset
    14
        pb = ProgressBar(nbops=rset.rowcount, size=70)
3f2857704444 [3.10.9 migration] don't display progress bar if stdout is not a tty
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7034
diff changeset
    15
    else:
3f2857704444 [3.10.9 migration] don't display progress bar if stdout is not a tty
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7034
diff changeset
    16
        pb = None
6955
a6c32edabc8d [entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
    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
    18
        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
    19
            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
    20
            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
    21
                commit(ask_confirm=False)
7050
3f2857704444 [3.10.9 migration] don't display progress bar if stdout is not a tty
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7034
diff changeset
    22
            if pb is not None:
3f2857704444 [3.10.9 migration] don't display progress bar if stdout is not a tty
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7034
diff changeset
    23
                pb.update()
6955
a6c32edabc8d [entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
    commit(ask_confirm=False)
7032
b712477ae286 [config] fix option group clash causing anonymous user configuration to end in the MAIN section instead of the WEB section if cubicweb-dev is installed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7026
diff changeset
    25
b712477ae286 [config] fix option group clash causing anonymous user configuration to end in the MAIN section instead of the WEB section if cubicweb-dev is installed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7026
diff changeset
    26
try:
b712477ae286 [config] fix option group clash causing anonymous user configuration to end in the MAIN section instead of the WEB section if cubicweb-dev is installed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7026
diff changeset
    27
    from cubicweb import devtools
b712477ae286 [config] fix option group clash causing anonymous user configuration to end in the MAIN section instead of the WEB section if cubicweb-dev is installed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7026
diff changeset
    28
    option_group_changed('anonymous-user', 'main', 'web')
b712477ae286 [config] fix option group clash causing anonymous user configuration to end in the MAIN section instead of the WEB section if cubicweb-dev is installed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7026
diff changeset
    29
    option_group_changed('anonymous-password', 'main', 'web')
b712477ae286 [config] fix option group clash causing anonymous user configuration to end in the MAIN section instead of the WEB section if cubicweb-dev is installed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7026
diff changeset
    30
except ImportError:
b712477ae286 [config] fix option group clash causing anonymous user configuration to end in the MAIN section instead of the WEB section if cubicweb-dev is installed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7026
diff changeset
    31
    # cubicweb-dev unavailable, nothing needed
b712477ae286 [config] fix option group clash causing anonymous user configuration to end in the MAIN section instead of the WEB section if cubicweb-dev is installed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7026
diff changeset
    32
    pass