49 print 'eid should be an integer' |
49 print 'eid should be an integer' |
50 continue |
50 continue |
51 return res |
51 return res |
52 |
52 |
53 # schema / perms deserialization ############################################## |
53 # schema / perms deserialization ############################################## |
|
54 |
54 def deserialize_schema(schema, session): |
55 def deserialize_schema(schema, session): |
55 """return a schema according to information stored in an rql database |
56 """return a schema according to information stored in an rql database |
56 as CWRType and CWEType entities |
57 as CWRType and CWEType entities |
57 """ |
58 """ |
58 repo = session.repo |
59 repo = session.repo |
213 if not quiet: |
214 if not quiet: |
214 _title = '-> storing the schema in the database ' |
215 _title = '-> storing the schema in the database ' |
215 print _title, |
216 print _title, |
216 execute = cursor.unsafe_execute |
217 execute = cursor.unsafe_execute |
217 eschemas = schema.entities() |
218 eschemas = schema.entities() |
218 aller = eschemas + schema.relations() |
|
219 if not quiet: |
219 if not quiet: |
220 pb_size = len(aller) + len(CONSTRAINTS) + len([x for x in eschemas if x.specializes()]) |
220 pb_size = (len(eschemas + schema.relations()) |
|
221 + len(CONSTRAINTS) |
|
222 + len([x for x in eschemas if x.specializes()])) |
221 pb = ProgressBar(pb_size, title=_title) |
223 pb = ProgressBar(pb_size, title=_title) |
222 else: |
224 else: |
223 pb = None |
225 pb = None |
224 # serialize all entity types, assuring CWEType is serialized first |
226 # serialize all entity types, assuring CWEType is serialized first |
|
227 groupmap = group_mapping(cursor) |
225 eschemas.remove(schema.eschema('CWEType')) |
228 eschemas.remove(schema.eschema('CWEType')) |
226 eschemas.insert(0, schema.eschema('CWEType')) |
229 eschemas.insert(0, schema.eschema('CWEType')) |
227 for eschema in eschemas: |
230 for eschema in eschemas: |
228 for rql, kwargs in eschema2rql(eschema, groupmap): |
231 for rql, kwargs in eschema2rql(eschema, groupmap): |
229 execute(rql, kwargs, build_descr=False) |
232 execute(rql, kwargs, build_descr=False) |
240 # skip virtual relations such as eid, has_text and identity |
243 # skip virtual relations such as eid, has_text and identity |
241 if rschema in VIRTUAL_RTYPES: |
244 if rschema in VIRTUAL_RTYPES: |
242 if pb is not None: |
245 if pb is not None: |
243 pb.update() |
246 pb.update() |
244 continue |
247 continue |
245 for rql, kwargs in erschema2rql(schema[ertype], groupmap): |
248 for rql, kwargs in rschema2rql(rschema, groupmap): |
246 execute(rql, kwargs, build_descr=False) |
249 execute(rql, kwargs, build_descr=False) |
247 if pb is not None: |
250 if pb is not None: |
248 pb.update() |
251 pb.update() |
249 for rql, kwargs in specialize2rql(schema): |
252 for rql, kwargs in specialize2rql(schema): |
250 assert execute(rql, kwargs, build_descr=False) |
253 execute(rql, kwargs, build_descr=False) |
251 if pb is not None: |
254 if pb is not None: |
252 pb.update() |
255 pb.update() |
253 if not quiet: |
256 if not quiet: |
254 print |
257 print |
255 |
258 |