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