31 from cubicweb.schema import (KNOWN_RPROPERTIES, CONSTRAINTS, ETYPE_NAME_MAP, |
31 from cubicweb.schema import (KNOWN_RPROPERTIES, CONSTRAINTS, ETYPE_NAME_MAP, |
32 VIRTUAL_RTYPES) |
32 VIRTUAL_RTYPES) |
33 from cubicweb.server import sqlutils |
33 from cubicweb.server import sqlutils |
34 |
34 |
35 |
35 |
36 def group_mapping(cursor, interactive=True): |
36 def group_mapping(cnx, interactive=True): |
37 """create a group mapping from an rql cursor |
37 """create a group mapping from an rql cursor |
38 |
38 |
39 A group mapping has standard group names as key (managers, owners at least) |
39 A group mapping has standard group names as key (managers, owners at least) |
40 and the actual CWGroup entity's eid as associated value. |
40 and the actual CWGroup entity's eid as associated value. |
41 In interactive mode (the default), missing groups'eid will be prompted |
41 In interactive mode (the default), missing groups'eid will be prompted |
42 from the user. |
42 from the user. |
43 """ |
43 """ |
44 res = {} |
44 res = {} |
45 for eid, name in cursor.execute('Any G, N WHERE G is CWGroup, G name N', |
45 for eid, name in cnx.execute('Any G, N WHERE G is CWGroup, G name N', |
46 build_descr=False): |
46 build_descr=False): |
47 res[name] = eid |
47 res[name] = eid |
48 if not interactive: |
48 if not interactive: |
49 return res |
49 return res |
50 missing = [g for g in ('owners', 'managers', 'users', 'guests') if not g in res] |
50 missing = [g for g in ('owners', 'managers', 'users', 'guests') if not g in res] |
303 for p in somethings) |
303 for p in somethings) |
304 |
304 |
305 |
305 |
306 # schema / perms serialization ################################################ |
306 # schema / perms serialization ################################################ |
307 |
307 |
308 def serialize_schema(cursor, schema): |
308 def serialize_schema(cnx, schema): |
309 """synchronize schema and permissions in the database according to |
309 """synchronize schema and permissions in the database according to |
310 current schema |
310 current schema |
311 """ |
311 """ |
312 quiet = os.environ.get('APYCOT_ROOT') |
312 quiet = os.environ.get('APYCOT_ROOT') |
313 if not quiet: |
313 if not quiet: |
314 _title = '-> storing the schema in the database ' |
314 _title = '-> storing the schema in the database ' |
315 print _title, |
315 print _title, |
316 execute = cursor.execute |
316 execute = cnx.execute |
317 eschemas = schema.entities() |
317 eschemas = schema.entities() |
318 if not quiet: |
318 if not quiet: |
319 pb_size = (len(eschemas + schema.relations()) |
319 pb_size = (len(eschemas + schema.relations()) |
320 + len(CONSTRAINTS) |
320 + len(CONSTRAINTS) |
321 + len([x for x in eschemas if x.specializes()])) |
321 + len([x for x in eschemas if x.specializes()])) |
322 pb = ProgressBar(pb_size, title=_title) |
322 pb = ProgressBar(pb_size, title=_title) |
323 else: |
323 else: |
324 pb = None |
324 pb = None |
325 groupmap = group_mapping(cursor, interactive=False) |
325 groupmap = group_mapping(cnx, interactive=False) |
326 # serialize all entity types, assuring CWEType is serialized first for proper |
326 # serialize all entity types, assuring CWEType is serialized first for proper |
327 # is / is_instance_of insertion |
327 # is / is_instance_of insertion |
328 eschemas.remove(schema.eschema('CWEType')) |
328 eschemas.remove(schema.eschema('CWEType')) |
329 eschemas.insert(0, schema.eschema('CWEType')) |
329 eschemas.insert(0, schema.eschema('CWEType')) |
330 for eschema in eschemas: |
330 for eschema in eschemas: |