author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 21 Aug 2009 08:43:28 +0200 | |
branch | 3.5 |
changeset 2945 | f0ab83510477 |
parent 2657 | de974465d381 |
child 3200 | 747d17498cca |
permissions | -rw-r--r-- |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
1 |
"""common web configuration for twisted/modpython instances |
0 | 2 |
|
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
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:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
2087 | 9 |
_ = unicode |
0 | 10 |
|
11 |
import os |
|
1132 | 12 |
from os.path import join, exists, split |
0 | 13 |
|
14 |
from logilab.common.configuration import Method |
|
15 |
from logilab.common.decorators import cached |
|
16 |
||
17 |
from cubicweb.toolsutils import read_config |
|
18 |
from cubicweb.cwconfig import CubicWebConfiguration, register_persistent_options, merge_options |
|
19 |
||
20 |
||
21 |
register_persistent_options( ( |
|
22 |
# site-wide only web ui configuration |
|
23 |
('site-title', |
|
24 |
{'type' : 'string', 'default': 'unset title', |
|
25 |
'help': _('site title'), |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
26 |
'sitewide': True, 'group': 'ui', |
0 | 27 |
}), |
28 |
('main-template', |
|
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
447
diff
changeset
|
29 |
{'type' : 'string', 'default': 'main-template', |
0 | 30 |
'help': _('id of main template used to render pages'), |
31 |
'sitewide': True, 'group': 'ui', |
|
32 |
}), |
|
33 |
# user web ui configuration |
|
34 |
('fckeditor', |
|
35 |
{'type' : 'yn', 'default': True, |
|
36 |
'help': _('should html fields being edited using fckeditor (a HTML ' |
|
37 |
'WYSIWYG editor). You should also select text/html as default ' |
|
38 |
'text format to actually get fckeditor.'), |
|
39 |
'group': 'ui', |
|
40 |
}), |
|
41 |
# navigation configuration |
|
42 |
('page-size', |
|
43 |
{'type' : 'int', 'default': 40, |
|
44 |
'help': _('maximum number of objects displayed by page of results'), |
|
45 |
'group': 'navigation', |
|
46 |
}), |
|
47 |
('related-limit', |
|
48 |
{'type' : 'int', 'default': 8, |
|
49 |
'help': _('maximum number of related entities to display in the primary ' |
|
50 |
'view'), |
|
51 |
'group': 'navigation', |
|
52 |
}), |
|
53 |
('combobox-limit', |
|
54 |
{'type' : 'int', 'default': 20, |
|
55 |
'help': _('maximum number of entities to display in related combo box'), |
|
56 |
'group': 'navigation', |
|
57 |
}), |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
58 |
|
0 | 59 |
)) |
60 |
||
61 |
||
62 |
class WebConfiguration(CubicWebConfiguration): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
63 |
"""the WebConfiguration is a singleton object handling instance's |
0 | 64 |
configuration and preferences |
65 |
""" |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2552
diff
changeset
|
66 |
cubicweb_appobject_path = CubicWebConfiguration.cubicweb_appobject_path | set(['web/views']) |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2552
diff
changeset
|
67 |
cube_appobject_path = CubicWebConfiguration.cube_appobject_path | set(['views']) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
68 |
|
0 | 69 |
options = merge_options(CubicWebConfiguration.options + ( |
70 |
('anonymous-user', |
|
71 |
{'type' : 'string', |
|
72 |
'default': None, |
|
73 |
'help': 'login of the CubicWeb user account to use for anonymous user (if you want to allow anonymous)', |
|
74 |
'group': 'main', 'inputlevel': 1, |
|
75 |
}), |
|
76 |
('anonymous-password', |
|
77 |
{'type' : 'string', |
|
78 |
'default': None, |
|
79 |
'help': 'password of the CubicWeb user account to use for anonymous user, ' |
|
80 |
'if anonymous-user is set', |
|
81 |
'group': 'main', 'inputlevel': 1, |
|
82 |
}), |
|
83 |
('query-log-file', |
|
84 |
{'type' : 'string', |
|
85 |
'default': None, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
86 |
'help': 'web instance query log file', |
0 | 87 |
'group': 'main', 'inputlevel': 2, |
88 |
}), |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
89 |
('pyro-instance-id', |
0 | 90 |
{'type' : 'string', |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
91 |
'default': Method('default_instance_id'), |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
92 |
'help': 'CubicWeb instance identifier in the Pyro name server', |
0 | 93 |
'group': 'pyro-client', 'inputlevel': 1, |
94 |
}), |
|
95 |
# web configuration |
|
96 |
('https-url', |
|
97 |
{'type' : 'string', |
|
98 |
'default': None, |
|
99 |
'help': 'web server root url on https. By specifying this option your '\ |
|
100 |
'site can be available as an http and https site. Authenticated users '\ |
|
101 |
'will in this case be authenticated and once done navigate through the '\ |
|
102 |
'https site. IMPORTANTE NOTE: to do this work, you should have your '\ |
|
103 |
'apache redirection include "https" as base url path so cubicweb can '\ |
|
104 |
'differentiate between http vs https access. For instance: \n'\ |
|
105 |
'RewriteRule ^/demo/(.*) http://127.0.0.1:8080/https/$1 [L,P]\n'\ |
|
106 |
'where the cubicweb web server is listening on port 8080.', |
|
107 |
'group': 'main', 'inputlevel': 2, |
|
108 |
}), |
|
109 |
('auth-mode', |
|
110 |
{'type' : 'choice', |
|
111 |
'choices' : ('cookie', 'http'), |
|
112 |
'default': 'cookie', |
|
113 |
'help': 'authentication mode (cookie / http)', |
|
114 |
'group': 'web', 'inputlevel': 1, |
|
115 |
}), |
|
116 |
('realm', |
|
117 |
{'type' : 'string', |
|
118 |
'default': 'cubicweb', |
|
119 |
'help': 'realm to use on HTTP authentication mode', |
|
120 |
'group': 'web', 'inputlevel': 2, |
|
121 |
}), |
|
122 |
('http-session-time', |
|
123 |
{'type' : 'int', |
|
124 |
'default': 0, |
|
125 |
'help': 'duration in seconds for HTTP sessions. 0 mean no expiration. '\ |
|
126 |
'Should be greater than RQL server\'s session-time.', |
|
127 |
'group': 'web', 'inputlevel': 2, |
|
128 |
}), |
|
129 |
('cleanup-session-time', |
|
130 |
{'type' : 'int', |
|
131 |
'default': 43200, |
|
132 |
'help': 'duration in seconds for which unused connections should be '\ |
|
133 |
'closed, to limit memory consumption. This is different from '\ |
|
134 |
'http-session-time since in some cases you may have an unexpired http '\ |
|
135 |
'session (e.g. valid session cookie) which will trigger transparent '\ |
|
136 |
'creation of a new session. In other cases, sessions may never expire \ |
|
137 |
and cause memory leak. Should be smaller than http-session-time, '\ |
|
138 |
'unless it\'s 0. Default to 12 h.', |
|
139 |
'group': 'web', 'inputlevel': 2, |
|
140 |
}), |
|
141 |
('cleanup-anonymous-session-time', |
|
142 |
{'type' : 'int', |
|
143 |
'default': 120, |
|
144 |
'help': 'Same as cleanup-session-time but specific to anonymous '\ |
|
145 |
'sessions. Default to 2 min.', |
|
146 |
'group': 'web', 'inputlevel': 2, |
|
147 |
}), |
|
2552
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
148 |
('force-html-content-type', |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
149 |
{'type' : 'yn', |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
150 |
'default': False, |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
151 |
'help': 'force text/html content type for your html pages instead of cubicweb user-agent based'\ |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
152 |
'deduction of an appropriate content type', |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
153 |
'group': 'web', 'inputlevel': 2, |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
154 |
}), |
0 | 155 |
('embed-allowed', |
156 |
{'type' : 'regexp', |
|
157 |
'default': None, |
|
158 |
'help': 'regular expression matching URLs that may be embeded. \ |
|
159 |
leave it blank if you don\'t want the embedding feature, or set it to ".*" \ |
|
160 |
if you want to allow everything', |
|
161 |
'group': 'web', 'inputlevel': 1, |
|
162 |
}), |
|
163 |
('submit-url', |
|
164 |
{'type' : 'string', |
|
165 |
'default': Method('default_submit_url'), |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
166 |
'help': ('URL that may be used to report bug in this instance ' |
0 | 167 |
'by direct access to the project\'s (jpl) tracker, ' |
168 |
'if you want this feature on. The url should looks like ' |
|
169 |
'http://mytracker.com/view?__linkto=concerns:1234:subject&etype=Ticket&type=bug&vid=creation ' |
|
170 |
'where 1234 should be replaced by the eid of your project in ' |
|
171 |
'the tracker. If you have no idea about what I\'am talking ' |
|
172 |
'about, you should probably let no value for this option.'), |
|
173 |
'group': 'web', 'inputlevel': 2, |
|
174 |
}), |
|
175 |
('submit-mail', |
|
176 |
{'type' : 'string', |
|
177 |
'default': None, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
178 |
'help': ('Mail used as recipient to report bug in this instance, ' |
0 | 179 |
'if you want this feature on'), |
180 |
'group': 'web', 'inputlevel': 2, |
|
181 |
}), |
|
182 |
||
183 |
('language-negociation', |
|
184 |
{'type' : 'yn', |
|
185 |
'default': True, |
|
186 |
'help': 'use Accept-Language http header to try to set user '\ |
|
187 |
'interface\'s language according to browser defined preferences', |
|
188 |
'group': 'web', 'inputlevel': 2, |
|
189 |
}), |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
190 |
|
0 | 191 |
('print-traceback', |
192 |
{'type' : 'yn', |
|
193 |
'default': not CubicWebConfiguration.mode == 'installed', |
|
194 |
'help': 'print the traceback on the error page when an error occured', |
|
195 |
'group': 'web', 'inputlevel': 2, |
|
196 |
}), |
|
197 |
)) |
|
198 |
||
199 |
def default_submit_url(self): |
|
200 |
try: |
|
201 |
cube = self.cubes()[0] |
|
202 |
cubeeid = self.cube_pkginfo(cube).cube_eid |
|
1149 | 203 |
except Exception: |
0 | 204 |
return None |
205 |
if cubeeid: |
|
206 |
return 'http://intranet.logilab.fr/jpl/view?__linkto=concerns:%s:subject&etype=Ticket&type=bug&vid=creation' % cubeeid |
|
207 |
return None |
|
208 |
||
890
3530baff9120
make fckeditor actually optional, fix its config, avoid needs for a link to fckeditor.js
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
209 |
def fckeditor_installed(self): |
3530baff9120
make fckeditor actually optional, fix its config, avoid needs for a link to fckeditor.js
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
210 |
return exists(self.ext_resources['FCKEDITOR_PATH']) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
211 |
|
890
3530baff9120
make fckeditor actually optional, fix its config, avoid needs for a link to fckeditor.js
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
212 |
def eproperty_definitions(self): |
893 | 213 |
for key, pdef in super(WebConfiguration, self).eproperty_definitions(): |
890
3530baff9120
make fckeditor actually optional, fix its config, avoid needs for a link to fckeditor.js
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
214 |
if key == 'ui.fckeditor' and not self.fckeditor_installed(): |
3530baff9120
make fckeditor actually optional, fix its config, avoid needs for a link to fckeditor.js
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
215 |
continue |
3530baff9120
make fckeditor actually optional, fix its config, avoid needs for a link to fckeditor.js
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
216 |
yield key, pdef |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
217 |
|
0 | 218 |
# method used to connect to the repository: 'inmemory' / 'pyro' |
219 |
# Pyro repository by default |
|
220 |
repo_method = 'pyro' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
221 |
|
0 | 222 |
# don't use @cached: we want to be able to disable it while this must still |
223 |
# be cached |
|
224 |
def repository(self, vreg=None): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
225 |
"""return the instance's repository object""" |
0 | 226 |
try: |
227 |
return self.__repo |
|
228 |
except AttributeError: |
|
229 |
from cubicweb.dbapi import get_repository |
|
230 |
if self.repo_method == 'inmemory': |
|
231 |
repo = get_repository('inmemory', vreg=vreg, config=self) |
|
232 |
else: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
233 |
repo = get_repository('pyro', self['pyro-instance-id'], |
0 | 234 |
config=self) |
235 |
self.__repo = repo |
|
236 |
return repo |
|
237 |
||
238 |
def vc_config(self): |
|
239 |
return self.repository().get_versions() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
240 |
|
0 | 241 |
# mapping to external resources (id -> path) (`external_resources` file) ## |
242 |
ext_resources = { |
|
243 |
'FAVICON': 'DATADIR/favicon.ico', |
|
244 |
'LOGO': 'DATADIR/logo.png', |
|
245 |
'RSS_LOGO': 'DATADIR/rss.png', |
|
246 |
'HELP': 'DATADIR/help.png', |
|
247 |
'CALENDAR_ICON': 'DATADIR/calendar.gif', |
|
248 |
'SEARCH_GO':'DATADIR/go.png', |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
249 |
|
0 | 250 |
'FCKEDITOR_PATH': '/usr/share/fckeditor/', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
251 |
|
0 | 252 |
'IE_STYLESHEETS': ['DATADIR/cubicweb.ie.css'], |
253 |
'STYLESHEETS': ['DATADIR/cubicweb.css'], |
|
254 |
'STYLESHEETS_PRINT': ['DATADIR/cubicweb.print.css'], |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
255 |
|
0 | 256 |
'JAVASCRIPTS': ['DATADIR/jquery.js', |
30
25ef1dddaab8
round corners are back
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
257 |
'DATADIR/jquery.corner.js', |
25ef1dddaab8
round corners are back
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
258 |
'DATADIR/jquery.json.js', |
0 | 259 |
'DATADIR/cubicweb.compat.js', |
260 |
'DATADIR/cubicweb.python.js', |
|
261 |
'DATADIR/cubicweb.htmlhelpers.js'], |
|
262 |
} |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
263 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
264 |
|
0 | 265 |
def anonymous_user(self): |
266 |
"""return a login and password to use for anonymous users. None |
|
267 |
may be returned for both if anonymous connections are not allowed |
|
268 |
""" |
|
269 |
try: |
|
270 |
user = self['anonymous-user'] |
|
271 |
passwd = self['anonymous-password'] |
|
272 |
except KeyError: |
|
273 |
user, passwd = None, None |
|
274 |
if user is not None: |
|
275 |
user = unicode(user) |
|
276 |
return user, passwd |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
277 |
|
0 | 278 |
def has_resource(self, rid): |
279 |
"""return true if an external resource is defined""" |
|
280 |
return bool(self.ext_resources.get(rid)) |
|
281 |
||
282 |
@cached |
|
283 |
def locate_resource(self, rid): |
|
284 |
"""return the directory where the given resource may be found""" |
|
285 |
return self._fs_locate(rid, 'data') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
286 |
|
0 | 287 |
@cached |
288 |
def locate_doc_file(self, fname): |
|
289 |
"""return the directory where the given resource may be found""" |
|
290 |
return self._fs_locate(fname, 'wdoc') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
291 |
|
0 | 292 |
def _fs_locate(self, rid, rdirectory): |
293 |
"""return the directory where the given resource may be found""" |
|
294 |
path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())] |
|
295 |
for directory in path: |
|
296 |
if exists(join(directory, rdirectory, rid)): |
|
297 |
return join(directory, rdirectory) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
298 |
|
0 | 299 |
def locate_all_files(self, rid, rdirectory='wdoc'): |
300 |
"""return all files corresponding to the given resource""" |
|
301 |
path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())] |
|
302 |
for directory in path: |
|
303 |
fpath = join(directory, rdirectory, rid) |
|
304 |
if exists(fpath): |
|
305 |
yield join(fpath) |
|
306 |
||
307 |
def load_configuration(self): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
308 |
"""load instance's configuration files""" |
0 | 309 |
super(WebConfiguration, self).load_configuration() |
310 |
# load external resources definition |
|
311 |
self._build_ext_resources() |
|
312 |
self._init_base_url() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
313 |
|
0 | 314 |
def _init_base_url(self): |
315 |
# normalize base url(s) |
|
316 |
baseurl = self['base-url'] |
|
317 |
if baseurl and baseurl[-1] != '/': |
|
318 |
baseurl += '/' |
|
319 |
self.global_set_option('base-url', baseurl) |
|
320 |
httpsurl = self['https-url'] |
|
321 |
if httpsurl and httpsurl[-1] != '/': |
|
322 |
httpsurl += '/' |
|
323 |
self.global_set_option('https-url', httpsurl) |
|
324 |
||
325 |
def _build_ext_resources(self): |
|
326 |
libresourcesfile = join(self.shared_dir(), 'data', 'external_resources') |
|
327 |
self.ext_resources.update(read_config(libresourcesfile)) |
|
328 |
for path in reversed([self.apphome] + self.cubes_path()): |
|
329 |
resourcesfile = join(path, 'data', 'external_resources') |
|
330 |
if exists(resourcesfile): |
|
331 |
self.debug('loading %s', resourcesfile) |
|
332 |
self.ext_resources.update(read_config(resourcesfile)) |
|
252
8cd0c2111783
search external_resources in application home
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
151
diff
changeset
|
333 |
resourcesfile = join(self.apphome, 'external_resources') |
8cd0c2111783
search external_resources in application home
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
151
diff
changeset
|
334 |
if exists(resourcesfile): |
8cd0c2111783
search external_resources in application home
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
151
diff
changeset
|
335 |
self.debug('loading %s', resourcesfile) |
8cd0c2111783
search external_resources in application home
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
151
diff
changeset
|
336 |
self.ext_resources.update(read_config(resourcesfile)) |
0 | 337 |
for resource in ('STYLESHEETS', 'STYLESHEETS_PRINT', |
338 |
'IE_STYLESHEETS', 'JAVASCRIPTS'): |
|
339 |
val = self.ext_resources[resource] |
|
340 |
if isinstance(val, str): |
|
341 |
files = [w.strip() for w in val.split(',') if w.strip()] |
|
342 |
self.ext_resources[resource] = files |
|
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
343 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
344 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
345 |
# static files handling ################################################### |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
346 |
|
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
347 |
@property |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
348 |
def static_directory(self): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
349 |
return join(self.appdatahome, 'static') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
350 |
|
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
351 |
def static_file_exists(self, rpath): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
352 |
return exists(join(self.static_directory, rpath)) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
353 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
354 |
def static_file_open(self, rpath, mode='wb'): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
355 |
staticdir = self.static_directory |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
356 |
rdir, filename = split(rpath) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
357 |
if rdir: |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
358 |
staticdir = join(staticdir, rdir) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
359 |
os.makedirs(staticdir) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
360 |
return file(join(staticdir, filename), mode) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
361 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
362 |
def static_file_add(self, rpath, data): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
363 |
stream = self.static_file_open(rpath) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
364 |
stream.write(data) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
365 |
stream.close() |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
366 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
367 |
def static_file_del(self, rpath): |
447 | 368 |
if self.static_file_exists(rpath): |
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
369 |
os.remove(join(self.static_directory, rpath)) |