author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 05 Jun 2009 15:06:55 +0200 | |
changeset 2057 | 0a0cbccafcb5 |
parent 1977 | 606923dff11b |
child 2220 | 64aace08ae2f |
permissions | -rw-r--r-- |
369
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
180
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
0 | 2 |
"""common configuration utilities for cubicweb |
3 |
||
4 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1948
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1493 | 7 |
|
8 |
.. envvar:: CW_CUBES_PATH |
|
9 |
||
10 |
Augments the default search path for cubes |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1681
diff
changeset
|
11 |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1948
diff
changeset
|
12 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 13 |
""" |
14 |
__docformat__ = "restructuredtext en" |
|
1948 | 15 |
_ = unicode |
0 | 16 |
|
17 |
import sys |
|
18 |
import os |
|
19 |
import logging |
|
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
20 |
from os.path import exists, join, expanduser, abspath, normpath, basename, isdir |
0 | 21 |
|
22 |
from logilab.common.decorators import cached |
|
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
23 |
from logilab.common.logging_ext import set_log_methods, init_log |
0 | 24 |
from logilab.common.configuration import (Configuration, Method, |
25 |
ConfigurationMixIn, merge_options) |
|
26 |
||
27 |
from cubicweb import CW_SOFTWARE_ROOT, CW_MIGRATION_MAP, ConfigurationError |
|
1132 | 28 |
from cubicweb.toolsutils import env_path, create_dir |
0 | 29 |
|
30 |
CONFIGURATIONS = [] |
|
31 |
||
32 |
||
33 |
class metaconfiguration(type): |
|
34 |
"""metaclass to automaticaly register configuration""" |
|
35 |
def __new__(mcs, name, bases, classdict): |
|
36 |
cls = super(metaconfiguration, mcs).__new__(mcs, name, bases, classdict) |
|
37 |
if classdict.get('name'): |
|
38 |
CONFIGURATIONS.append(cls) |
|
39 |
return cls |
|
40 |
||
41 |
def configuration_cls(name): |
|
42 |
"""return the configuration class registered with the given name""" |
|
43 |
try: |
|
44 |
return [c for c in CONFIGURATIONS if c.name == name][0] |
|
45 |
except IndexError: |
|
46 |
raise ConfigurationError('no such config %r (check it exists with "cubicweb-ctl list")' % name) |
|
47 |
||
48 |
def possible_configurations(directory): |
|
49 |
"""return a list of installed configurations in a directory |
|
50 |
according to *-ctl files |
|
51 |
""" |
|
52 |
return [name for name in ('repository', 'twisted', 'all-in-one') |
|
53 |
if exists(join(directory, '%s.conf' % name))] |
|
54 |
||
55 |
def guess_configuration(directory): |
|
56 |
"""try to guess the configuration to use for a directory. If multiple |
|
57 |
configurations are found, ConfigurationError is raised |
|
58 |
""" |
|
59 |
modes = possible_configurations(directory) |
|
60 |
if len(modes) != 1: |
|
61 |
raise ConfigurationError('unable to guess configuration from %r %s' |
|
62 |
% (directory, modes)) |
|
63 |
return modes[0] |
|
64 |
||
65 |
||
66 |
# persistent options definition |
|
67 |
PERSISTENT_OPTIONS = ( |
|
68 |
('encoding', |
|
69 |
{'type' : 'string', |
|
70 |
'default': 'UTF-8', |
|
71 |
'help': _('user interface encoding'), |
|
72 |
'group': 'ui', 'sitewide': True, |
|
1446 | 73 |
}), |
0 | 74 |
('language', |
75 |
{'type' : 'string', |
|
76 |
'default': 'en', |
|
77 |
'vocabulary': Method('available_languages'), |
|
78 |
'help': _('language of the user interface'), |
|
1446 | 79 |
'group': 'ui', |
0 | 80 |
}), |
81 |
('date-format', |
|
82 |
{'type' : 'string', |
|
83 |
'default': '%Y/%m/%d', |
|
84 |
'help': _('how to format date in the ui ("man strftime" for format description)'), |
|
1446 | 85 |
'group': 'ui', |
0 | 86 |
}), |
87 |
('datetime-format', |
|
88 |
{'type' : 'string', |
|
89 |
'default': '%Y/%m/%d %H:%M', |
|
90 |
'help': _('how to format date and time in the ui ("man strftime" for format description)'), |
|
1446 | 91 |
'group': 'ui', |
0 | 92 |
}), |
93 |
('time-format', |
|
94 |
{'type' : 'string', |
|
95 |
'default': '%H:%M', |
|
96 |
'help': _('how to format time in the ui ("man strftime" for format description)'), |
|
1446 | 97 |
'group': 'ui', |
0 | 98 |
}), |
99 |
('float-format', |
|
100 |
{'type' : 'string', |
|
101 |
'default': '%.3f', |
|
102 |
'help': _('how to format float numbers in the ui'), |
|
1446 | 103 |
'group': 'ui', |
0 | 104 |
}), |
105 |
('default-text-format', |
|
106 |
{'type' : 'choice', |
|
107 |
'choices': ('text/plain', 'text/rest', 'text/html'), |
|
108 |
'default': 'text/html', # use fckeditor in the web ui |
|
109 |
'help': _('default text format for rich text fields.'), |
|
1446 | 110 |
'group': 'ui', |
0 | 111 |
}), |
112 |
('short-line-size', |
|
113 |
{'type' : 'int', |
|
114 |
'default': 40, |
|
115 |
'help': _('maximum number of characters in short description'), |
|
116 |
'group': 'navigation', |
|
117 |
}), |
|
118 |
) |
|
119 |
||
120 |
def register_persistent_options(options): |
|
121 |
global PERSISTENT_OPTIONS |
|
122 |
PERSISTENT_OPTIONS = merge_options(PERSISTENT_OPTIONS + options) |
|
1446 | 123 |
|
0 | 124 |
CFGTYPE2ETYPE_MAP = { |
125 |
'string': 'String', |
|
126 |
'choice': 'String', |
|
127 |
'yn': 'Boolean', |
|
128 |
'int': 'Int', |
|
129 |
'float' : 'Float', |
|
130 |
} |
|
1446 | 131 |
|
0 | 132 |
class CubicWebNoAppConfiguration(ConfigurationMixIn): |
133 |
"""base class for cubicweb configuration without a specific instance directory |
|
134 |
""" |
|
135 |
__metaclass__ = metaconfiguration |
|
136 |
# to set in concrete configuration |
|
137 |
name = None |
|
138 |
# log messages format (see logging module documentation for available keys) |
|
139 |
log_format = '%(asctime)s - (%(name)s) %(levelname)s: %(message)s' |
|
140 |
# nor remove vobjects based on unused interface |
|
141 |
cleanup_interface_sobjects = True |
|
142 |
||
143 |
if os.environ.get('APYCOT_ROOT'): |
|
144 |
mode = 'test' |
|
145 |
CUBES_DIR = '%(APYCOT_ROOT)s/local/share/cubicweb/cubes/' % os.environ |
|
436 | 146 |
# create __init__ file |
147 |
file(join(CUBES_DIR, '__init__.py'), 'w').close() |
|
0 | 148 |
elif exists(join(CW_SOFTWARE_ROOT, '.hg')): |
149 |
mode = 'dev' |
|
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
150 |
CUBES_DIR = abspath(normpath(join(CW_SOFTWARE_ROOT, '../cubes'))) |
0 | 151 |
else: |
152 |
mode = 'installed' |
|
153 |
CUBES_DIR = '/usr/share/cubicweb/cubes/' |
|
154 |
||
1046
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
155 |
options = ( |
0 | 156 |
('log-threshold', |
157 |
{'type' : 'string', # XXX use a dedicated type? |
|
158 |
'default': 'ERROR', |
|
159 |
'help': 'server\'s log level', |
|
160 |
'group': 'main', 'inputlevel': 1, |
|
161 |
}), |
|
162 |
# pyro name server |
|
163 |
('pyro-ns-host', |
|
164 |
{'type' : 'string', |
|
378
c0cd7398edff
revert local debug checkin
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
369
diff
changeset
|
165 |
'default': '', |
0 | 166 |
'help': 'Pyro name server\'s host. If not set, will be detected by a \ |
167 |
broadcast query', |
|
168 |
'group': 'pyro-name-server', 'inputlevel': 1, |
|
169 |
}), |
|
170 |
('pyro-ns-port', |
|
171 |
{'type' : 'int', |
|
172 |
'default': None, |
|
173 |
'help': 'Pyro name server\'s listening port. If not set, default \ |
|
174 |
port will be used.', |
|
175 |
'group': 'pyro-name-server', 'inputlevel': 1, |
|
176 |
}), |
|
177 |
('pyro-ns-group', |
|
178 |
{'type' : 'string', |
|
179 |
'default': 'cubicweb', |
|
180 |
'help': 'Pyro name server\'s group where the repository will be \ |
|
181 |
registered.', |
|
182 |
'group': 'pyro-name-server', 'inputlevel': 1, |
|
183 |
}), |
|
184 |
# common configuration options which are potentially required as soon as |
|
185 |
# you're using "base" application objects (ie to really server/web |
|
186 |
# specific) |
|
187 |
('base-url', |
|
188 |
{'type' : 'string', |
|
189 |
'default': None, |
|
190 |
'help': 'web server root url', |
|
191 |
'group': 'main', 'inputlevel': 1, |
|
192 |
}), |
|
1520
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
193 |
('use-request-subdomain', |
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
194 |
{'type' : 'yn', |
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
195 |
'default': None, |
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
196 |
'help': ('if set, base-url subdomain is replaced by the request\'s ' |
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
197 |
'host, to help managing sites with several subdomains in a ' |
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
198 |
'single cubicweb instance'), |
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
199 |
'group': 'main', 'inputlevel': 1, |
b097057e629d
provide an option to substitute the base-url (left-most part) subdomain by the one of the current http query to easy multiple subdomains website management
Florent <florent@secondweb.fr>
parents:
1446
diff
changeset
|
200 |
}), |
0 | 201 |
('mangle-emails', |
202 |
{'type' : 'yn', |
|
203 |
'default': False, |
|
204 |
'help': "don't display actual email addresses but mangle them if \ |
|
205 |
this option is set to yes", |
|
206 |
'group': 'email', 'inputlevel': 2, |
|
207 |
}), |
|
1046
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
208 |
('disable-appobjects', |
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
209 |
{'type' : 'csv', 'default': (), |
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
210 |
'help': 'comma separated list of identifiers of application objects (<registry>.<oid>) to disable', |
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
211 |
'group': 'appobjects', 'inputlevel': 2, |
52ee022d87e3
simplify registry options to disable some appobjects to use a single option
sylvain.thenault@logilab.fr
parents:
819
diff
changeset
|
212 |
}), |
0 | 213 |
) |
214 |
# static and class methods used to get application independant resources ## |
|
1446 | 215 |
|
0 | 216 |
@staticmethod |
217 |
def cubicweb_version(): |
|
218 |
"""return installed cubicweb version""" |
|
219 |
from logilab.common.changelog import Version |
|
220 |
from cubicweb import __pkginfo__ |
|
221 |
version = __pkginfo__.numversion |
|
222 |
assert len(version) == 3, version |
|
223 |
return Version(version) |
|
1446 | 224 |
|
0 | 225 |
@staticmethod |
226 |
def persistent_options_configuration(): |
|
227 |
return Configuration(options=PERSISTENT_OPTIONS) |
|
228 |
||
229 |
@classmethod |
|
230 |
def shared_dir(cls): |
|
231 |
"""return the shared data directory (i.e. directory where standard |
|
232 |
library views and data may be found) |
|
233 |
""" |
|
234 |
if cls.mode in ('dev', 'test') and not os.environ.get('APYCOT_ROOT'): |
|
235 |
return join(CW_SOFTWARE_ROOT, 'web') |
|
1039 | 236 |
return cls.cube_dir('shared') |
1446 | 237 |
|
0 | 238 |
@classmethod |
239 |
def i18n_lib_dir(cls): |
|
240 |
"""return application's i18n directory""" |
|
241 |
if cls.mode in ('dev', 'test') and not os.environ.get('APYCOT_ROOT'): |
|
242 |
return join(CW_SOFTWARE_ROOT, 'i18n') |
|
243 |
return join(cls.shared_dir(), 'i18n') |
|
244 |
||
245 |
@classmethod |
|
246 |
def available_cubes(cls): |
|
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
247 |
cubes = set() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
248 |
for directory in cls.cubes_search_path(): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
249 |
for cube in os.listdir(directory): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
250 |
if isdir(join(directory, cube)) and not cube in ('CVS', '.svn', 'shared', '.hg'): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
251 |
cubes.add(cube) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
252 |
return sorted(cubes) |
1446 | 253 |
|
0 | 254 |
@classmethod |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
255 |
def cubes_search_path(cls): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
256 |
"""return the path of directories where cubes should be searched""" |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
257 |
path = [] |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
258 |
try: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
259 |
for directory in os.environ['CW_CUBES_PATH'].split(os.pathsep): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
260 |
directory = abspath(normpath(directory)) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
261 |
if exists(directory) and not directory in path: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
262 |
path.append(directory) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
263 |
except KeyError: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
264 |
pass |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
265 |
if not cls.CUBES_DIR in path: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
266 |
path.append(cls.CUBES_DIR) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
267 |
return path |
1446 | 268 |
|
0 | 269 |
@classmethod |
270 |
def cube_dir(cls, cube): |
|
271 |
"""return the cube directory for the given cube id, |
|
272 |
raise ConfigurationError if it doesn't exists |
|
273 |
""" |
|
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
274 |
for directory in cls.cubes_search_path(): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
275 |
cubedir = join(directory, cube) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
276 |
if exists(cubedir): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
277 |
return cubedir |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
278 |
raise ConfigurationError('no cube %s in %s' % (cube, cls.cubes_search_path())) |
0 | 279 |
|
280 |
@classmethod |
|
281 |
def cube_migration_scripts_dir(cls, cube): |
|
282 |
"""cube migration scripts directory""" |
|
283 |
return join(cls.cube_dir(cube), 'migration') |
|
1446 | 284 |
|
0 | 285 |
@classmethod |
286 |
def cube_pkginfo(cls, cube): |
|
287 |
"""return the information module for the given cube""" |
|
288 |
cube = CW_MIGRATION_MAP.get(cube, cube) |
|
289 |
try: |
|
290 |
return getattr(__import__('cubes.%s.__pkginfo__' % cube), cube).__pkginfo__ |
|
140
478bdd15bc0e
more error resilient
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
291 |
except Exception, ex: |
0 | 292 |
raise ConfigurationError('unable to find packaging information for ' |
140
478bdd15bc0e
more error resilient
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
293 |
'cube %s (%s: %s)' % (cube, ex.__class__.__name__, ex)) |
0 | 294 |
|
295 |
@classmethod |
|
296 |
def cube_version(cls, cube): |
|
1446 | 297 |
"""return the version of the cube located in the given directory |
0 | 298 |
""" |
299 |
from logilab.common.changelog import Version |
|
300 |
version = cls.cube_pkginfo(cube).numversion |
|
301 |
assert len(version) == 3, version |
|
302 |
return Version(version) |
|
303 |
||
304 |
@classmethod |
|
305 |
def cube_dependencies(cls, cube): |
|
306 |
"""return cubicweb cubes used by the given cube""" |
|
307 |
return getattr(cls.cube_pkginfo(cube), '__use__', ()) |
|
308 |
||
309 |
@classmethod |
|
310 |
def cube_recommends(cls, cube): |
|
311 |
"""return cubicweb cubes recommended by the given cube""" |
|
312 |
return getattr(cls.cube_pkginfo(cube), '__recommend__', ()) |
|
313 |
||
314 |
@classmethod |
|
315 |
def expand_cubes(cls, cubes): |
|
316 |
"""expand the given list of top level cubes used by adding recursivly |
|
317 |
each cube dependencies |
|
318 |
""" |
|
319 |
cubes = list(cubes) |
|
320 |
todo = cubes[:] |
|
321 |
while todo: |
|
322 |
cube = todo.pop(0) |
|
323 |
for depcube in cls.cube_dependencies(cube): |
|
324 |
if depcube not in cubes: |
|
325 |
depcube = CW_MIGRATION_MAP.get(depcube, depcube) |
|
326 |
cubes.append(depcube) |
|
327 |
todo.append(depcube) |
|
328 |
return cubes |
|
329 |
||
330 |
@classmethod |
|
331 |
def reorder_cubes(cls, cubes): |
|
332 |
"""reorder cubes from the top level cubes to inner dependencies |
|
333 |
cubes |
|
334 |
""" |
|
335 |
from logilab.common.graph import get_cycles |
|
336 |
graph = {} |
|
337 |
for cube in cubes: |
|
338 |
cube = CW_MIGRATION_MAP.get(cube, cube) |
|
339 |
deps = cls.cube_dependencies(cube) + \ |
|
340 |
cls.cube_recommends(cube) |
|
341 |
graph[cube] = set(dep for dep in deps if dep in cubes) |
|
342 |
cycles = get_cycles(graph) |
|
343 |
if cycles: |
|
344 |
cycles = '\n'.join(' -> '.join(cycle) for cycle in cycles) |
|
345 |
raise ConfigurationError('cycles in cubes dependencies: %s' |
|
346 |
% cycles) |
|
347 |
cubes = [] |
|
348 |
while graph: |
|
349 |
# sorted to get predictable results |
|
350 |
for cube, deps in sorted(graph.items()): |
|
351 |
if not deps: |
|
352 |
cubes.append(cube) |
|
353 |
del graph[cube] |
|
354 |
for deps in graph.itervalues(): |
|
355 |
try: |
|
356 |
deps.remove(cube) |
|
357 |
except KeyError: |
|
358 |
continue |
|
359 |
return tuple(reversed(cubes)) |
|
1446 | 360 |
|
0 | 361 |
@classmethod |
362 |
def cls_adjust_sys_path(cls): |
|
363 |
"""update python path if necessary""" |
|
1023
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
364 |
cubes_parent_dir = normpath(join(cls.CUBES_DIR, '..')) |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
365 |
if not cubes_parent_dir in sys.path: |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
366 |
sys.path.insert(0, cubes_parent_dir) |
0 | 367 |
try: |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
368 |
import cubes |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
369 |
cubes.__path__ = cls.cubes_search_path() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
370 |
except ImportError: |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
371 |
return # cubes dir doesn't exists |
0 | 372 |
|
373 |
@classmethod |
|
374 |
def load_cwctl_plugins(cls): |
|
375 |
from logilab.common.modutils import load_module_from_file |
|
376 |
cls.cls_adjust_sys_path() |
|
377 |
for ctlfile in ('web/webctl.py', 'etwist/twctl.py', |
|
378 |
'server/serverctl.py', 'hercule.py', |
|
379 |
'devtools/devctl.py', 'goa/goactl.py'): |
|
380 |
if exists(join(CW_SOFTWARE_ROOT, ctlfile)): |
|
381 |
load_module_from_file(join(CW_SOFTWARE_ROOT, ctlfile)) |
|
382 |
cls.info('loaded cubicweb-ctl plugin %s', ctlfile) |
|
383 |
for cube in cls.available_cubes(): |
|
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
384 |
pluginfile = join(cls.cube_dir(cube), 'ecplugin.py') |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
436
diff
changeset
|
385 |
initfile = join(cls.cube_dir(cube), '__init__.py') |
0 | 386 |
if exists(pluginfile): |
387 |
try: |
|
388 |
__import__('cubes.%s.ecplugin' % cube) |
|
389 |
cls.info('loaded cubicweb-ctl plugin from %s', cube) |
|
390 |
except: |
|
391 |
cls.exception('while loading plugin %s', pluginfile) |
|
392 |
elif exists(initfile): |
|
393 |
try: |
|
394 |
__import__('cubes.%s' % cube) |
|
395 |
except: |
|
396 |
cls.exception('while loading cube %s', cube) |
|
397 |
else: |
|
1446 | 398 |
cls.warning('no __init__ file in cube %s', cube) |
0 | 399 |
|
400 |
@classmethod |
|
401 |
def init_available_cubes(cls): |
|
402 |
"""cubes may register some sources (svnfile for instance) in their |
|
403 |
__init__ file, so they should be loaded early in the startup process |
|
404 |
""" |
|
405 |
for cube in cls.available_cubes(): |
|
406 |
try: |
|
407 |
__import__('cubes.%s' % cube) |
|
408 |
except Exception, ex: |
|
409 |
cls.warning("can't init cube %s: %s", cube, ex) |
|
1446 | 410 |
|
0 | 411 |
cubicweb_vobject_path = set(['entities']) |
412 |
cube_vobject_path = set(['entities']) |
|
413 |
||
414 |
@classmethod |
|
415 |
def build_vregistry_path(cls, templpath, evobjpath=None, tvobjpath=None): |
|
416 |
"""given a list of directories, return a list of sub files and |
|
417 |
directories that should be loaded by the application objects registry. |
|
418 |
||
419 |
:param evobjpath: |
|
420 |
optional list of sub-directories (or files without the .py ext) of |
|
421 |
the cubicweb library that should be tested and added to the output list |
|
422 |
if they exists. If not give, default to `cubicweb_vobject_path` class |
|
423 |
attribute. |
|
424 |
:param tvobjpath: |
|
425 |
optional list of sub-directories (or files without the .py ext) of |
|
426 |
directories given in `templpath` that should be tested and added to |
|
427 |
the output list if they exists. If not give, default to |
|
428 |
`cube_vobject_path` class attribute. |
|
429 |
""" |
|
430 |
vregpath = cls.build_vregistry_cubicweb_path(evobjpath) |
|
431 |
vregpath += cls.build_vregistry_cube_path(templpath, tvobjpath) |
|
432 |
return vregpath |
|
433 |
||
434 |
@classmethod |
|
435 |
def build_vregistry_cubicweb_path(cls, evobjpath=None): |
|
436 |
vregpath = [] |
|
437 |
if evobjpath is None: |
|
438 |
evobjpath = cls.cubicweb_vobject_path |
|
439 |
for subdir in evobjpath: |
|
440 |
path = join(CW_SOFTWARE_ROOT, subdir) |
|
441 |
if exists(path): |
|
442 |
vregpath.append(path) |
|
443 |
return vregpath |
|
444 |
||
445 |
@classmethod |
|
446 |
def build_vregistry_cube_path(cls, templpath, tvobjpath=None): |
|
447 |
vregpath = [] |
|
448 |
if tvobjpath is None: |
|
449 |
tvobjpath = cls.cube_vobject_path |
|
450 |
for directory in templpath: |
|
451 |
for subdir in tvobjpath: |
|
452 |
path = join(directory, subdir) |
|
453 |
if exists(path): |
|
454 |
vregpath.append(path) |
|
455 |
elif exists(path + '.py'): |
|
456 |
vregpath.append(path + '.py') |
|
457 |
return vregpath |
|
1446 | 458 |
|
0 | 459 |
def __init__(self): |
460 |
ConfigurationMixIn.__init__(self) |
|
461 |
self.adjust_sys_path() |
|
462 |
self.load_defaults() |
|
1446 | 463 |
self.translations = {} |
0 | 464 |
|
465 |
def adjust_sys_path(self): |
|
466 |
self.cls_adjust_sys_path() |
|
1446 | 467 |
|
468 |
def init_log(self, logthreshold=None, debug=False, |
|
0 | 469 |
logfile=None, syslog=False): |
470 |
"""init the log service""" |
|
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
471 |
if logthreshold is None: |
0 | 472 |
if debug: |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
473 |
logthreshold = 'DEBUG' |
0 | 474 |
else: |
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
475 |
logthreshold = self['log-threshold'] |
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
476 |
init_log(debug, syslog, logthreshold, logfile, self.log_format) |
0 | 477 |
# configure simpleTal logger |
478 |
logging.getLogger('simpleTAL').setLevel(logging.ERROR) |
|
479 |
||
480 |
def vregistry_path(self): |
|
481 |
"""return a list of files or directories where the registry will look |
|
482 |
for application objects. By default return nothing in NoApp config. |
|
483 |
""" |
|
484 |
return [] |
|
1446 | 485 |
|
0 | 486 |
def eproperty_definitions(self): |
487 |
cfg = self.persistent_options_configuration() |
|
488 |
for section, options in cfg.options_by_section(): |
|
489 |
section = section.lower() |
|
490 |
for optname, optdict, value in options: |
|
491 |
key = '%s.%s' % (section, optname) |
|
492 |
type, vocab = self.map_option(optdict) |
|
493 |
default = cfg.option_default(optname, optdict) |
|
494 |
pdef = {'type': type, 'vocabulary': vocab, 'default': default, |
|
495 |
'help': optdict['help'], |
|
496 |
'sitewide': optdict.get('sitewide', False)} |
|
497 |
yield key, pdef |
|
1446 | 498 |
|
0 | 499 |
def map_option(self, optdict): |
500 |
try: |
|
501 |
vocab = optdict['choices'] |
|
502 |
except KeyError: |
|
503 |
vocab = optdict.get('vocabulary') |
|
504 |
if isinstance(vocab, Method): |
|
505 |
vocab = getattr(self, vocab.method, ()) |
|
506 |
return CFGTYPE2ETYPE_MAP[optdict['type']], vocab |
|
507 |
||
1446 | 508 |
|
0 | 509 |
class CubicWebConfiguration(CubicWebNoAppConfiguration): |
510 |
"""base class for cubicweb server and web configurations""" |
|
1446 | 511 |
|
1170
a7c089405185
refactor to avoid having to define CW_INSTANCE_DATA when CW_REGISTRY is set
sylvain.thenault@logilab.fr
parents:
1039
diff
changeset
|
512 |
INSTANCE_DATA_DIR = None |
0 | 513 |
if CubicWebNoAppConfiguration.mode == 'test': |
514 |
root = os.environ['APYCOT_ROOT'] |
|
515 |
REGISTRY_DIR = '%s/etc/cubicweb.d/' % root |
|
516 |
RUNTIME_DIR = '/tmp/' |
|
517 |
MIGRATION_DIR = '%s/local/share/cubicweb/migration/' % root |
|
518 |
if not exists(REGISTRY_DIR): |
|
519 |
os.makedirs(REGISTRY_DIR) |
|
520 |
elif CubicWebNoAppConfiguration.mode == 'dev': |
|
521 |
REGISTRY_DIR = expanduser('~/etc/cubicweb.d/') |
|
522 |
RUNTIME_DIR = '/tmp/' |
|
523 |
MIGRATION_DIR = join(CW_SOFTWARE_ROOT, 'misc', 'migration') |
|
524 |
else: #mode = 'installed' |
|
525 |
REGISTRY_DIR = '/etc/cubicweb.d/' |
|
526 |
INSTANCE_DATA_DIR = '/var/lib/cubicweb/instances/' |
|
527 |
RUNTIME_DIR = '/var/run/cubicweb/' |
|
528 |
MIGRATION_DIR = '/usr/share/cubicweb/migration/' |
|
529 |
||
530 |
# for some commands (creation...) we don't want to initialize gettext |
|
531 |
set_language = True |
|
532 |
# set this to true to avoid false error message while creating an application |
|
533 |
creating = False |
|
1446 | 534 |
|
0 | 535 |
options = CubicWebNoAppConfiguration.options + ( |
536 |
('log-file', |
|
537 |
{'type' : 'string', |
|
538 |
'default': Method('default_log_file'), |
|
539 |
'help': 'file where output logs should be written', |
|
540 |
'group': 'main', 'inputlevel': 2, |
|
541 |
}), |
|
542 |
# email configuration |
|
543 |
('smtp-host', |
|
544 |
{'type' : 'string', |
|
545 |
'default': 'mail', |
|
546 |
'help': 'hostname of the SMTP mail server', |
|
547 |
'group': 'email', 'inputlevel': 1, |
|
548 |
}), |
|
549 |
('smtp-port', |
|
550 |
{'type' : 'int', |
|
551 |
'default': 25, |
|
552 |
'help': 'listening port of the SMTP mail server', |
|
553 |
'group': 'email', 'inputlevel': 1, |
|
554 |
}), |
|
555 |
('sender-name', |
|
556 |
{'type' : 'string', |
|
1446 | 557 |
'default': Method('default_application_id'), |
0 | 558 |
'help': 'name used as HELO name for outgoing emails from the \ |
559 |
repository.', |
|
560 |
'group': 'email', 'inputlevel': 2, |
|
561 |
}), |
|
562 |
('sender-addr', |
|
563 |
{'type' : 'string', |
|
564 |
'default': 'devel@logilab.fr', |
|
565 |
'help': 'email address used as HELO address for outgoing emails from \ |
|
566 |
the repository', |
|
567 |
'group': 'email', 'inputlevel': 1, |
|
568 |
}), |
|
569 |
) |
|
570 |
||
571 |
@classmethod |
|
572 |
def runtime_dir(cls): |
|
573 |
"""run time directory for pid file...""" |
|
574 |
return env_path('CW_RUNTIME', cls.RUNTIME_DIR, 'run time') |
|
1446 | 575 |
|
0 | 576 |
@classmethod |
577 |
def registry_dir(cls): |
|
578 |
"""return the control directory""" |
|
579 |
return env_path('CW_REGISTRY', cls.REGISTRY_DIR, 'registry') |
|
580 |
||
581 |
@classmethod |
|
582 |
def instance_data_dir(cls): |
|
583 |
"""return the instance data directory""" |
|
1170
a7c089405185
refactor to avoid having to define CW_INSTANCE_DATA when CW_REGISTRY is set
sylvain.thenault@logilab.fr
parents:
1039
diff
changeset
|
584 |
return env_path('CW_INSTANCE_DATA', |
a7c089405185
refactor to avoid having to define CW_INSTANCE_DATA when CW_REGISTRY is set
sylvain.thenault@logilab.fr
parents:
1039
diff
changeset
|
585 |
cls.INSTANCE_DATA_DIR or cls.REGISTRY_DIR, |
0 | 586 |
'additional data') |
1446 | 587 |
|
0 | 588 |
@classmethod |
589 |
def migration_scripts_dir(cls): |
|
590 |
"""cubicweb migration scripts directory""" |
|
591 |
return env_path('CW_MIGRATION', cls.MIGRATION_DIR, 'migration') |
|
592 |
||
593 |
@classmethod |
|
594 |
def config_for(cls, appid, config=None): |
|
595 |
"""return a configuration instance for the given application identifier |
|
596 |
""" |
|
597 |
config = config or guess_configuration(cls.application_home(appid)) |
|
598 |
configcls = configuration_cls(config) |
|
599 |
return configcls(appid) |
|
1446 | 600 |
|
0 | 601 |
@classmethod |
602 |
def possible_configurations(cls, appid): |
|
603 |
"""return the name of possible configurations for the given |
|
604 |
application id |
|
605 |
""" |
|
606 |
home = cls.application_home(appid) |
|
607 |
return possible_configurations(home) |
|
1446 | 608 |
|
0 | 609 |
@classmethod |
610 |
def application_home(cls, appid): |
|
611 |
"""return the home directory of the application with the given |
|
612 |
application id |
|
613 |
""" |
|
614 |
home = join(cls.registry_dir(), appid) |
|
615 |
if not exists(home): |
|
616 |
raise ConfigurationError('no such application %s (check it exists with "cubicweb-ctl list")' % appid) |
|
617 |
return home |
|
618 |
||
619 |
MODES = ('common', 'repository', 'Any', 'web') |
|
620 |
MCOMPAT = {'all-in-one': MODES, |
|
621 |
'repository': ('common', 'repository', 'Any'), |
|
622 |
'twisted' : ('common', 'web'),} |
|
623 |
@classmethod |
|
624 |
def accept_mode(cls, mode): |
|
625 |
#assert mode in cls.MODES, mode |
|
626 |
return mode in cls.MCOMPAT[cls.name] |
|
1446 | 627 |
|
0 | 628 |
# default configuration methods ########################################### |
1446 | 629 |
|
0 | 630 |
def default_application_id(self): |
631 |
"""return the application identifier, useful for option which need this |
|
632 |
as default value |
|
633 |
""" |
|
634 |
return self.appid |
|
635 |
||
636 |
def default_log_file(self): |
|
637 |
"""return default path to the log file of the application'server""" |
|
638 |
if self.mode == 'dev': |
|
639 |
basepath = '/tmp/%s-%s' % (basename(self.appid), self.name) |
|
640 |
path = basepath + '.log' |
|
641 |
i = 1 |
|
642 |
while exists(path) and i < 100: # arbitrary limit to avoid infinite loop |
|
643 |
try: |
|
644 |
file(path, 'a') |
|
645 |
break |
|
646 |
except IOError: |
|
647 |
path = '%s-%s.log' % (basepath, i) |
|
648 |
i += 1 |
|
649 |
return path |
|
650 |
return '/var/log/cubicweb/%s-%s.log' % (self.appid, self.name) |
|
1446 | 651 |
|
0 | 652 |
def default_pid_file(self): |
653 |
"""return default path to the pid file of the application'server""" |
|
654 |
return join(self.runtime_dir(), '%s-%s.pid' % (self.appid, self.name)) |
|
1446 | 655 |
|
0 | 656 |
# instance methods used to get application specific resources ############# |
1446 | 657 |
|
0 | 658 |
def __init__(self, appid): |
659 |
self.appid = appid |
|
660 |
CubicWebNoAppConfiguration.__init__(self) |
|
661 |
self._cubes = None |
|
662 |
self._site_loaded = set() |
|
663 |
self.load_file_configuration(self.main_config_file()) |
|
664 |
||
665 |
def adjust_sys_path(self): |
|
666 |
CubicWebNoAppConfiguration.adjust_sys_path(self) |
|
667 |
# adding apphome to python path is not usually necessary in production |
|
668 |
# environments, but necessary for tests |
|
669 |
if self.apphome and not self.apphome in sys.path: |
|
670 |
sys.path.insert(0, self.apphome) |
|
671 |
||
672 |
@property |
|
673 |
def apphome(self): |
|
674 |
return join(self.registry_dir(), self.appid) |
|
1446 | 675 |
|
0 | 676 |
@property |
677 |
def appdatahome(self): |
|
678 |
return join(self.instance_data_dir(), self.appid) |
|
1446 | 679 |
|
0 | 680 |
def init_cubes(self, cubes): |
1681
1586c0ed9a92
nicer assertion message
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1521
diff
changeset
|
681 |
assert self._cubes is None, self._cubes |
0 | 682 |
self._cubes = self.reorder_cubes(cubes) |
683 |
# load cubes'__init__.py file first |
|
684 |
for cube in cubes: |
|
685 |
__import__('cubes.%s' % cube) |
|
686 |
self.load_site_cubicweb() |
|
687 |
# reload config file in cases options are defined in cubes __init__ |
|
688 |
# or site_cubicweb files |
|
689 |
self.load_file_configuration(self.main_config_file()) |
|
690 |
# configuration initialization hook |
|
691 |
self.load_configuration() |
|
1446 | 692 |
|
0 | 693 |
def cubes(self): |
694 |
"""return the list of cubes used by this instance |
|
695 |
||
696 |
result is ordered from the top level cubes to inner dependencies |
|
697 |
cubes |
|
698 |
""" |
|
699 |
assert self._cubes is not None |
|
700 |
return self._cubes |
|
1446 | 701 |
|
0 | 702 |
def cubes_path(self): |
703 |
"""return the list of path to cubes used by this instance, from outer |
|
704 |
most to inner most cubes |
|
705 |
""" |
|
706 |
return [self.cube_dir(p) for p in self.cubes()] |
|
707 |
||
708 |
def add_cubes(self, cubes): |
|
709 |
"""add given cubes to the list of used cubes""" |
|
710 |
if not isinstance(cubes, list): |
|
711 |
cubes = list(cubes) |
|
712 |
self._cubes = self.reorder_cubes(list(self._cubes) + cubes) |
|
1446 | 713 |
|
0 | 714 |
def main_config_file(self): |
715 |
"""return application's control configuration file""" |
|
716 |
return join(self.apphome, '%s.conf' % self.name) |
|
1446 | 717 |
|
0 | 718 |
def save(self): |
719 |
"""write down current configuration""" |
|
720 |
self.generate_config(open(self.main_config_file(), 'w')) |
|
721 |
||
722 |
@cached |
|
723 |
def instance_md5_version(self): |
|
724 |
import md5 |
|
725 |
infos = [] |
|
726 |
for pkg in self.cubes(): |
|
727 |
version = self.cube_version(pkg) |
|
728 |
infos.append('%s-%s' % (pkg, version)) |
|
729 |
return md5.new(';'.join(infos)).hexdigest() |
|
1446 | 730 |
|
0 | 731 |
def load_site_cubicweb(self): |
732 |
"""load (web?) application's specific site_cubicweb file""" |
|
733 |
for path in reversed([self.apphome] + self.cubes_path()): |
|
734 |
sitefile = join(path, 'site_cubicweb.py') |
|
735 |
if exists(sitefile) and not sitefile in self._site_loaded: |
|
736 |
self._load_site_cubicweb(sitefile) |
|
737 |
self._site_loaded.add(sitefile) |
|
738 |
else: |
|
739 |
sitefile = join(path, 'site_erudi.py') |
|
740 |
if exists(sitefile) and not sitefile in self._site_loaded: |
|
741 |
self._load_site_cubicweb(sitefile) |
|
742 |
self._site_loaded.add(sitefile) |
|
743 |
self.warning('site_erudi.py is deprecated, should be renamed to site_cubicweb.py') |
|
1446 | 744 |
|
0 | 745 |
def _load_site_cubicweb(self, sitefile): |
746 |
context = {} |
|
747 |
execfile(sitefile, context, context) |
|
748 |
self.info('%s loaded', sitefile) |
|
749 |
# cube specific options |
|
750 |
if context.get('options'): |
|
751 |
self.register_options(context['options']) |
|
752 |
self.load_defaults() |
|
1446 | 753 |
|
0 | 754 |
def load_configuration(self): |
755 |
"""load application's configuration files""" |
|
756 |
super(CubicWebConfiguration, self).load_configuration() |
|
757 |
if self.apphome and self.set_language: |
|
758 |
# init gettext |
|
759 |
self._set_language() |
|
1446 | 760 |
|
0 | 761 |
def init_log(self, logthreshold=None, debug=False, force=False): |
762 |
"""init the log service""" |
|
763 |
if not force and hasattr(self, '_logging_initialized'): |
|
764 |
return |
|
765 |
self._logging_initialized = True |
|
766 |
CubicWebNoAppConfiguration.init_log(self, logthreshold, debug, |
|
767 |
logfile=self.get('log-file')) |
|
768 |
# read a config file if it exists |
|
769 |
logconfig = join(self.apphome, 'logging.conf') |
|
770 |
if exists(logconfig): |
|
771 |
logging.fileConfig(logconfig) |
|
772 |
||
773 |
def available_languages(self, *args): |
|
774 |
"""return available translation for an application, by looking for |
|
775 |
compiled catalog |
|
776 |
||
777 |
take *args to be usable as a vocabulary method |
|
778 |
""" |
|
779 |
from glob import glob |
|
780 |
yield 'en' # ensure 'en' is yielded even if no .mo found |
|
781 |
for path in glob(join(self.apphome, 'i18n', |
|
782 |
'*', 'LC_MESSAGES', 'cubicweb.mo')): |
|
783 |
lang = path.split(os.sep)[-3] |
|
784 |
if lang != 'en': |
|
785 |
yield lang |
|
1446 | 786 |
|
0 | 787 |
def _set_language(self): |
788 |
"""set language for gettext""" |
|
789 |
from gettext import translation |
|
790 |
path = join(self.apphome, 'i18n') |
|
791 |
for language in self.available_languages(): |
|
792 |
self.info("loading language %s", language) |
|
793 |
try: |
|
794 |
tr = translation('cubicweb', path, languages=[language]) |
|
795 |
self.translations[language] = tr.ugettext |
|
796 |
except (ImportError, AttributeError, IOError): |
|
797 |
self.exception('localisation support error for language %s', |
|
1446 | 798 |
language) |
799 |
||
0 | 800 |
def vregistry_path(self): |
801 |
"""return a list of files or directories where the registry will look |
|
802 |
for application objects |
|
803 |
""" |
|
804 |
templpath = list(reversed(self.cubes_path())) |
|
805 |
if self.apphome: # may be unset in tests |
|
806 |
templpath.append(self.apphome) |
|
807 |
return self.build_vregistry_path(templpath) |
|
808 |
||
809 |
def set_sources_mode(self, sources): |
|
810 |
if not 'all' in sources: |
|
811 |
print 'warning: ignoring specified sources, requires a repository '\ |
|
812 |
'configuration' |
|
1446 | 813 |
|
0 | 814 |
def migration_handler(self): |
815 |
"""return a migration handler instance""" |
|
816 |
from cubicweb.common.migration import MigrationHelper |
|
817 |
return MigrationHelper(self, verbosity=self.verbosity) |
|
818 |
||
819 |
def i18ncompile(self, langs=None): |
|
820 |
from cubicweb.common import i18n |
|
821 |
if langs is None: |
|
822 |
langs = self.available_languages() |
|
823 |
i18ndir = join(self.apphome, 'i18n') |
|
824 |
if not exists(i18ndir): |
|
825 |
create_dir(i18ndir) |
|
826 |
sourcedirs = [join(path, 'i18n') for path in self.cubes_path()] |
|
827 |
sourcedirs.append(self.i18n_lib_dir()) |
|
828 |
return i18n.compile_i18n_catalogs(sourcedirs, i18ndir, langs) |
|
829 |
||
180
8bcebdb5f55d
code moved to logilab.common.logging_ext
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
140
diff
changeset
|
830 |
set_log_methods(CubicWebConfiguration, logging.getLogger('cubicweb.configuration')) |
1446 | 831 |
|
0 | 832 |
# alias to get a configuration instance from an application id |
1446 | 833 |
application_configuration = CubicWebConfiguration.config_for |
0 | 834 |