author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 13 Oct 2009 08:50:19 +0200 | |
changeset 3647 | 2941f4a0aab9 |
parent 3530 | 7dfe9d2c0fe7 |
child 3720 | 5376aaadd16b |
permissions | -rw-r--r-- |
0 | 1 |
"""Server subcube of cubicweb : defines objects used only on the server |
2 |
(repository) side |
|
3 |
||
4 |
This module contains functions to initialize a new repository. |
|
5 |
||
6 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
7 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 8 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
9 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 10 |
""" |
11 |
__docformat__ = "restructuredtext en" |
|
12 |
||
13 |
import sys |
|
14 |
from os.path import join, exists |
|
2730
bb6fcb8c5d71
to make cw schemas importable, they have to be installed w/ cw code, not in /usr/share/cubicweb/schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2633
diff
changeset
|
15 |
from glob import glob |
0 | 16 |
|
17 |
from logilab.common.modutils import LazyObject |
|
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2631
diff
changeset
|
18 |
from logilab.common.textutils import splitstrip |
0 | 19 |
|
2730
bb6fcb8c5d71
to make cw schemas importable, they have to be installed w/ cw code, not in /usr/share/cubicweb/schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2633
diff
changeset
|
20 |
from yams import BASE_GROUPS |
bb6fcb8c5d71
to make cw schemas importable, they have to be installed w/ cw code, not in /usr/share/cubicweb/schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2633
diff
changeset
|
21 |
|
bb6fcb8c5d71
to make cw schemas importable, they have to be installed w/ cw code, not in /usr/share/cubicweb/schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2633
diff
changeset
|
22 |
from cubicweb import CW_SOFTWARE_ROOT |
bb6fcb8c5d71
to make cw schemas importable, they have to be installed w/ cw code, not in /usr/share/cubicweb/schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2633
diff
changeset
|
23 |
|
2593
16d9419a4a79
F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2589
diff
changeset
|
24 |
# server-side debugging ######################################################### |
16d9419a4a79
F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2589
diff
changeset
|
25 |
|
2628
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
26 |
# server debugging flags. They may be combined using binary operators. |
2766
07e47b84acc2
DBG_MS flag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
27 |
DBG_NONE = 0 # no debug information |
07e47b84acc2
DBG_MS flag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
28 |
DBG_RQL = 1 # rql execution information |
07e47b84acc2
DBG_MS flag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
29 |
DBG_SQL = 2 # executed sql |
07e47b84acc2
DBG_MS flag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
30 |
DBG_REPO = 4 # repository events |
07e47b84acc2
DBG_MS flag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
31 |
DBG_MS = 8 # multi-sources |
07e47b84acc2
DBG_MS flag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
32 |
DBG_MORE = 16 # repository events |
2593
16d9419a4a79
F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2589
diff
changeset
|
33 |
|
2628
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
34 |
# current debug mode |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
35 |
DEBUG = 0 |
2593
16d9419a4a79
F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2589
diff
changeset
|
36 |
|
16d9419a4a79
F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2589
diff
changeset
|
37 |
def set_debug(debugmode): |
2628
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
38 |
"""change the repository debugging mode""" |
2593
16d9419a4a79
F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2589
diff
changeset
|
39 |
global DEBUG |
16d9419a4a79
F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2589
diff
changeset
|
40 |
if not debugmode: |
16d9419a4a79
F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2589
diff
changeset
|
41 |
DEBUG = 0 |
16d9419a4a79
F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2589
diff
changeset
|
42 |
return |
16d9419a4a79
F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2589
diff
changeset
|
43 |
if isinstance(debugmode, basestring): |
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2631
diff
changeset
|
44 |
for mode in splitstrip(debugmode, sep='|'): |
2628
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
45 |
DEBUG |= globals()[mode] |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
46 |
else: |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
47 |
DEBUG |= debugmode |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
48 |
|
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
49 |
|
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
50 |
class debugged(object): |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
51 |
"""repository debugging context manager / decorator |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
52 |
|
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
53 |
Can be used either as a context manager: |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
54 |
|
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
55 |
>>> with debugged(server.DBG_RQL | server.DBG_REPO): |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
56 |
... # some code in which you want to debug repository activity, |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
57 |
... # seing information about RQL being executed an repository events. |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
58 |
|
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
59 |
or as a function decorator: |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
60 |
|
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
61 |
>>> @debugged(server.DBG_RQL | server.DBG_REPO) |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
62 |
... def some_function(): |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
63 |
... # some code in which you want to debug repository activity, |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
64 |
... # seing information about RQL being executed an repository events |
2593
16d9419a4a79
F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2589
diff
changeset
|
65 |
|
2628
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
66 |
debug mode will be reseted at its original value when leaving the "with" |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
67 |
block or the decorated function |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
68 |
""" |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
69 |
def __init__(self, debugmode): |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
70 |
self.debugmode = debugmode |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
71 |
self._clevel = None |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
72 |
|
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
73 |
def __enter__(self): |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
74 |
"""enter with block""" |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
75 |
self._clevel = DEBUG |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
76 |
set_debug(self.debugmode) |
2593
16d9419a4a79
F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2589
diff
changeset
|
77 |
|
2628
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
78 |
def __exit__(self, exctype, exc, traceback): |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
79 |
"""leave with block""" |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
80 |
set_debug(self._clevel) |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
81 |
return traceback is None |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
82 |
|
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
83 |
def __call__(self, func): |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
84 |
"""decorate function""" |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
85 |
def wrapped(*args, **kwargs): |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
86 |
_clevel = DEBUG |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
87 |
set_debug(self.debugmode) |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
88 |
try: |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
89 |
return func(*args, **kwargs) |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
90 |
finally: |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
91 |
set_debug(self._clevel) |
a2cc32c1d982
document and replace debugged by a contextmanager/decorator class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2595
diff
changeset
|
92 |
return wrapped |
2593
16d9419a4a79
F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2589
diff
changeset
|
93 |
|
16d9419a4a79
F: start to handle binary debug log level on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2589
diff
changeset
|
94 |
# database initialization ###################################################### |
0 | 95 |
|
96 |
def init_repository(config, interactive=True, drop=False, vreg=None): |
|
97 |
"""initialise a repository database by creating tables add filling them |
|
98 |
with the minimal set of entities (ie at least the schema, base groups and |
|
99 |
a initial user) |
|
100 |
""" |
|
101 |
from cubicweb.dbapi import in_memory_cnx |
|
102 |
from cubicweb.server.repository import Repository |
|
103 |
from cubicweb.server.utils import manager_userpasswd |
|
104 |
from cubicweb.server.sqlutils import sqlexec, sqlschema, sqldropschema |
|
105 |
# configuration to avoid db schema loading and user'state checking |
|
106 |
# on connection |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
107 |
read_instance_schema = config.read_instance_schema |
0 | 108 |
bootstrap_schema = config.bootstrap_schema |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
109 |
config.read_instance_schema = False |
0 | 110 |
config.creating = True |
111 |
config.bootstrap_schema = True |
|
112 |
config.consider_user_state = False |
|
113 |
config.set_language = False |
|
114 |
# only enable the system source at initialization time + admin which is not |
|
115 |
# an actual source but contains initial manager account information |
|
116 |
config.enabled_sources = ('system', 'admin') |
|
117 |
repo = Repository(config, vreg=vreg) |
|
118 |
assert len(repo.sources) == 1, repo.sources |
|
119 |
schema = repo.schema |
|
120 |
sourcescfg = config.sources() |
|
2396
8bfb99d7bbcc
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2395
diff
changeset
|
121 |
_title = '-> creating tables ' |
8bfb99d7bbcc
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2395
diff
changeset
|
122 |
print _title, |
0 | 123 |
source = sourcescfg['system'] |
124 |
driver = source['db-driver'] |
|
125 |
sqlcnx = repo.system_source.get_connection() |
|
126 |
sqlcursor = sqlcnx.cursor() |
|
2306
95da5d9f0870
give session to doexec so it's able to rollback the connection on unexpected error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2172
diff
changeset
|
127 |
execute = sqlcursor.execute |
0 | 128 |
if drop: |
129 |
dropsql = sqldropschema(schema, driver) |
|
130 |
try: |
|
131 |
sqlexec(dropsql, execute) |
|
132 |
except Exception, ex: |
|
2394
92bba46b853f
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2306
diff
changeset
|
133 |
print '-> drop failed, skipped (%s).' % ex |
0 | 134 |
sqlcnx.rollback() |
135 |
# schema entities and relations tables |
|
136 |
# can't skip entities table even if system source doesn't support them, |
|
137 |
# they are used sometimes by generated sql. Keeping them empty is much |
|
138 |
# simpler than fixing this... |
|
139 |
if sqlcnx.logged_user != source['db-user']: |
|
140 |
schemasql = sqlschema(schema, driver, user=source['db-user']) |
|
141 |
else: |
|
142 |
schemasql = sqlschema(schema, driver) |
|
143 |
#skip_entities=[str(e) for e in schema.entities() |
|
144 |
# if not repo.system_source.support_entity(str(e))]) |
|
2396
8bfb99d7bbcc
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2395
diff
changeset
|
145 |
sqlexec(schemasql, execute, pbtitle=_title) |
0 | 146 |
# install additional driver specific sql files |
2730
bb6fcb8c5d71
to make cw schemas importable, they have to be installed w/ cw code, not in /usr/share/cubicweb/schemas
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2633
diff
changeset
|
147 |
for fpath in glob(join(CW_SOFTWARE_ROOT, 'schemas', '*.sql.%s' % driver)): |
2394
92bba46b853f
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2306
diff
changeset
|
148 |
print '-> installing', fpath |
0 | 149 |
sqlexec(open(fpath).read(), execute, False, delimiter=';;') |
3530
7dfe9d2c0fe7
call special sql files in correct order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3005
diff
changeset
|
150 |
for directory in reversed(config.cubes_path()): |
0 | 151 |
for fpath in glob(join(directory, 'schema', '*.sql.%s' % driver)): |
2394
92bba46b853f
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2306
diff
changeset
|
152 |
print '-> installing', fpath |
0 | 153 |
sqlexec(open(fpath).read(), execute, False, delimiter=';;') |
154 |
sqlcursor.close() |
|
155 |
sqlcnx.commit() |
|
156 |
sqlcnx.close() |
|
157 |
session = repo.internal_session() |
|
158 |
try: |
|
159 |
login = unicode(sourcescfg['admin']['login']) |
|
160 |
pwd = sourcescfg['admin']['password'] |
|
161 |
except KeyError: |
|
162 |
if interactive: |
|
163 |
msg = 'enter login and password of the initial manager account' |
|
164 |
login, pwd = manager_userpasswd(msg=msg, confirm=True) |
|
165 |
else: |
|
166 |
login, pwd = unicode(source['db-user']), source['db-password'] |
|
2394
92bba46b853f
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2306
diff
changeset
|
167 |
print '-> inserting default user and default groups.' |
2595
e76bf303c6f2
[F server test] sort for test predictability
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2593
diff
changeset
|
168 |
# sort for eid predicatability as expected in some server tests |
e76bf303c6f2
[F server test] sort for test predictability
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2593
diff
changeset
|
169 |
for group in sorted(BASE_GROUPS): |
2631 | 170 |
session.execute('INSERT CWGroup X: X name %(name)s', |
171 |
{'name': unicode(group)}) |
|
172 |
session.execute('INSERT CWUser X: X login %(login)s, X upassword %(pwd)s', |
|
173 |
{'login': login, 'pwd': pwd}) |
|
0 | 174 |
session.execute('SET U in_group G WHERE G name "managers"') |
175 |
session.commit() |
|
176 |
# reloging using the admin user |
|
177 |
config._cubes = None # avoid assertion error |
|
3647
2941f4a0aab9
refactor repo authentication to allow pluggable authentifier to login with something else than a password
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3530
diff
changeset
|
178 |
repo, cnx = in_memory_cnx(config, login, password=pwd) |
0 | 179 |
assert len(repo.sources) == 1, repo.sources |
180 |
handler = config.migration_handler(schema, interactive=False, |
|
181 |
cnx=cnx, repo=repo) |
|
182 |
initialize_schema(config, schema, handler) |
|
183 |
# yoo ! |
|
184 |
cnx.commit() |
|
185 |
config.enabled_sources = None |
|
186 |
for uri, source_config in config.sources().items(): |
|
187 |
if uri in ('admin', 'system'): |
|
188 |
# not an actual source or init_creating already called |
|
189 |
continue |
|
190 |
source = repo.get_source(uri, source_config) |
|
191 |
source.init_creating() |
|
192 |
cnx.commit() |
|
193 |
cnx.close() |
|
194 |
session.close() |
|
195 |
# restore initial configuration |
|
196 |
config.creating = False |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
197 |
config.read_instance_schema = read_instance_schema |
0 | 198 |
config.bootstrap_schema = bootstrap_schema |
199 |
config.consider_user_state = True |
|
200 |
config.set_language = True |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
201 |
print '-> database for instance %s initialized.' % config.appid |
0 | 202 |
|
203 |
||
204 |
def initialize_schema(config, schema, mhandler, event='create'): |
|
205 |
from cubicweb.server.schemaserial import serialize_schema |
|
206 |
paths = [p for p in config.cubes_path() + [config.apphome] |
|
207 |
if exists(join(p, 'migration'))] |
|
208 |
# execute cubicweb's pre<event> script |
|
209 |
mhandler.exec_event_script('pre%s' % event) |
|
210 |
# execute cubes pre<event> script if any |
|
211 |
for path in reversed(paths): |
|
212 |
mhandler.exec_event_script('pre%s' % event, path) |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
213 |
# enter instance'schema into the database |
2907
e222fac3cca3
we have to ensure a pool is set there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2903
diff
changeset
|
214 |
mhandler.session.set_pool() |
2903
043c8fcb3819
[migration] drop rqlcursor
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2766
diff
changeset
|
215 |
serialize_schema(mhandler.session, schema) |
0 | 216 |
# execute cubicweb's post<event> script |
217 |
mhandler.exec_event_script('post%s' % event) |
|
218 |
# execute cubes'post<event> script if any |
|
219 |
for path in reversed(paths): |
|
220 |
mhandler.exec_event_script('post%s' % event, path) |
|
221 |
||
222 |
||
223 |
# sqlite'stored procedures have to be registered at connexion opening time |
|
224 |
SQL_CONNECT_HOOKS = {} |
|
225 |
||
226 |
# add to this set relations which should have their add security checking done |
|
227 |
# *BEFORE* adding the actual relation (done after by default) |
|
228 |
BEFORE_ADD_RELATIONS = set(('owned_by',)) |
|
229 |
||
230 |
# add to this set relations which should have their add security checking done |
|
231 |
# *at COMMIT TIME* (done after by default) |
|
232 |
ON_COMMIT_ADD_RELATIONS = set(()) |
|
233 |
||
234 |
# available sources registry |
|
235 |
SOURCE_TYPES = {'native': LazyObject('cubicweb.server.sources.native', 'NativeSQLSource'), |
|
236 |
# XXX private sources installed by an external cube |
|
237 |
'pyrorql': LazyObject('cubicweb.server.sources.pyrorql', 'PyroRQLSource'), |
|
238 |
'ldapuser': LazyObject('cubicweb.server.sources.ldapuser', 'LDAPUserSource'), |
|
239 |
} |