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