|
1 sync_schema_props_perms('cw_support', syncperms=False) |
|
2 sync_schema_props_perms('cw_dont_cross', syncperms=False) |
|
3 sync_schema_props_perms('cw_may_cross', syncperms=False) |
|
4 |
|
5 try: |
|
6 from cubicweb.server.sources.pyrorql import PyroRQLSource |
|
7 except ImportError: |
|
8 pass |
|
9 else: |
|
10 |
|
11 from os.path import join |
|
12 |
|
13 def load_mapping_file(source): |
|
14 mappingfile = source.config['mapping-file'] |
|
15 mappingfile = join(source.repo.config.apphome, mappingfile) |
|
16 mapping = {} |
|
17 execfile(mappingfile, mapping) |
|
18 for junk in ('__builtins__', '__doc__'): |
|
19 mapping.pop(junk, None) |
|
20 mapping.setdefault('support_relations', {}) |
|
21 mapping.setdefault('dont_cross_relations', set()) |
|
22 mapping.setdefault('cross_relations', set()) |
|
23 # do some basic checks of the mapping content |
|
24 assert 'support_entities' in mapping, \ |
|
25 'mapping file should at least define support_entities' |
|
26 assert isinstance(mapping['support_entities'], dict) |
|
27 assert isinstance(mapping['support_relations'], dict) |
|
28 assert isinstance(mapping['dont_cross_relations'], set) |
|
29 assert isinstance(mapping['cross_relations'], set) |
|
30 unknown = set(mapping) - set( ('support_entities', 'support_relations', |
|
31 'dont_cross_relations', 'cross_relations') ) |
|
32 assert not unknown, 'unknown mapping attribute(s): %s' % unknown |
|
33 # relations that are necessarily not crossed |
|
34 for rtype in ('is', 'is_instance_of', 'cw_source'): |
|
35 assert rtype not in mapping['dont_cross_relations'], \ |
|
36 '%s relation should not be in dont_cross_relations' % rtype |
|
37 assert rtype not in mapping['support_relations'], \ |
|
38 '%s relation should not be in support_relations' % rtype |
|
39 return mapping |
|
40 |
|
41 for source in repo.sources_by_uri.values(): |
|
42 if not isinstance(source, PyroRQLSource): |
|
43 continue |
|
44 mapping = load_mapping_file(source) |
|
45 print 'migrating map for', source |
|
46 for etype in mapping['support_entities']: # XXX write support |
|
47 rql('SET S cw_support ET WHERE ET name %(etype)s, ET is CWEType, S eid %(s)s', |
|
48 {'etype': etype, 's': source.eid}) |
|
49 for rtype in mapping['support_relations']: # XXX write support |
|
50 rql('SET S cw_support RT WHERE RT name %(rtype)s, RT is CWRType, S eid %(s)s', |
|
51 {'rtype': rtype, 's': source.eid}) |
|
52 for rtype in mapping['dont_cross_relations']: # XXX write support |
|
53 rql('SET S cw_dont_cross RT WHERE RT name %(rtype)s, S eid %(s)s', |
|
54 {'rtype': rtype, 's': source.eid}) |
|
55 for rtype in mapping['cross_relations']: # XXX write support |
|
56 rql('SET S cw_may_cross RT WHERE RT name %(rtype)s, S eid %(s)s', |
|
57 {'rtype': rtype, 's': source.eid}) |