author | Rémi Cardona <remi.cardona@logilab.fr> |
Mon, 05 Oct 2015 17:10:36 +0200 | |
changeset 10686 | a08d5a657836 |
parent 10662 | 10942ed172de |
child 10897 | 7c386161ebd6 |
permissions | -rw-r--r-- |
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
1 |
# copyright 2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
# |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
4 |
# This file is part of CubicWeb. |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
# |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
9 |
# any later version. |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
10 |
# |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
14 |
# details. |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
15 |
# |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
18 |
"""property sheets allowing configuration of the web ui""" |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
19 |
|
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
20 |
__docformat__ = "restructuredtext en" |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
21 |
|
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
22 |
import re |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
23 |
import os |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
24 |
import os.path as osp |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
25 |
|
6000
98ca82aae3a1
[uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5938
diff
changeset
|
26 |
TYPE_CHECKS = [('STYLESHEETS', list), ('JAVASCRIPTS', list), |
98ca82aae3a1
[uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5938
diff
changeset
|
27 |
('STYLESHEETS_IE', list), ('STYLESHEETS_PRINT', list), |
98ca82aae3a1
[uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5938
diff
changeset
|
28 |
] |
98ca82aae3a1
[uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5938
diff
changeset
|
29 |
|
5938
9cb13d1b2ce4
[uiprops] introduce lazystr to get a chance to change style without having to change all properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
30 |
class lazystr(object): |
9cb13d1b2ce4
[uiprops] introduce lazystr to get a chance to change style without having to change all properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
31 |
def __init__(self, string, context): |
9cb13d1b2ce4
[uiprops] introduce lazystr to get a chance to change style without having to change all properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
32 |
self.string = string |
9cb13d1b2ce4
[uiprops] introduce lazystr to get a chance to change style without having to change all properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
33 |
self.context = context |
9cb13d1b2ce4
[uiprops] introduce lazystr to get a chance to change style without having to change all properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
34 |
def __str__(self): |
9cb13d1b2ce4
[uiprops] introduce lazystr to get a chance to change style without having to change all properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
35 |
return self.string % self.context |
9cb13d1b2ce4
[uiprops] introduce lazystr to get a chance to change style without having to change all properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
36 |
|
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
37 |
|
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
38 |
class PropertySheet(dict): |
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
39 |
def __init__(self, cache_directory, **context): |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
40 |
self._cache_directory = cache_directory |
5467
57372dbfd114
[https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5466
diff
changeset
|
41 |
self.context = context |
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
42 |
self.reset() |
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
43 |
context['sheet'] = self |
5938
9cb13d1b2ce4
[uiprops] introduce lazystr to get a chance to change style without having to change all properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
44 |
context['lazystr'] = self.lazystr |
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
45 |
self._percent_rgx = re.compile('%(?!\()') |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
46 |
|
5938
9cb13d1b2ce4
[uiprops] introduce lazystr to get a chance to change style without having to change all properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
47 |
def lazystr(self, str): |
9cb13d1b2ce4
[uiprops] introduce lazystr to get a chance to change style without having to change all properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
48 |
return lazystr(str, self) |
9cb13d1b2ce4
[uiprops] introduce lazystr to get a chance to change style without having to change all properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
49 |
|
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
50 |
def reset(self): |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
51 |
self.clear() |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
52 |
self._ordered_propfiles = [] |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
53 |
self._propfile_mtime = {} |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
54 |
self._sourcefile_mtime = {} |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
55 |
self._cache = {} |
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
56 |
|
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
57 |
def load(self, fpath): |
5467
57372dbfd114
[https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5466
diff
changeset
|
58 |
scriptglobals = self.context.copy() |
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
59 |
scriptglobals['__file__'] = fpath |
10615
6c497fe389d2
[py3k] execfile → exec
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
60 |
with open(fpath, 'rb') as fobj: |
6c497fe389d2
[py3k] execfile → exec
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
61 |
code = compile(fobj.read(), fpath, 'exec') |
6c497fe389d2
[py3k] execfile → exec
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
62 |
exec(code, scriptglobals, self) |
6000
98ca82aae3a1
[uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5938
diff
changeset
|
63 |
for name, type in TYPE_CHECKS: |
98ca82aae3a1
[uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5938
diff
changeset
|
64 |
if name in self: |
98ca82aae3a1
[uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5938
diff
changeset
|
65 |
if not isinstance(self[name], type): |
98ca82aae3a1
[uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5938
diff
changeset
|
66 |
msg = "Configuration error: %s.%s should be a %s" % (fpath, name, type) |
98ca82aae3a1
[uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5938
diff
changeset
|
67 |
raise Exception(msg) |
10505
a9becf2cce8b
[web] Stop using negative indices with os.stat results
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8695
diff
changeset
|
68 |
self._propfile_mtime[fpath] = os.stat(fpath).st_mtime |
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
69 |
self._ordered_propfiles.append(fpath) |
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
70 |
|
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
71 |
def need_reload(self): |
10686
a08d5a657836
[py3k] add list() around dict methods
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10662
diff
changeset
|
72 |
for rid, (adirectory, rdirectory, mtime) in list(self._cache.items()): |
10505
a9becf2cce8b
[web] Stop using negative indices with os.stat results
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8695
diff
changeset
|
73 |
if os.stat(osp.join(rdirectory, rid)).st_mtime > mtime: |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
74 |
del self._cache[rid] |
10662
10942ed172de
[py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10615
diff
changeset
|
75 |
for fpath, mtime in self._propfile_mtime.items(): |
10505
a9becf2cce8b
[web] Stop using negative indices with os.stat results
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8695
diff
changeset
|
76 |
if os.stat(fpath).st_mtime > mtime: |
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
77 |
return True |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
78 |
return False |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
79 |
|
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
80 |
def reload(self): |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
81 |
ordered_files = self._ordered_propfiles |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
82 |
self.reset() |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
83 |
for fpath in ordered_files: |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
84 |
self.load(fpath) |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
85 |
|
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
86 |
def reload_if_needed(self): |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
87 |
if self.need_reload(): |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
88 |
self.reload() |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
89 |
|
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
90 |
def process_resource(self, rdirectory, rid): |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
91 |
try: |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
92 |
return self._cache[rid][0] |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
93 |
except KeyError: |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
94 |
cachefile = osp.join(self._cache_directory, rid) |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
95 |
self.debug('caching processed %s/%s into %s', |
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
96 |
rdirectory, rid, cachefile) |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
97 |
rcachedir = osp.dirname(cachefile) |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
98 |
if not osp.exists(rcachedir): |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
99 |
os.makedirs(rcachedir) |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
100 |
sourcefile = osp.join(rdirectory, rid) |
10614
57dfde80df11
[py3k] file → open
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10505
diff
changeset
|
101 |
content = open(sourcefile).read() |
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
102 |
# XXX replace % not followed by a paren by %% to avoid having to do |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
103 |
# this in the source css file ? |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
104 |
try: |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
105 |
content = self.compile(content) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7083
diff
changeset
|
106 |
except ValueError as ex: |
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
107 |
self.error("can't process %s/%s: %s", rdirectory, rid, ex) |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
108 |
adirectory = rdirectory |
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
109 |
else: |
10614
57dfde80df11
[py3k] file → open
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10505
diff
changeset
|
110 |
stream = open(cachefile, 'w') |
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
111 |
stream.write(content) |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
112 |
stream.close() |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
113 |
adirectory = self._cache_directory |
10505
a9becf2cce8b
[web] Stop using negative indices with os.stat results
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8695
diff
changeset
|
114 |
self._cache[rid] = (adirectory, rdirectory, os.stat(sourcefile).st_mtime) |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
115 |
return adirectory |
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
116 |
|
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
117 |
def compile(self, content): |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
118 |
return self._percent_rgx.sub('%%', content) % self |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
119 |
|
7083
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6000
diff
changeset
|
120 |
# these are overridden by set_log_methods below |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6000
diff
changeset
|
121 |
# only defining here to prevent pylint from complaining |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6000
diff
changeset
|
122 |
info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6000
diff
changeset
|
123 |
|
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
124 |
from cubicweb.web import LOGGER |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
125 |
from logilab.common.logging_ext import set_log_methods |
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
126 |
set_log_methods(PropertySheet, LOGGER) |