misc/migration/3.10.0_Any.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Sun, 17 Oct 2010 21:10:01 +0200
changeset 6527 2421875ab889
parent 6488 a512dd258ee8
child 6546 31586c7b63f6
permissions -rw-r--r--
[3.10] user changelog
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6488
a512dd258ee8 [migration] missing future import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
     1
from __future__ import with_statement
a512dd258ee8 [migration] missing future import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
     2
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
     3
from cubicweb.server.session import hooks_control
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
     4
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
     5
for uri, cfg in config.sources().items():
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
     6
    if uri in ('system', 'admin'):
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
     7
        continue
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
     8
    repo.sources_by_uri[uri] = repo.get_source(cfg['adapter'], uri, cfg)
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
     9
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    10
add_entity_type('CWSource')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    11
add_relation_definition('CWSource', 'cw_source', 'CWSource')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    12
add_entity_type('CWSourceHostConfig')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    13
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    14
with hooks_control(session, session.HOOKS_ALLOW_ALL, 'cw.sources'):
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    15
    create_entity('CWSource', type=u'native', name=u'system')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    16
commit()
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    17
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    18
sql('INSERT INTO cw_source_relation(eid_from,eid_to) '
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    19
    'SELECT e.eid,s.cw_eid FROM entities as e, cw_CWSource as s '
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    20
    'WHERE s.cw_name=e.type')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    21
commit()
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    22
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    23
for uri, cfg in config.sources().items():
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    24
    if uri in ('system', 'admin'):
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    25
        continue
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    26
    repo.sources_by_uri.pop(uri)
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    27
    config = u'\n'.join('%s=%s' % (key, value) for key, value in cfg.items()
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    28
                        if key != 'adapter')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    29
    create_entity('CWSource', name=unicode(uri), type=unicode(cfg['adapter']),
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    30
                  config=config)
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    31
commit()
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6378
diff changeset
    32
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
# rename cwprops for boxes/contentnavigation
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
for x in rql('Any X,XK WHERE X pkey XK, '
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    35
             'X pkey ~= "boxes.%s" OR '
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    36
             'X pkey ~= "contentnavigation.%s"').entities():
6378
5a86a0c147bd [3.10 migration] fix migration of cwproperties related to components/boxes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
    37
    x.set_attributes(pkey=u'ctxcomponents.' + x.pkey.split('.', 1)[1])
5a86a0c147bd [3.10 migration] fix migration of cwproperties related to components/boxes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
    38