1 from six import text_type |
|
2 |
|
3 from cubicweb.server.session import hooks_control |
|
4 |
|
5 for uri, cfg in config.read_sources_file().items(): |
|
6 if uri in ('system', 'admin'): |
|
7 continue |
|
8 repo.sources_by_uri[uri] = repo.get_source(cfg['adapter'], uri, cfg.copy()) |
|
9 |
|
10 add_entity_type('CWSource') |
|
11 add_relation_definition('CWSource', 'cw_source', 'CWSource') |
|
12 add_entity_type('CWSourceHostConfig') |
|
13 |
|
14 with hooks_control(session, session.HOOKS_ALLOW_ALL, 'cw.sources'): |
|
15 create_entity('CWSource', type=u'native', name=u'system') |
|
16 commit() |
|
17 |
|
18 sql('INSERT INTO cw_source_relation(eid_from,eid_to) ' |
|
19 'SELECT e.eid,s.cw_eid FROM entities as e, cw_CWSource as s ' |
|
20 'WHERE s.cw_name=e.type') |
|
21 commit() |
|
22 |
|
23 for uri, cfg in config.read_sources_file().items(): |
|
24 if uri in ('system', 'admin'): |
|
25 continue |
|
26 repo.sources_by_uri.pop(uri) |
|
27 config = u'\n'.join('%s=%s' % (key, value) for key, value in cfg.items() |
|
28 if key != 'adapter' and value is not None) |
|
29 create_entity('CWSource', name=text_type(uri), type=text_type(cfg['adapter']), |
|
30 config=config) |
|
31 commit() |
|
32 |
|
33 # rename cwprops for boxes/contentnavigation |
|
34 for x in rql('Any X,XK WHERE X pkey XK, ' |
|
35 'X pkey ~= "boxes.%" OR ' |
|
36 'X pkey ~= "contentnavigation.%"').entities(): |
|
37 x.cw_set(pkey=u'ctxcomponents.' + x.pkey.split('.', 1)[1]) |
|