equal
deleted
inserted
replaced
21 from cubicweb import _ |
21 from cubicweb import _ |
22 |
22 |
23 import os |
23 import os |
24 import hmac |
24 import hmac |
25 from uuid import uuid4 |
25 from uuid import uuid4 |
26 from os.path import join, exists, split, isdir |
26 from os.path import dirname, join, exists, split, isdir |
27 from warnings import warn |
27 from warnings import warn |
28 |
28 |
29 from six import text_type |
29 from six import text_type |
30 |
30 |
31 from logilab.common.decorators import cached, cachedproperty |
31 from logilab.common.decorators import cached, cachedproperty |
33 from logilab.common.configuration import merge_options |
33 from logilab.common.configuration import merge_options |
34 |
34 |
35 from cubicweb import ConfigurationError |
35 from cubicweb import ConfigurationError |
36 from cubicweb.toolsutils import read_config |
36 from cubicweb.toolsutils import read_config |
37 from cubicweb.cwconfig import CubicWebConfiguration, register_persistent_options |
37 from cubicweb.cwconfig import CubicWebConfiguration, register_persistent_options |
|
38 |
|
39 |
|
40 _DATA_DIR = join(dirname(__file__), 'data') |
38 |
41 |
39 |
42 |
40 register_persistent_options( ( |
43 register_persistent_options( ( |
41 # site-wide only web ui configuration |
44 # site-wide only web ui configuration |
42 ('site-title', |
45 ('site-title', |
202 'group': 'web', 'level': 2, |
205 'group': 'web', 'level': 2, |
203 }), |
206 }), |
204 |
207 |
205 ('captcha-font-file', |
208 ('captcha-font-file', |
206 {'type' : 'string', |
209 {'type' : 'string', |
207 'default': join(CubicWebConfiguration.shared_dir(), 'data', 'porkys.ttf'), |
210 'default': join(_DATA_DIR, 'porkys.ttf'), |
208 'help': 'True type font to use for captcha image generation (you \ |
211 'help': 'True type font to use for captcha image generation (you \ |
209 must have the python imaging library installed to use captcha)', |
212 must have the python imaging library installed to use captcha)', |
210 'group': 'web', 'level': 3, |
213 'group': 'web', 'level': 3, |
211 }), |
214 }), |
212 ('captcha-font-size', |
215 ('captcha-font-size', |
325 return self._fs_locate(fname, 'wdoc')[0] |
328 return self._fs_locate(fname, 'wdoc')[0] |
326 |
329 |
327 @cached |
330 @cached |
328 def _fs_path_locate(self, rid, rdirectory): |
331 def _fs_path_locate(self, rid, rdirectory): |
329 """return the directory where the given resource may be found""" |
332 """return the directory where the given resource may be found""" |
330 path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())] |
333 path = [self.apphome] + self.cubes_path() + [dirname(__file__)] |
331 for directory in path: |
334 for directory in path: |
332 if exists(join(directory, rdirectory, rid)): |
335 if exists(join(directory, rdirectory, rid)): |
333 return directory |
336 return directory |
334 |
337 |
335 def _fs_locate(self, rid, rdirectory): |
338 def _fs_locate(self, rid, rdirectory): |
350 join(directory, rdirectory), rid)), rid |
353 join(directory, rdirectory), rid)), rid |
351 return join(directory, rdirectory), rid |
354 return join(directory, rdirectory), rid |
352 |
355 |
353 def locate_all_files(self, rid, rdirectory='wdoc'): |
356 def locate_all_files(self, rid, rdirectory='wdoc'): |
354 """return all files corresponding to the given resource""" |
357 """return all files corresponding to the given resource""" |
355 path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())] |
358 path = [self.apphome] + self.cubes_path() + [dirname(__file__)] |
356 for directory in path: |
359 for directory in path: |
357 fpath = join(directory, rdirectory, rid) |
360 fpath = join(directory, rdirectory, rid) |
358 if exists(fpath): |
361 if exists(fpath): |
359 yield join(fpath) |
362 yield join(fpath) |
360 |
363 |
397 data=lambda x: self.datadir_url + x, |
400 data=lambda x: self.datadir_url + x, |
398 datadir_url=self.datadir_url[:-1]) |
401 datadir_url=self.datadir_url[:-1]) |
399 self._init_uiprops(self.uiprops) |
402 self._init_uiprops(self.uiprops) |
400 |
403 |
401 def _init_uiprops(self, uiprops): |
404 def _init_uiprops(self, uiprops): |
402 libuiprops = join(self.shared_dir(), 'data', 'uiprops.py') |
405 libuiprops = join(_DATA_DIR, 'uiprops.py') |
403 uiprops.load(libuiprops) |
406 uiprops.load(libuiprops) |
404 for path in reversed([self.apphome] + self.cubes_path()): |
407 for path in reversed([self.apphome] + self.cubes_path()): |
405 self._load_ui_properties_file(uiprops, path) |
408 self._load_ui_properties_file(uiprops, path) |
406 self._load_ui_properties_file(uiprops, self.apphome) |
409 self._load_ui_properties_file(uiprops, self.apphome) |
407 datadir_url = uiprops.context['datadir_url'] |
410 datadir_url = uiprops.context['datadir_url'] |