misc/migration/3.10.0_Any.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 07 Jul 2011 18:20:23 +0200
changeset 7632 3c9dfc6e820b
parent 7508 48398bf8a33a
child 8483 4ba11607d84a
permissions -rw-r--r--
[book] fix some rest/sphinx errors
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
6945
28bf94d062a9 [sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6546
diff changeset
     8
    repo.sources_by_uri[uri] = repo.get_source(cfg['adapter'], uri, cfg.copy())
6427
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()
6546
31586c7b63f6 [3.10 migration] must skip None values
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6488
diff changeset
    28
                        if key != 'adapter' and value is not None)
6427
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, '
7508
48398bf8a33a fix 3.10 cwproperties migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6945
diff changeset
    35
             'X pkey ~= "boxes.%" OR '
48398bf8a33a fix 3.10 cwproperties migration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6945
diff changeset
    36
             'X pkey ~= "contentnavigation.%"').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