24 import os |
24 import os |
25 from os.path import join, exists, split |
25 from os.path import join, exists, split |
26 from warnings import warn |
26 from warnings import warn |
27 |
27 |
28 from logilab.common.decorators import cached |
28 from logilab.common.decorators import cached |
|
29 from logilab.common.deprecation import deprecated |
29 |
30 |
30 from cubicweb.toolsutils import read_config |
31 from cubicweb.toolsutils import read_config |
31 from cubicweb.cwconfig import CubicWebConfiguration, register_persistent_options, merge_options |
32 from cubicweb.cwconfig import CubicWebConfiguration, register_persistent_options, merge_options |
32 |
33 |
33 |
34 |
251 user, passwd = None, None |
252 user, passwd = None, None |
252 if user is not None: |
253 if user is not None: |
253 user = unicode(user) |
254 user = unicode(user) |
254 return user, passwd |
255 return user, passwd |
255 |
256 |
256 def has_resource(self, rid): |
|
257 """return true if an external resource is defined""" |
|
258 return bool(self.uiprops.get(rid)) |
|
259 |
|
260 @cached |
|
261 def locate_resource(self, rid): |
257 def locate_resource(self, rid): |
262 """return the directory where the given resource may be found""" |
258 """return the directory where the given resource may be found""" |
263 return self._fs_locate(rid, 'data') |
259 return self._fs_locate(rid, 'data') |
264 |
260 |
265 @cached |
|
266 def locate_doc_file(self, fname): |
261 def locate_doc_file(self, fname): |
267 """return the directory where the given resource may be found""" |
262 """return the directory where the given resource may be found""" |
268 return self._fs_locate(fname, 'wdoc') |
263 return self._fs_locate(fname, 'wdoc') |
269 |
264 |
270 def _fs_locate(self, rid, rdirectory): |
265 @cached |
|
266 def _fs_path_locate(self, rid, rdirectory): |
271 """return the directory where the given resource may be found""" |
267 """return the directory where the given resource may be found""" |
272 path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())] |
268 path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())] |
273 for directory in path: |
269 for directory in path: |
274 if exists(join(directory, rdirectory, rid)): |
270 if exists(join(directory, rdirectory, rid)): |
275 if rdirectory == 'data' and rid.endswith('.css'): |
271 return directory |
276 return self.uiprops.process_resource(join(directory, rdirectory), |
272 |
277 rid) |
273 def _fs_locate(self, rid, rdirectory): |
278 return join(directory, rdirectory) |
274 """return the directory where the given resource may be found""" |
|
275 directory = self._fs_path_locate(rid, rdirectory) |
|
276 if directory is None: |
|
277 return None |
|
278 if rdirectory == 'data' and rid.endswith('.css'): |
|
279 return self.uiprops.process_resource(join(directory, rdirectory), rid) |
|
280 return join(directory, rdirectory) |
279 |
281 |
280 def locate_all_files(self, rid, rdirectory='wdoc'): |
282 def locate_all_files(self, rid, rdirectory='wdoc'): |
281 """return all files corresponding to the given resource""" |
283 """return all files corresponding to the given resource""" |
282 path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())] |
284 path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())] |
283 for directory in path: |
285 for directory in path: |
317 data=lambda x: self.datadir_url + x, |
319 data=lambda x: self.datadir_url + x, |
318 datadir_url=self.datadir_url[:-1]) |
320 datadir_url=self.datadir_url[:-1]) |
319 libuiprops = join(self.shared_dir(), 'data', 'uiprops.py') |
321 libuiprops = join(self.shared_dir(), 'data', 'uiprops.py') |
320 self.uiprops.load(libuiprops) |
322 self.uiprops.load(libuiprops) |
321 for path in reversed([self.apphome] + self.cubes_path()): |
323 for path in reversed([self.apphome] + self.cubes_path()): |
322 self._load_ui_properties(join(path, 'data')) |
324 self._load_ui_properties(path) |
323 self._load_ui_properties(self.apphome) |
325 self._load_ui_properties(self.apphome) |
324 |
326 |
325 def _load_ui_properties(self, path): |
327 def _load_ui_properties(self, path): |
326 resourcesfile = join(path, 'external_resources') |
328 resourcesfile = join(path, 'data', 'external_resources') |
327 if exists(resourcesfile): |
329 if exists(resourcesfile): |
328 warn('[3.9] %s file is deprecated, use an uiprops.py file' |
330 warn('[3.9] %s file is deprecated, use an uiprops.py file' |
329 % resourcesfile, DeprecationWarning) |
331 % resourcesfile, DeprecationWarning) |
330 for rid, val in read_config(resourcesfile).iteritems(): |
332 for rid, val in read_config(resourcesfile).iteritems(): |
331 if rid in ('STYLESHEETS', 'STYLESHEETS_PRINT', |
333 if rid in ('STYLESHEETS', 'STYLESHEETS_PRINT', |