server/schemaserial.py
changeset 9891 3386fd89c914
parent 9503 562cef272a35
child 9956 19a683a0047c
equal deleted inserted replaced
9875:d4f6f4c77e9c 9891:3386fd89c914
   307 
   307 
   308 def serialize_schema(cnx, 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     _title = '-> storing the schema in the database '
   313     if not quiet:
   313     print _title,
   314         _title = '-> storing the schema in the database '
       
   315         print _title,
       
   316     execute = cnx.execute
   314     execute = cnx.execute
   317     eschemas = schema.entities()
   315     eschemas = schema.entities()
   318     if not quiet:
   316     pb_size = (len(eschemas + schema.relations())
   319         pb_size = (len(eschemas + schema.relations())
   317                + len(CONSTRAINTS)
   320                    + len(CONSTRAINTS)
   318                + len([x for x in eschemas if x.specializes()]))
   321                    + len([x for x in eschemas if x.specializes()]))
   319     pb = ProgressBar(pb_size, title=_title)
   322         pb = ProgressBar(pb_size, title=_title)
       
   323     else:
       
   324         pb = None
       
   325     groupmap = group_mapping(cnx, interactive=False)
   320     groupmap = group_mapping(cnx, interactive=False)
   326     # serialize all entity types, assuring CWEType is serialized first for proper
   321     # serialize all entity types, assuring CWEType is serialized first for proper
   327     # is / is_instance_of insertion
   322     # is / is_instance_of insertion
   328     eschemas.remove(schema.eschema('CWEType'))
   323     eschemas.remove(schema.eschema('CWEType'))
   329     eschemas.insert(0, schema.eschema('CWEType'))
   324     eschemas.insert(0, schema.eschema('CWEType'))
   364     # serialize yams inheritance relationships
   359     # serialize yams inheritance relationships
   365     for rql, kwargs in specialize2rql(schema):
   360     for rql, kwargs in specialize2rql(schema):
   366         execute(rql, kwargs, build_descr=False)
   361         execute(rql, kwargs, build_descr=False)
   367         if pb is not None:
   362         if pb is not None:
   368             pb.update()
   363             pb.update()
   369     if not quiet:
   364     print
   370         print
       
   371 
   365 
   372 
   366 
   373 # high level serialization functions
   367 # high level serialization functions
   374 
   368 
   375 def execschemarql(execute, schema, rqls):
   369 def execschemarql(execute, schema, rqls):