goa/dbinit.py
branchtls-sprint
changeset 1802 d628defebc17
parent 1398 5fe84a5f7035
child 1977 606923dff11b
equal deleted inserted replaced
1801:672acc730ce5 1802:d628defebc17
     1 """some utility functions for datastore initialization.
     1 """some utility functions for datastore initialization.
     2 
     2 
     3 :organization: Logilab
     3 :organization: Logilab
     4 :copyright: 2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     4 :copyright: 2008-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 """
     6 """
     7 __docformat__ = "restructuredtext en"
     7 __docformat__ = "restructuredtext en"
     8 
     8 
     9 from google.appengine.api.datastore import Key, Entity, Put, Get, Query
     9 from google.appengine.api.datastore import Key, Entity, Put, Get, Query
    70         if rschema == 'identity':
    70         if rschema == 'identity':
    71             continue
    71             continue
    72         dsrelation = 'o_' + rschema.type
    72         dsrelation = 'o_' + rschema.type
    73         if not dsrelation in gaeentity:
    73         if not dsrelation in gaeentity:
    74             gaeentity[dsrelation] = None
    74             gaeentity[dsrelation] = None
    75     
    75 
    76 def fix_entities(schema):
    76 def fix_entities(schema):
    77     for etype in ('CWUser', 'CWGroup'):
    77     for etype in ('CWUser', 'CWGroup'):
    78         eschema = schema.eschema(etype)
    78         eschema = schema.eschema(etype)
    79         for gaeentity in Query(etype).Run():
    79         for gaeentity in Query(etype).Run():
    80             init_relations(gaeentity, eschema)
    80             init_relations(gaeentity, eschema)
    81             # XXX o_is on CWEType entity
    81             # XXX o_is on CWEType entity
    82             gaeentity['s_is'] = Key.from_path('CWEType', 'key_' + etype, parent=None)
    82             gaeentity['s_is'] = Key.from_path('CWEType', 'key_' + etype, parent=None)
    83             Put(gaeentity)
    83             Put(gaeentity)
    84     
    84 
    85 def init_persistent_schema(ssession, schema):
    85 def init_persistent_schema(ssession, schema):
    86     execute = ssession.unsafe_execute
    86     execute = ssession.unsafe_execute
    87     rql = ('INSERT CWEType X: X name %(name)s, X description %(descr)s,'
    87     rql = ('INSERT CWEType X: X name %(name)s, X description %(descr)s,'
    88            'X final FALSE, X meta %(meta)s')
    88            'X final FALSE, X meta %(meta)s')
    89     eschema = schema.eschema('CWEType')
    89     eschema = schema.eschema('CWEType')
   103              'v': unicode(config.cubicweb_version())})
   103              'v': unicode(config.cubicweb_version())})
   104     for cube in config.cubes():
   104     for cube in config.cubes():
   105         execute('INSERT CWProperty X: X pkey %(pk)s, X value%(v)s',
   105         execute('INSERT CWProperty X: X pkey %(pk)s, X value%(v)s',
   106                 {'pk': u'system.version.%s' % cube,
   106                 {'pk': u'system.version.%s' % cube,
   107                  'v': unicode(config.cube_version(cube))})
   107                  'v': unicode(config.cube_version(cube))})
   108