author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Thu, 09 Jul 2009 15:15:18 +0200 | |
branch | stable |
changeset 2356 | ef9e30485ee7 |
parent 2267 | e1d2df3f1091 |
child 2476 | 1294a6bdf3bf |
permissions | -rw-r--r-- |
0 | 1 |
"""common web configuration for twisted/modpython applications |
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): |
|
63 |
"""the WebConfiguration is a singleton object handling application's |
|
64 |
configuration and preferences |
|
65 |
""" |
|
66 |
cubicweb_vobject_path = CubicWebConfiguration.cubicweb_vobject_path | set(['web/views']) |
|
67 |
cube_vobject_path = CubicWebConfiguration.cube_vobject_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, |
|
86 |
'help': 'web application query log file', |
|
87 |
'group': 'main', 'inputlevel': 2, |
|
88 |
}), |
|
89 |
('pyro-application-id', |
|
90 |
{'type' : 'string', |
|
91 |
'default': Method('default_application_id'), |
|
92 |
'help': 'CubicWeb application identifier in the Pyro name server', |
|
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 |
}), |
|
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-url', |
|
157 |
{'type' : 'string', |
|
158 |
'default': Method('default_submit_url'), |
|
159 |
'help': ('URL that may be used to report bug in this application ' |
|
160 |
'by direct access to the project\'s (jpl) tracker, ' |
|
161 |
'if you want this feature on. The url should looks like ' |
|
162 |
'http://mytracker.com/view?__linkto=concerns:1234:subject&etype=Ticket&type=bug&vid=creation ' |
|
163 |
'where 1234 should be replaced by the eid of your project in ' |
|
164 |
'the tracker. If you have no idea about what I\'am talking ' |
|
165 |
'about, you should probably let no value for this option.'), |
|
166 |
'group': 'web', 'inputlevel': 2, |
|
167 |
}), |
|
168 |
('submit-mail', |
|
169 |
{'type' : 'string', |
|
170 |
'default': None, |
|
171 |
'help': ('Mail used as recipient to report bug in this application, ' |
|
172 |
'if you want this feature on'), |
|
173 |
'group': 'web', 'inputlevel': 2, |
|
174 |
}), |
|
175 |
||
176 |
('language-negociation', |
|
177 |
{'type' : 'yn', |
|
178 |
'default': True, |
|
179 |
'help': 'use Accept-Language http header to try to set user '\ |
|
180 |
'interface\'s language according to browser defined preferences', |
|
181 |
'group': 'web', 'inputlevel': 2, |
|
182 |
}), |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
183 |
|
0 | 184 |
('print-traceback', |
185 |
{'type' : 'yn', |
|
186 |
'default': not CubicWebConfiguration.mode == 'installed', |
|
187 |
'help': 'print the traceback on the error page when an error occured', |
|
188 |
'group': 'web', 'inputlevel': 2, |
|
189 |
}), |
|
190 |
)) |
|
191 |
||
192 |
def default_submit_url(self): |
|
193 |
try: |
|
194 |
cube = self.cubes()[0] |
|
195 |
cubeeid = self.cube_pkginfo(cube).cube_eid |
|
1149 | 196 |
except Exception: |
0 | 197 |
return None |
198 |
if cubeeid: |
|
199 |
return 'http://intranet.logilab.fr/jpl/view?__linkto=concerns:%s:subject&etype=Ticket&type=bug&vid=creation' % cubeeid |
|
200 |
return None |
|
201 |
||
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 |
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
|
203 |
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
|
204 |
|
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
|
205 |
def eproperty_definitions(self): |
893 | 206 |
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
|
207 |
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
|
208 |
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
|
209 |
yield key, pdef |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
210 |
|
0 | 211 |
# method used to connect to the repository: 'inmemory' / 'pyro' |
212 |
# Pyro repository by default |
|
213 |
repo_method = 'pyro' |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
214 |
|
0 | 215 |
# don't use @cached: we want to be able to disable it while this must still |
216 |
# be cached |
|
217 |
def repository(self, vreg=None): |
|
218 |
"""return the application's repository object""" |
|
219 |
try: |
|
220 |
return self.__repo |
|
221 |
except AttributeError: |
|
222 |
from cubicweb.dbapi import get_repository |
|
223 |
if self.repo_method == 'inmemory': |
|
224 |
repo = get_repository('inmemory', vreg=vreg, config=self) |
|
225 |
else: |
|
226 |
repo = get_repository('pyro', self['pyro-application-id'], |
|
227 |
config=self) |
|
228 |
self.__repo = repo |
|
229 |
return repo |
|
230 |
||
231 |
def vc_config(self): |
|
232 |
return self.repository().get_versions() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
233 |
|
0 | 234 |
# mapping to external resources (id -> path) (`external_resources` file) ## |
235 |
ext_resources = { |
|
236 |
'FAVICON': 'DATADIR/favicon.ico', |
|
237 |
'LOGO': 'DATADIR/logo.png', |
|
238 |
'RSS_LOGO': 'DATADIR/rss.png', |
|
239 |
'HELP': 'DATADIR/help.png', |
|
240 |
'CALENDAR_ICON': 'DATADIR/calendar.gif', |
|
241 |
'SEARCH_GO':'DATADIR/go.png', |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
242 |
|
0 | 243 |
'FCKEDITOR_PATH': '/usr/share/fckeditor/', |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
244 |
|
0 | 245 |
'IE_STYLESHEETS': ['DATADIR/cubicweb.ie.css'], |
246 |
'STYLESHEETS': ['DATADIR/cubicweb.css'], |
|
247 |
'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
|
248 |
|
0 | 249 |
'JAVASCRIPTS': ['DATADIR/jquery.js', |
30
25ef1dddaab8
round corners are back
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
250 |
'DATADIR/jquery.corner.js', |
25ef1dddaab8
round corners are back
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
251 |
'DATADIR/jquery.json.js', |
0 | 252 |
'DATADIR/cubicweb.compat.js', |
253 |
'DATADIR/cubicweb.python.js', |
|
254 |
'DATADIR/cubicweb.htmlhelpers.js'], |
|
255 |
} |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
256 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
257 |
|
0 | 258 |
def anonymous_user(self): |
259 |
"""return a login and password to use for anonymous users. None |
|
260 |
may be returned for both if anonymous connections are not allowed |
|
261 |
""" |
|
262 |
try: |
|
263 |
user = self['anonymous-user'] |
|
264 |
passwd = self['anonymous-password'] |
|
265 |
except KeyError: |
|
266 |
user, passwd = None, None |
|
267 |
if user is not None: |
|
268 |
user = unicode(user) |
|
269 |
return user, passwd |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
270 |
|
0 | 271 |
def has_resource(self, rid): |
272 |
"""return true if an external resource is defined""" |
|
273 |
return bool(self.ext_resources.get(rid)) |
|
274 |
||
275 |
@cached |
|
276 |
def locate_resource(self, rid): |
|
277 |
"""return the directory where the given resource may be found""" |
|
278 |
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
|
279 |
|
0 | 280 |
@cached |
281 |
def locate_doc_file(self, fname): |
|
282 |
"""return the directory where the given resource may be found""" |
|
283 |
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
|
284 |
|
0 | 285 |
def _fs_locate(self, rid, rdirectory): |
286 |
"""return the directory where the given resource may be found""" |
|
287 |
path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())] |
|
288 |
for directory in path: |
|
289 |
if exists(join(directory, rdirectory, rid)): |
|
290 |
return join(directory, rdirectory) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
291 |
|
0 | 292 |
def locate_all_files(self, rid, rdirectory='wdoc'): |
293 |
"""return all files corresponding to the given resource""" |
|
294 |
path = [self.apphome] + self.cubes_path() + [join(self.shared_dir())] |
|
295 |
for directory in path: |
|
296 |
fpath = join(directory, rdirectory, rid) |
|
297 |
if exists(fpath): |
|
298 |
yield join(fpath) |
|
299 |
||
300 |
def load_configuration(self): |
|
301 |
"""load application's configuration files""" |
|
302 |
super(WebConfiguration, self).load_configuration() |
|
303 |
# load external resources definition |
|
304 |
self._build_ext_resources() |
|
305 |
self._init_base_url() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
306 |
|
0 | 307 |
def _init_base_url(self): |
308 |
# normalize base url(s) |
|
309 |
baseurl = self['base-url'] |
|
310 |
if baseurl and baseurl[-1] != '/': |
|
311 |
baseurl += '/' |
|
312 |
self.global_set_option('base-url', baseurl) |
|
313 |
httpsurl = self['https-url'] |
|
314 |
if httpsurl and httpsurl[-1] != '/': |
|
315 |
httpsurl += '/' |
|
316 |
self.global_set_option('https-url', httpsurl) |
|
317 |
||
318 |
def _build_ext_resources(self): |
|
319 |
libresourcesfile = join(self.shared_dir(), 'data', 'external_resources') |
|
320 |
self.ext_resources.update(read_config(libresourcesfile)) |
|
321 |
for path in reversed([self.apphome] + self.cubes_path()): |
|
322 |
resourcesfile = join(path, 'data', 'external_resources') |
|
323 |
if exists(resourcesfile): |
|
324 |
self.debug('loading %s', resourcesfile) |
|
325 |
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
|
326 |
resourcesfile = join(self.apphome, 'external_resources') |
8cd0c2111783
search external_resources in application home
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
151
diff
changeset
|
327 |
if exists(resourcesfile): |
8cd0c2111783
search external_resources in application home
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
151
diff
changeset
|
328 |
self.debug('loading %s', resourcesfile) |
8cd0c2111783
search external_resources in application home
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
151
diff
changeset
|
329 |
self.ext_resources.update(read_config(resourcesfile)) |
0 | 330 |
for resource in ('STYLESHEETS', 'STYLESHEETS_PRINT', |
331 |
'IE_STYLESHEETS', 'JAVASCRIPTS'): |
|
332 |
val = self.ext_resources[resource] |
|
333 |
if isinstance(val, str): |
|
334 |
files = [w.strip() for w in val.split(',') if w.strip()] |
|
335 |
self.ext_resources[resource] = files |
|
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
336 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
337 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
338 |
# static files handling ################################################### |
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 |
@property |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
341 |
def static_directory(self): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
342 |
return join(self.appdatahome, 'static') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1490
diff
changeset
|
343 |
|
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
344 |
def static_file_exists(self, rpath): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
345 |
return exists(join(self.static_directory, rpath)) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
346 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
347 |
def static_file_open(self, rpath, mode='wb'): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
348 |
staticdir = self.static_directory |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
349 |
rdir, filename = split(rpath) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
350 |
if rdir: |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
351 |
staticdir = join(staticdir, rdir) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
352 |
os.makedirs(staticdir) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
353 |
return file(join(staticdir, filename), mode) |
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_add(self, rpath, data): |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
356 |
stream = self.static_file_open(rpath) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
357 |
stream.write(data) |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
358 |
stream.close() |
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
359 |
|
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
360 |
def static_file_del(self, rpath): |
447 | 361 |
if self.static_file_exists(rpath): |
151
343e7a18675d
static files support
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
30
diff
changeset
|
362 |
os.remove(join(self.static_directory, rpath)) |