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