6 :organization: Logilab |
6 :organization: Logilab |
7 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
7 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
8 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
9 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
9 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
10 """ |
10 """ |
|
11 from __future__ import with_statement |
|
12 |
11 __docformat__ = "restructuredtext en" |
13 __docformat__ = "restructuredtext en" |
12 |
14 |
13 import sys |
15 import sys |
14 from os.path import join, exists |
16 from os.path import join, exists |
15 from glob import glob |
17 from glob import glob |
207 print '-> database for instance %s initialized.' % config.appid |
209 print '-> database for instance %s initialized.' % config.appid |
208 |
210 |
209 |
211 |
210 def initialize_schema(config, schema, mhandler, event='create'): |
212 def initialize_schema(config, schema, mhandler, event='create'): |
211 from cubicweb.server.schemaserial import serialize_schema |
213 from cubicweb.server.schemaserial import serialize_schema |
|
214 from cubicweb.server.session import hooks_control |
|
215 session = mhandler.session |
|
216 paths = [p for p in config.cubes_path() + [config.apphome] |
|
217 if exists(join(p, 'migration'))] |
212 # deactivate every hooks but those responsible to set metadata |
218 # deactivate every hooks but those responsible to set metadata |
213 # so, NO INTEGRITY CHECKS are done, to have quicker db creation |
219 # so, NO INTEGRITY CHECKS are done, to have quicker db creation |
214 oldmode = config.set_hooks_mode(config.DENY_ALL) |
220 with hooks_control(session, session.HOOKS_DENY_ALL, 'metadata'): |
215 changes = config.enable_hook_category('metadata') |
221 # execute cubicweb's pre<event> script |
216 paths = [p for p in config.cubes_path() + [config.apphome] |
222 mhandler.exec_event_script('pre%s' % event) |
217 if exists(join(p, 'migration'))] |
223 # execute cubes pre<event> script if any |
218 # execute cubicweb's pre<event> script |
224 for path in reversed(paths): |
219 mhandler.exec_event_script('pre%s' % event) |
225 mhandler.exec_event_script('pre%s' % event, path) |
220 # execute cubes pre<event> script if any |
226 # enter instance'schema into the database |
221 for path in reversed(paths): |
227 session.set_pool() |
222 mhandler.exec_event_script('pre%s' % event, path) |
228 serialize_schema(session, schema) |
223 # enter instance'schema into the database |
229 # execute cubicweb's post<event> script |
224 mhandler.session.set_pool() |
230 mhandler.exec_event_script('post%s' % event) |
225 serialize_schema(mhandler.session, schema) |
231 # execute cubes'post<event> script if any |
226 # execute cubicweb's post<event> script |
232 for path in reversed(paths): |
227 mhandler.exec_event_script('post%s' % event) |
233 mhandler.exec_event_script('post%s' % event, path) |
228 # execute cubes'post<event> script if any |
|
229 for path in reversed(paths): |
|
230 mhandler.exec_event_script('post%s' % event, path) |
|
231 # restore hooks config |
|
232 if changes: |
|
233 config.disable_hook_category(changes) |
|
234 config.set_hooks_mode(oldmode) |
|
235 |
234 |
236 |
235 |
237 # sqlite'stored procedures have to be registered at connection opening time |
236 # sqlite'stored procedures have to be registered at connection opening time |
238 from logilab.db import SQL_CONNECT_HOOKS |
237 from logilab.db import SQL_CONNECT_HOOKS |
239 |
238 |