10 """ |
10 """ |
11 __docformat__ = "restructuredtext en" |
11 __docformat__ = "restructuredtext en" |
12 |
12 |
13 import sys |
13 import sys |
14 from os.path import join, exists |
14 from os.path import join, exists |
|
15 from glob import glob |
15 |
16 |
16 from logilab.common.modutils import LazyObject |
17 from logilab.common.modutils import LazyObject |
17 from logilab.common.textutils import splitstrip |
18 from logilab.common.textutils import splitstrip |
|
19 |
|
20 from yams import BASE_GROUPS |
|
21 |
|
22 from cubicweb import CW_SOFTWARE_ROOT |
18 |
23 |
19 # server-side debugging ######################################################### |
24 # server-side debugging ######################################################### |
20 |
25 |
21 # server debugging flags. They may be combined using binary operators. |
26 # server debugging flags. They may be combined using binary operators. |
22 DBG_NONE = 0 # no debug information |
27 DBG_NONE = 0 # no debug information |
90 def init_repository(config, interactive=True, drop=False, vreg=None): |
95 def init_repository(config, interactive=True, drop=False, vreg=None): |
91 """initialise a repository database by creating tables add filling them |
96 """initialise a repository database by creating tables add filling them |
92 with the minimal set of entities (ie at least the schema, base groups and |
97 with the minimal set of entities (ie at least the schema, base groups and |
93 a initial user) |
98 a initial user) |
94 """ |
99 """ |
95 from glob import glob |
|
96 from yams import BASE_GROUPS |
|
97 from cubicweb.dbapi import in_memory_cnx |
100 from cubicweb.dbapi import in_memory_cnx |
98 from cubicweb.server.repository import Repository |
101 from cubicweb.server.repository import Repository |
99 from cubicweb.server.utils import manager_userpasswd |
102 from cubicweb.server.utils import manager_userpasswd |
100 from cubicweb.server.sqlutils import sqlexec, sqlschema, sqldropschema |
103 from cubicweb.server.sqlutils import sqlexec, sqlschema, sqldropschema |
101 # configuration to avoid db schema loading and user'state checking |
104 # configuration to avoid db schema loading and user'state checking |
138 schemasql = sqlschema(schema, driver) |
141 schemasql = sqlschema(schema, driver) |
139 #skip_entities=[str(e) for e in schema.entities() |
142 #skip_entities=[str(e) for e in schema.entities() |
140 # if not repo.system_source.support_entity(str(e))]) |
143 # if not repo.system_source.support_entity(str(e))]) |
141 sqlexec(schemasql, execute, pbtitle=_title) |
144 sqlexec(schemasql, execute, pbtitle=_title) |
142 # install additional driver specific sql files |
145 # install additional driver specific sql files |
143 for fpath in glob(join(config.schemas_lib_dir(), '*.sql.%s' % driver)): |
146 for fpath in glob(join(CW_SOFTWARE_ROOT, 'schemas', '*.sql.%s' % driver)): |
144 print '-> installing', fpath |
147 print '-> installing', fpath |
145 sqlexec(open(fpath).read(), execute, False, delimiter=';;') |
148 sqlexec(open(fpath).read(), execute, False, delimiter=';;') |
146 for directory in config.cubes_path(): |
149 for directory in config.cubes_path(): |
147 for fpath in glob(join(directory, 'schema', '*.sql.%s' % driver)): |
150 for fpath in glob(join(directory, 'schema', '*.sql.%s' % driver)): |
148 print '-> installing', fpath |
151 print '-> installing', fpath |