243 failed = sqlexec(failed, execute, cnx=sqlcnx, |
244 failed = sqlexec(failed, execute, cnx=sqlcnx, |
244 pbtitle='-> dropping tables (second pass)') |
245 pbtitle='-> dropping tables (second pass)') |
245 remainings = filter(drop_filter, helper.list_tables(sqlcursor)) |
246 remainings = filter(drop_filter, helper.list_tables(sqlcursor)) |
246 assert not remainings, 'Remaining tables: %s' % ', '.join(remainings) |
247 assert not remainings, 'Remaining tables: %s' % ', '.join(remainings) |
247 _title = '-> creating tables ' |
248 _title = '-> creating tables ' |
248 print _title, |
249 print(_title, end=' ') |
249 # schema entities and relations tables |
250 # schema entities and relations tables |
250 # can't skip entities table even if system source doesn't support them, |
251 # can't skip entities table even if system source doesn't support them, |
251 # they are used sometimes by generated sql. Keeping them empty is much |
252 # they are used sometimes by generated sql. Keeping them empty is much |
252 # simpler than fixing this... |
253 # simpler than fixing this... |
253 schemasql = sqlschema(schema, driver) |
254 schemasql = sqlschema(schema, driver) |
254 #skip_entities=[str(e) for e in schema.entities() |
255 #skip_entities=[str(e) for e in schema.entities() |
255 # if not repo.system_source.support_entity(str(e))]) |
256 # if not repo.system_source.support_entity(str(e))]) |
256 failed = sqlexec(schemasql, execute, pbtitle=_title, delimiter=';;') |
257 failed = sqlexec(schemasql, execute, pbtitle=_title, delimiter=';;') |
257 if failed: |
258 if failed: |
258 print 'The following SQL statements failed. You should check your schema.' |
259 print('The following SQL statements failed. You should check your schema.') |
259 print failed |
260 print(failed) |
260 raise Exception('execution of the sql schema failed, you should check your schema') |
261 raise Exception('execution of the sql schema failed, you should check your schema') |
261 sqlcursor.close() |
262 sqlcursor.close() |
262 sqlcnx.commit() |
263 sqlcnx.commit() |
263 sqlcnx.close() |
264 sqlcnx.close() |
264 with repo.internal_cnx() as cnx: |
265 with repo.internal_cnx() as cnx: |
265 # insert entity representing the system source |
266 # insert entity representing the system source |
266 ssource = cnx.create_entity('CWSource', type=u'native', name=u'system') |
267 ssource = cnx.create_entity('CWSource', type=u'native', name=u'system') |
267 repo.system_source.eid = ssource.eid |
268 repo.system_source.eid = ssource.eid |
268 cnx.execute('SET X cw_source X WHERE X eid %(x)s', {'x': ssource.eid}) |
269 cnx.execute('SET X cw_source X WHERE X eid %(x)s', {'x': ssource.eid}) |
269 # insert base groups and default admin |
270 # insert base groups and default admin |
270 print '-> inserting default user and default groups.' |
271 print('-> inserting default user and default groups.') |
271 try: |
272 try: |
272 login = unicode(sourcescfg['admin']['login']) |
273 login = unicode(sourcescfg['admin']['login']) |
273 pwd = sourcescfg['admin']['password'] |
274 pwd = sourcescfg['admin']['password'] |
274 except KeyError: |
275 except KeyError: |
275 if interactive: |
276 if interactive: |
308 config.creating = False |
309 config.creating = False |
309 config.consider_user_state = True |
310 config.consider_user_state = True |
310 # (drop instance attribute to get back to class attribute) |
311 # (drop instance attribute to get back to class attribute) |
311 del config.cubicweb_appobject_path |
312 del config.cubicweb_appobject_path |
312 del config.cube_appobject_path |
313 del config.cube_appobject_path |
313 print '-> database for instance %s initialized.' % config.appid |
314 print('-> database for instance %s initialized.' % config.appid) |
314 |
315 |
315 |
316 |
316 def initialize_schema(config, schema, mhandler, event='create'): |
317 def initialize_schema(config, schema, mhandler, event='create'): |
317 from cubicweb.server.schemaserial import serialize_schema |
318 from cubicweb.server.schemaserial import serialize_schema |
318 cnx = mhandler.cnx |
319 cnx = mhandler.cnx |