author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 09 Jul 2009 14:58:55 +0200 | |
branch | stable |
changeset 2352 | 734eb79680e9 |
parent 2107 | 6c4a4c514ac2 |
child 2476 | 1294a6bdf3bf |
permissions | -rw-r--r-- |
0 | 1 |
"""server.serverconfig definition |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1666
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
: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:
1666
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
import os |
|
11 |
from os.path import join, exists |
|
12 |
||
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
13 |
from logilab.common.configuration import REQUIRED, Method, Configuration, \ |
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
14 |
ini_format_section |
0 | 15 |
from logilab.common.decorators import wproperty, cached, clear_cache |
16 |
||
17 |
from cubicweb import CW_SOFTWARE_ROOT, RegistryNotFound |
|
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
18 |
from cubicweb.toolsutils import env_path, read_config, restrict_perms_to_user |
0 | 19 |
from cubicweb.cwconfig import CubicWebConfiguration, merge_options |
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
20 |
from cubicweb.server import SOURCE_TYPES |
0 | 21 |
|
22 |
||
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
23 |
USER_OPTIONS = ( |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
24 |
('login', {'type' : 'string', |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
25 |
'default': REQUIRED, |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
26 |
'help': "cubicweb manager account's login " |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
27 |
'(this user will be created)', |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
28 |
'inputlevel': 0, |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
29 |
}), |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
30 |
('password', {'type' : 'password', |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
31 |
'help': "cubicweb manager account's password", |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
32 |
'inputlevel': 0, |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
33 |
}), |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
34 |
) |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
35 |
|
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
36 |
def generate_sources_file(sourcesfile, sourcescfg, keys=None): |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
37 |
"""serialize repository'sources configuration into a INI like file |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
38 |
|
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
39 |
the `keys` parameter may be used to sort sections |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
40 |
""" |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
41 |
if keys is None: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
42 |
keys = sourcescfg.keys() |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
43 |
else: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
44 |
for key in sourcescfg: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
45 |
if not key in keys: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
46 |
keys.append(key) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
47 |
stream = open(sourcesfile, 'w') |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
48 |
for uri in keys: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
49 |
sconfig = sourcescfg[uri] |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
50 |
if isinstance(sconfig, dict): |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
51 |
# get a Configuration object |
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
52 |
if uri == 'admin': |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
53 |
options = USER_OPTIONS |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
54 |
else: |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
55 |
options = SOURCE_TYPES[sconfig['adapter']].options |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
56 |
_sconfig = Configuration(options=options) |
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
57 |
for attr, val in sconfig.items(): |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
58 |
if attr == 'uri': |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
59 |
continue |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
60 |
if attr == 'adapter': |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
61 |
_sconfig.adapter = val |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
62 |
else: |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
63 |
_sconfig.set_option(attr, val) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
64 |
sconfig = _sconfig |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
65 |
optsbysect = list(sconfig.options_by_section()) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
66 |
assert len(optsbysect) == 1, 'all options for a source should be in the same group' |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
67 |
ini_format_section(stream, uri, optsbysect[0][1]) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
68 |
if hasattr(sconfig, 'adapter'): |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
69 |
print >> stream |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
70 |
print >> stream, '# adapter for this source (YOU SHOULD NOT CHANGE THIS)' |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
71 |
print >> stream, 'adapter=%s' % sconfig.adapter |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
72 |
print >> stream |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
73 |
|
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
74 |
|
0 | 75 |
class ServerConfiguration(CubicWebConfiguration): |
76 |
"""standalone RQL server""" |
|
77 |
name = 'repository' |
|
78 |
if os.environ.get('APYCOT_ROOT'): |
|
79 |
root = os.environ['APYCOT_ROOT'] |
|
80 |
SCHEMAS_LIB_DIR = '%s/local/share/cubicweb/schemas/' % root |
|
81 |
elif CubicWebConfiguration.mode == 'dev': |
|
82 |
SCHEMAS_LIB_DIR = join(CW_SOFTWARE_ROOT, 'schemas') |
|
83 |
BACKUP_DIR = CubicWebConfiguration.RUNTIME_DIR |
|
84 |
else: |
|
85 |
SCHEMAS_LIB_DIR = '/usr/share/cubicweb/schemas/' |
|
86 |
BACKUP_DIR = '/var/lib/cubicweb/backup/' |
|
87 |
||
88 |
cubicweb_vobject_path = CubicWebConfiguration.cubicweb_vobject_path | set(['sobjects']) |
|
89 |
cube_vobject_path = CubicWebConfiguration.cube_vobject_path | set(['sobjects', 'hooks']) |
|
90 |
||
91 |
options = merge_options(( |
|
92 |
# ctl configuration |
|
93 |
('host', |
|
94 |
{'type' : 'string', |
|
95 |
'default': None, |
|
96 |
'help': 'host name if not correctly detectable through gethostname', |
|
97 |
'group': 'main', 'inputlevel': 1, |
|
98 |
}), |
|
99 |
('pid-file', |
|
100 |
{'type' : 'string', |
|
101 |
'default': Method('default_pid_file'), |
|
102 |
'help': 'repository\'s pid file', |
|
103 |
'group': 'main', 'inputlevel': 2, |
|
104 |
}), |
|
105 |
('uid', |
|
106 |
{'type' : 'string', |
|
107 |
'default': None, |
|
108 |
'help': 'if this option is set, use the specified user to start \ |
|
109 |
the repository rather than the user running the command', |
|
136
ff51a18c66a3
ask less questions on instance creation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
110 |
'group': 'main', 'inputlevel': (CubicWebConfiguration.mode == 'installed') and 0 or 1, |
0 | 111 |
}), |
112 |
('session-time', |
|
113 |
{'type' : 'int', |
|
114 |
'default': 30*60, |
|
115 |
'help': 'session expiration time, default to 30 minutes', |
|
116 |
'group': 'main', 'inputlevel': 1, |
|
117 |
}), |
|
118 |
('connections-pool-size', |
|
119 |
{'type' : 'int', |
|
120 |
'default': 4, |
|
121 |
'help': 'size of the connections pools. Each source supporting multiple \ |
|
122 |
connections will have this number of opened connections.', |
|
123 |
'group': 'main', 'inputlevel': 1, |
|
124 |
}), |
|
125 |
('rql-cache-size', |
|
126 |
{'type' : 'int', |
|
127 |
'default': 300, |
|
128 |
'help': 'size of the parsed rql cache size.', |
|
129 |
'group': 'main', 'inputlevel': 1, |
|
130 |
}), |
|
1160
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
131 |
('delay-full-text-indexation', |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
132 |
{'type' : 'yn', 'default': False, |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
133 |
'help': 'When full text indexation of entity has a too important cost' |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
134 |
' to be done when entity are added/modified by users, activate this ' |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
135 |
'option and setup a job using cubicweb-ctl db-rebuild-fti on your ' |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
136 |
'system (using cron for instance).', |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
137 |
'group': 'main', 'inputlevel': 1, |
77bf88f01fcc
new delay-full-text-indexation configuration option
sylvain.thenault@logilab.fr
parents:
136
diff
changeset
|
138 |
}), |
1666 | 139 |
|
0 | 140 |
# email configuration |
141 |
('default-recipients-mode', |
|
142 |
{'type' : 'choice', |
|
143 |
'choices' : ('default-dest-addrs', 'users', 'none'), |
|
144 |
'default': 'default-dest-addrs', |
|
145 |
'help': 'when a notification should be sent with no specific rules \ |
|
146 |
to find recipients, recipients will be found according to this mode. Available \ |
|
147 |
modes are "default-dest-addrs" (emails specified in the configuration \ |
|
148 |
variable with the same name), "users" (every users which has activated \ |
|
149 |
account with an email set), "none" (no notification).', |
|
150 |
'group': 'email', 'inputlevel': 1, |
|
151 |
}), |
|
152 |
('default-dest-addrs', |
|
153 |
{'type' : 'csv', |
|
154 |
'default': (), |
|
155 |
'help': 'comma separated list of email addresses that will be used \ |
|
156 |
as default recipient when an email is sent and the notification has no \ |
|
157 |
specific recipient rules.', |
|
158 |
'group': 'email', 'inputlevel': 1, |
|
159 |
}), |
|
160 |
('supervising-addrs', |
|
161 |
{'type' : 'csv', |
|
162 |
'default': (), |
|
163 |
'help': 'comma separated list of email addresses that will be \ |
|
164 |
notified of every changes.', |
|
165 |
'group': 'email', 'inputlevel': 2, |
|
166 |
}), |
|
167 |
# pyro server.serverconfig |
|
168 |
('pyro-port', |
|
169 |
{'type' : 'int', |
|
170 |
'default': None, |
|
171 |
'help': 'Pyro server port. If not set, it will be choosen randomly', |
|
172 |
'group': 'pyro-server', 'inputlevel': 2, |
|
173 |
}), |
|
174 |
('pyro-id', # XXX reuse pyro-application-id |
|
175 |
{'type' : 'string', |
|
176 |
'default': None, |
|
177 |
'help': 'identifier of the repository in the pyro name server', |
|
178 |
'group': 'pyro-server', 'inputlevel': 2, |
|
179 |
}), |
|
180 |
) + CubicWebConfiguration.options) |
|
1666 | 181 |
|
0 | 182 |
# read the schema from the database |
183 |
read_application_schema = True |
|
184 |
bootstrap_schema = True |
|
1666 | 185 |
|
0 | 186 |
# check user's state at login time |
187 |
consider_user_state = True |
|
1666 | 188 |
|
0 | 189 |
# hooks registration configuration |
190 |
# all hooks should be activated during normal execution |
|
191 |
core_hooks = True |
|
192 |
usergroup_hooks = True |
|
193 |
schema_hooks = True |
|
194 |
notification_hooks = True |
|
195 |
security_hooks = True |
|
196 |
application_hooks = True |
|
197 |
||
198 |
# should some hooks be deactivated during [pre|post]create script execution |
|
199 |
free_wheel = False |
|
1666 | 200 |
|
0 | 201 |
# list of enables sources when sources restriction is necessary |
202 |
# (eg repository initialization at least) |
|
203 |
_enabled_sources = None |
|
204 |
@wproperty |
|
205 |
def enabled_sources(self, sourceuris=None): |
|
206 |
self._enabled_sources = sourceuris |
|
207 |
clear_cache(self, 'sources') |
|
1666 | 208 |
|
0 | 209 |
@classmethod |
210 |
def schemas_lib_dir(cls): |
|
211 |
"""application schema directory""" |
|
212 |
return env_path('CW_SCHEMA_LIB', cls.SCHEMAS_LIB_DIR, 'schemas') |
|
213 |
||
214 |
@classmethod |
|
215 |
def backup_dir(cls): |
|
216 |
"""backup directory where a stored db backups before migration""" |
|
217 |
return env_path('CW_BACKUP', cls.BACKUP_DIR, 'run time') |
|
218 |
||
219 |
def bootstrap_cubes(self): |
|
220 |
from logilab.common.textutils import get_csv |
|
221 |
for line in file(join(self.apphome, 'bootstrap_cubes')): |
|
222 |
line = line.strip() |
|
223 |
if not line or line.startswith('#'): |
|
224 |
continue |
|
225 |
self.init_cubes(self.expand_cubes(get_csv(line))) |
|
226 |
break |
|
227 |
else: |
|
228 |
# no cubes |
|
229 |
self.init_cubes(()) |
|
1666 | 230 |
|
0 | 231 |
def write_bootstrap_cubes_file(self, cubes): |
232 |
stream = file(join(self.apphome, 'bootstrap_cubes'), 'w') |
|
233 |
stream.write('# this is a generated file only used for bootstraping\n') |
|
234 |
stream.write('# you should not have to edit this\n') |
|
235 |
stream.write('%s\n' % ','.join(cubes)) |
|
236 |
stream.close() |
|
1666 | 237 |
|
0 | 238 |
def sources_file(self): |
239 |
return join(self.apphome, 'sources') |
|
1666 | 240 |
|
0 | 241 |
# this method has to be cached since when the server is running using a |
242 |
# restricted user, this user usually don't have access to the sources |
|
243 |
# configuration file (#16102) |
|
244 |
@cached |
|
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
245 |
def read_sources_file(self): |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
246 |
return read_config(self.sources_file()) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
247 |
|
0 | 248 |
def sources(self): |
249 |
"""return a dictionnaries containing sources definitions indexed by |
|
250 |
sources'uri |
|
251 |
""" |
|
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
252 |
allsources = self.read_sources_file() |
0 | 253 |
if self._enabled_sources is None: |
254 |
return allsources |
|
255 |
return dict((uri, config) for uri, config in allsources.items() |
|
256 |
if uri in self._enabled_sources or uri == 'admin') |
|
1666 | 257 |
|
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
258 |
def write_sources_file(self, sourcescfg): |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
259 |
sourcesfile = self.sources_file() |
2107
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
260 |
if exists(sourcesfile): |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
261 |
import shutil |
6c4a4c514ac2
add source to sources configuration when adding a cube defining a source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2105
diff
changeset
|
262 |
shutil.copy(sourcesfile, sourcesfile + '.bak') |
2105
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
263 |
generate_sources_file(sourcesfile, sourcescfg, ['admin', 'system']) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
264 |
restrict_perms_to_user(sourcesfile) |
92ea410806fe
refactor sources configuration, add source to sources when using a cube defining
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
265 |
|
0 | 266 |
def pyro_enabled(self): |
267 |
"""pyro is always enabled in standalone repository configuration""" |
|
268 |
return True |
|
1666 | 269 |
|
0 | 270 |
def load_hooks(self, vreg): |
271 |
hooks = {} |
|
272 |
for path in reversed([self.apphome] + self.cubes_path()): |
|
273 |
hooksfile = join(path, 'application_hooks.py') |
|
274 |
if exists(hooksfile): |
|
275 |
self.warning('application_hooks.py is deprecated, use dynamic ' |
|
276 |
'objects to register hooks (%s)', hooksfile) |
|
277 |
context = {} |
|
1666 | 278 |
# Use execfile rather than `load_module_from_name` because |
279 |
# the latter gets fooled by the `sys.modules` cache when |
|
0 | 280 |
# loading different configurations one after the other |
281 |
# (another fix would have been to do : |
|
282 |
# sys.modules.pop('applications_hooks') |
|
283 |
# or to modify load_module_from_name so that it provides |
|
284 |
# a use_cache optional parameter |
|
285 |
execfile(hooksfile, context, context) |
|
286 |
for event, hooksdef in context['HOOKS'].items(): |
|
287 |
for ertype, hookcbs in hooksdef.items(): |
|
288 |
hooks.setdefault(event, {}).setdefault(ertype, []).extend(hookcbs) |
|
289 |
try: |
|
290 |
apphookdefs = vreg.registry_objects('hooks') |
|
291 |
except RegistryNotFound: |
|
292 |
return hooks |
|
293 |
for hookdef in apphookdefs: |
|
294 |
for event, ertype in hookdef.register_to(): |
|
295 |
if ertype == 'Any': |
|
296 |
ertype = '' |
|
297 |
cb = hookdef.make_callback(event) |
|
298 |
hooks.setdefault(event, {}).setdefault(ertype, []).append(cb) |
|
299 |
return hooks |
|
1666 | 300 |
|
301 |
def load_schema(self, expand_cubes=False, **kwargs): |
|
0 | 302 |
from cubicweb.schema import CubicWebSchemaLoader |
303 |
if expand_cubes: |
|
304 |
# in case some new dependencies have been introduced, we have to |
|
305 |
# reinitialize cubes so the full filesystem schema is read |
|
306 |
origcubes = self.cubes() |
|
307 |
self._cubes = None |
|
308 |
self.init_cubes(self.expand_cubes(origcubes)) |
|
1666 | 309 |
schema = CubicWebSchemaLoader().load(self, **kwargs) |
0 | 310 |
if expand_cubes: |
311 |
# restaure original value |
|
312 |
self._cubes = origcubes |
|
313 |
return schema |
|
1666 | 314 |
|
0 | 315 |
def load_bootstrap_schema(self): |
316 |
from cubicweb.schema import BootstrapSchemaLoader |
|
317 |
schema = BootstrapSchemaLoader().load(self) |
|
318 |
schema.name = 'bootstrap' |
|
319 |
return schema |
|
1666 | 320 |
|
0 | 321 |
def set_sources_mode(self, sources): |
322 |
if 'migration' in sources: |
|
323 |
from cubicweb.server.sources import source_adapter |
|
324 |
assert len(sources) == 1 |
|
325 |
enabled_sources = [] |
|
326 |
for uri, config in self.sources().iteritems(): |
|
327 |
if uri == 'admin': |
|
328 |
continue |
|
329 |
if source_adapter(config).connect_for_migration: |
|
330 |
enabled_sources.append(uri) |
|
331 |
else: |
|
332 |
print 'not connecting to source', uri, 'during migration' |
|
333 |
elif 'all' in sources: |
|
334 |
assert len(sources) == 1 |
|
1133 | 335 |
enabled_sources = None |
0 | 336 |
else: |
337 |
known_sources = self.sources() |
|
338 |
for uri in sources: |
|
339 |
assert uri in known_sources, uri |
|
340 |
enabled_sources = sources |
|
341 |
self._enabled_sources = enabled_sources |
|
342 |
clear_cache(self, 'sources') |
|
1666 | 343 |
|
0 | 344 |
def migration_handler(self, schema=None, interactive=True, |
345 |
cnx=None, repo=None, connect=True): |
|
346 |
"""return a migration handler instance""" |
|
347 |
from cubicweb.server.migractions import ServerMigrationHelper |
|
348 |
return ServerMigrationHelper(self, schema, interactive=interactive, |
|
349 |
cnx=cnx, repo=repo, connect=connect, |
|
350 |
verbosity=getattr(self, 'verbosity', 0)) |