server/__init__.py
changeset 9494 197b7a4ef544
parent 9460 a2a0bc984863
child 9511 241b1232ed7f
equal deleted inserted replaced
9493:852f5ac90cd9 9494:197b7a4ef544
   253         print failed
   253         print failed
   254         raise Exception('execution of the sql schema failed, you should check your schema')
   254         raise Exception('execution of the sql schema failed, you should check your schema')
   255     sqlcursor.close()
   255     sqlcursor.close()
   256     sqlcnx.commit()
   256     sqlcnx.commit()
   257     sqlcnx.close()
   257     sqlcnx.close()
   258     session = repo.internal_session()
   258     with repo.internal_cnx() as cnx:
   259     # insert entity representing the system source
   259         # insert entity representing the system source
   260     ssource = session.create_entity('CWSource', type=u'native', name=u'system')
   260         ssource = cnx.create_entity('CWSource', type=u'native', name=u'system')
   261     repo.system_source.eid = ssource.eid
   261         repo.system_source.eid = ssource.eid
   262     session.execute('SET X cw_source X WHERE X eid %(x)s', {'x': ssource.eid})
   262         cnx.execute('SET X cw_source X WHERE X eid %(x)s', {'x': ssource.eid})
   263     # insert base groups and default admin
   263         # insert base groups and default admin
   264     print '-> inserting default user and default groups.'
   264         print '-> inserting default user and default groups.'
   265     try:
   265         try:
   266         login = unicode(sourcescfg['admin']['login'])
   266             login = unicode(sourcescfg['admin']['login'])
   267         pwd = sourcescfg['admin']['password']
   267             pwd = sourcescfg['admin']['password']
   268     except KeyError:
   268         except KeyError:
   269         if interactive:
   269             if interactive:
   270             msg = 'enter login and password of the initial manager account'
   270                 msg = 'enter login and password of the initial manager account'
   271             login, pwd = manager_userpasswd(msg=msg, confirm=True)
   271                 login, pwd = manager_userpasswd(msg=msg, confirm=True)
   272         else:
   272             else:
   273             login, pwd = unicode(source['db-user']), source['db-password']
   273                 login, pwd = unicode(source['db-user']), source['db-password']
   274     # sort for eid predicatability as expected in some server tests
   274         # sort for eid predicatability as expected in some server tests
   275     for group in sorted(BASE_GROUPS):
   275         for group in sorted(BASE_GROUPS):
   276         session.create_entity('CWGroup', name=unicode(group))
   276             cnx.create_entity('CWGroup', name=unicode(group))
   277     admin = create_user(session, login, pwd, 'managers')
   277         admin = create_user(cnx, login, pwd, 'managers')
   278     session.execute('SET X owned_by U WHERE X is IN (CWGroup,CWSource), U eid %(u)s',
   278         cnx.execute('SET X owned_by U WHERE X is IN (CWGroup,CWSource), U eid %(u)s',
   279                     {'u': admin.eid})
   279                         {'u': admin.eid})
   280     session.commit()
   280         cnx.commit()
   281     session.close()
       
   282     repo.shutdown()
   281     repo.shutdown()
   283     # reloging using the admin user
   282     # reloging using the admin user
   284     config._cubes = None # avoid assertion error
   283     config._cubes = None # avoid assertion error
   285     repo, cnx = in_memory_repo_cnx(config, login, password=pwd)
   284     repo, cnx = in_memory_repo_cnx(config, login, password=pwd)
   286     repo.system_source.eid = ssource.eid # redo this manually
   285     repo.system_source.eid = ssource.eid # redo this manually