author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 24 Feb 2010 15:00:37 +0100 | |
branch | stable |
changeset 4694 | c19366a12281 |
parent 4595 | bb08a75832e6 |
child 4719 | aaed3f813ef8 |
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 |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3642
diff
changeset
|
4 |
:copyright: 2001-2010 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 |
|
3642 | 15 |
from logilab.common.decorators import cached |
0 | 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 |
}), |
|
89 |
# web configuration |
|
90 |
('https-url', |
|
91 |
{'type' : 'string', |
|
92 |
'default': None, |
|
93 |
'help': 'web server root url on https. By specifying this option your '\ |
|
94 |
'site can be available as an http and https site. Authenticated users '\ |
|
95 |
'will in this case be authenticated and once done navigate through the '\ |
|
96 |
'https site. IMPORTANTE NOTE: to do this work, you should have your '\ |
|
97 |
'apache redirection include "https" as base url path so cubicweb can '\ |
|
98 |
'differentiate between http vs https access. For instance: \n'\ |
|
99 |
'RewriteRule ^/demo/(.*) http://127.0.0.1:8080/https/$1 [L,P]\n'\ |
|
100 |
'where the cubicweb web server is listening on port 8080.', |
|
101 |
'group': 'main', 'inputlevel': 2, |
|
102 |
}), |
|
103 |
('auth-mode', |
|
104 |
{'type' : 'choice', |
|
105 |
'choices' : ('cookie', 'http'), |
|
106 |
'default': 'cookie', |
|
107 |
'help': 'authentication mode (cookie / http)', |
|
108 |
'group': 'web', 'inputlevel': 1, |
|
109 |
}), |
|
110 |
('realm', |
|
111 |
{'type' : 'string', |
|
112 |
'default': 'cubicweb', |
|
113 |
'help': 'realm to use on HTTP authentication mode', |
|
114 |
'group': 'web', 'inputlevel': 2, |
|
115 |
}), |
|
116 |
('http-session-time', |
|
117 |
{'type' : 'int', |
|
118 |
'default': 0, |
|
119 |
'help': 'duration in seconds for HTTP sessions. 0 mean no expiration. '\ |
|
120 |
'Should be greater than RQL server\'s session-time.', |
|
121 |
'group': 'web', 'inputlevel': 2, |
|
122 |
}), |
|
123 |
('cleanup-session-time', |
|
124 |
{'type' : 'int', |
|
125 |
'default': 43200, |
|
126 |
'help': 'duration in seconds for which unused connections should be '\ |
|
127 |
'closed, to limit memory consumption. This is different from '\ |
|
128 |
'http-session-time since in some cases you may have an unexpired http '\ |
|
129 |
'session (e.g. valid session cookie) which will trigger transparent '\ |
|
130 |
'creation of a new session. In other cases, sessions may never expire \ |
|
131 |
and cause memory leak. Should be smaller than http-session-time, '\ |
|
132 |
'unless it\'s 0. Default to 12 h.', |
|
133 |
'group': 'web', 'inputlevel': 2, |
|
134 |
}), |
|
135 |
('cleanup-anonymous-session-time', |
|
136 |
{'type' : 'int', |
|
137 |
'default': 120, |
|
138 |
'help': 'Same as cleanup-session-time but specific to anonymous '\ |
|
139 |
'sessions. Default to 2 min.', |
|
140 |
'group': 'web', 'inputlevel': 2, |
|
141 |
}), |
|
2552
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
142 |
('force-html-content-type', |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
143 |
{'type' : 'yn', |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
144 |
'default': False, |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
145 |
'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
|
146 |
'deduction of an appropriate content type', |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
147 |
'group': 'web', 'inputlevel': 2, |
1ea2f2ff5dca
add force-html-content-type config boolean variable
Florent <florent@secondweb.fr>
parents:
2476
diff
changeset
|
148 |
}), |
0 | 149 |
('embed-allowed', |
150 |
{'type' : 'regexp', |
|
151 |
'default': None, |
|
152 |
'help': 'regular expression matching URLs that may be embeded. \ |
|
153 |
leave it blank if you don\'t want the embedding feature, or set it to ".*" \ |
|
154 |
if you want to allow everything', |
|
155 |
'group': 'web', 'inputlevel': 1, |
|
156 |
}), |
|
157 |
('submit-mail', |
|
158 |
{'type' : 'string', |
|
159 |
'default': None, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
160 |
'help': ('Mail used as recipient to report bug in this instance, ' |
0 | 161 |
'if you want this feature on'), |
162 |
'group': 'web', 'inputlevel': 2, |
|
163 |
}), |
|
164 |
||
165 |
('language-negociation', |
|
166 |
{'type' : 'yn', |
|
167 |
'default': True, |
|
168 |
'help': 'use Accept-Language http header to try to set user '\ |
|
169 |
'interface\'s language according to browser defined preferences', |
|
170 |
'group': 'web', 'inputlevel': 2, |
|
171 |
}), |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
172 |
|
0 | 173 |
('print-traceback', |
174 |
{'type' : 'yn', |
|
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3539
diff
changeset
|
175 |
'default': CubicWebConfiguration.mode != 'system', |
0 | 176 |
'help': 'print the traceback on the error page when an error occured', |
177 |
'group': 'web', 'inputlevel': 2, |
|
178 |
}), |
|
4595
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
179 |
|
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
180 |
('captcha-font-file', |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
181 |
{'type' : 'string', |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
182 |
'default': join(CubicWebConfiguration.shared_dir(), 'data', 'porkys.ttf'), |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
183 |
'help': 'True type font to use for captcha image generation (you \ |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
184 |
must have the python imaging library installed to use captcha)', |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
185 |
'group': 'web', 'inputlevel': 2, |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
186 |
}), |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
187 |
('captcha-font-size', |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
188 |
{'type' : 'int', |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
189 |
'default': 25, |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
190 |
'help': 'Font size to use for captcha image generation (you must \ |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
191 |
have the python imaging library installed to use captcha)', |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
192 |
'group': 'web', 'inputlevel': 2, |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
193 |
}), |
bb08a75832e6
backport crypto/captcha utilities from the registration cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
194 |
|
0 | 195 |
)) |
196 |
||
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
|
197 |
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
|
198 |
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
|
199 |
|
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
|
200 |
def eproperty_definitions(self): |
893 | 201 |
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
|
202 |
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
|
203 |
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
|
204 |
yield key, pdef |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
205 |
|
0 | 206 |
# method used to connect to the repository: 'inmemory' / 'pyro' |
207 |
# Pyro repository by default |
|
208 |
repo_method = 'pyro' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
209 |
|
0 | 210 |
# don't use @cached: we want to be able to disable it while this must still |
211 |
# be cached |
|
212 |
def repository(self, vreg=None): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
213 |
"""return the instance's repository object""" |
0 | 214 |
try: |
215 |
return self.__repo |
|
216 |
except AttributeError: |
|
217 |
from cubicweb.dbapi import get_repository |
|
218 |
if self.repo_method == 'inmemory': |
|
219 |
repo = get_repository('inmemory', vreg=vreg, config=self) |
|
220 |
else: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
221 |
repo = get_repository('pyro', self['pyro-instance-id'], |
0 | 222 |
config=self) |
223 |
self.__repo = repo |
|
224 |
return repo |
|
225 |
||
226 |
def vc_config(self): |
|
227 |
return self.repository().get_versions() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
228 |
|
0 | 229 |
# mapping to external resources (id -> path) (`external_resources` file) ## |
230 |
ext_resources = { |
|
231 |
'FAVICON': 'DATADIR/favicon.ico', |
|
232 |
'LOGO': 'DATADIR/logo.png', |
|
233 |
'RSS_LOGO': 'DATADIR/rss.png', |
|
234 |
'HELP': 'DATADIR/help.png', |
|
235 |
'CALENDAR_ICON': 'DATADIR/calendar.gif', |
|
236 |
'SEARCH_GO':'DATADIR/go.png', |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
237 |
|
0 | 238 |
'FCKEDITOR_PATH': '/usr/share/fckeditor/', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
239 |
|
0 | 240 |
'IE_STYLESHEETS': ['DATADIR/cubicweb.ie.css'], |
241 |
'STYLESHEETS': ['DATADIR/cubicweb.css'], |
|
242 |
'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
|
243 |
|
0 | 244 |
'JAVASCRIPTS': ['DATADIR/jquery.js', |
30
25ef1dddaab8
round corners are back
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
245 |
'DATADIR/jquery.corner.js', |
25ef1dddaab8
round corners are back
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
246 |
'DATADIR/jquery.json.js', |
0 | 247 |
'DATADIR/cubicweb.compat.js', |
248 |
'DATADIR/cubicweb.python.js', |
|
249 |
'DATADIR/cubicweb.htmlhelpers.js'], |
|
250 |
} |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
251 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
252 |
|
0 | 253 |
def anonymous_user(self): |
254 |
"""return a login and password to use for anonymous users. None |
|
255 |
may be returned for both if anonymous connections are not allowed |
|
256 |
""" |
|
257 |
try: |
|
258 |
user = self['anonymous-user'] |
|
259 |
passwd = self['anonymous-password'] |
|
260 |
except KeyError: |
|
261 |
user, passwd = None, None |
|
262 |
if user is not None: |
|
263 |
user = unicode(user) |
|
264 |
return user, passwd |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
265 |
|
0 | 266 |
def has_resource(self, rid): |
267 |
"""return true if an external resource is defined""" |
|
268 |
return bool(self.ext_resources.get(rid)) |
|
269 |
||
270 |
@cached |
|
271 |
def locate_resource(self, rid): |
|
272 |
"""return the directory where the given resource may be found""" |
|
273 |
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
|
274 |
|
0 | 275 |
@cached |
276 |
def locate_doc_file(self, fname): |
|
277 |
"""return the directory where the given resource may be found""" |
|
278 |
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
|
279 |
|
0 | 280 |
def _fs_locate(self, rid, rdirectory): |
281 |
"""return the directory where the given resource may be found""" |
|
282 |
path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())] |
|
283 |
for directory in path: |
|
284 |
if exists(join(directory, rdirectory, rid)): |
|
285 |
return join(directory, rdirectory) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
286 |
|
0 | 287 |
def locate_all_files(self, rid, rdirectory='wdoc'): |
288 |
"""return all files corresponding to the given resource""" |
|
289 |
path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())] |
|
290 |
for directory in path: |
|
291 |
fpath = join(directory, rdirectory, rid) |
|
292 |
if exists(fpath): |
|
293 |
yield join(fpath) |
|
294 |
||
295 |
def load_configuration(self): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
296 |
"""load instance's configuration files""" |
0 | 297 |
super(WebConfiguration, self).load_configuration() |
298 |
# load external resources definition |
|
299 |
self._build_ext_resources() |
|
300 |
self._init_base_url() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
301 |
|
0 | 302 |
def _init_base_url(self): |
303 |
# normalize base url(s) |
|
304 |
baseurl = self['base-url'] |
|
305 |
if baseurl and baseurl[-1] != '/': |
|
306 |
baseurl += '/' |
|
307 |
self.global_set_option('base-url', baseurl) |
|
308 |
httpsurl = self['https-url'] |
|
309 |
if httpsurl and httpsurl[-1] != '/': |
|
310 |
httpsurl += '/' |
|
311 |
self.global_set_option('https-url', httpsurl) |
|
312 |
||
313 |
def _build_ext_resources(self): |
|
314 |
libresourcesfile = join(self.shared_dir(), 'data', 'external_resources') |
|
315 |
self.ext_resources.update(read_config(libresourcesfile)) |
|
316 |
for path in reversed([self.apphome] + self.cubes_path()): |
|
317 |
resourcesfile = join(path, 'data', 'external_resources') |
|
318 |
if exists(resourcesfile): |
|
319 |
self.debug('loading %s', resourcesfile) |
|
320 |
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
|
321 |
resourcesfile = join(self.apphome, 'external_resources') |
8cd0c2111783
search external_resources in application home
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
151
diff
changeset
|
322 |
if exists(resourcesfile): |
8cd0c2111783
search external_resources in application home
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
151
diff
changeset
|
323 |
self.debug('loading %s', resourcesfile) |
8cd0c2111783
search external_resources in application home
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
151
diff
changeset
|
324 |
self.ext_resources.update(read_config(resourcesfile)) |
0 | 325 |
for resource in ('STYLESHEETS', 'STYLESHEETS_PRINT', |
326 |
'IE_STYLESHEETS', 'JAVASCRIPTS'): |
|
327 |
val = self.ext_resources[resource] |
|
328 |
if isinstance(val, str): |
|
329 |
files = [w.strip() for w in val.split(',') if w.strip()] |
|
330 |
self.ext_resources[resource] = files |
|
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
331 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
332 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
333 |
# static files handling ################################################### |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
334 |
|
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
335 |
@property |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
336 |
def static_directory(self): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
337 |
return join(self.appdatahome, 'static') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
338 |
|
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
339 |
def static_file_exists(self, rpath): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
340 |
return exists(join(self.static_directory, rpath)) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
341 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
342 |
def static_file_open(self, rpath, mode='wb'): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
343 |
staticdir = self.static_directory |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
344 |
rdir, filename = split(rpath) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
345 |
if rdir: |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
346 |
staticdir = join(staticdir, rdir) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
347 |
os.makedirs(staticdir) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
348 |
return file(join(staticdir, filename), mode) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
349 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
350 |
def static_file_add(self, rpath, data): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
351 |
stream = self.static_file_open(rpath) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
352 |
stream.write(data) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
353 |
stream.close() |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
354 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
355 |
def static_file_del(self, rpath): |
447 | 356 |
if self.static_file_exists(rpath): |
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
357 |
os.remove(join(self.static_directory, rpath)) |