cubicweb/web/propertysheet.py
author Philippe Pepiot <philippe.pepiot@logilab.fr>
Thu, 19 Jan 2017 15:27:39 +0100
changeset 11899 bf6106b91633
parent 11767 432f87a63057
child 11965 fb03a4113979
permissions -rw-r--r--
[schema] load schema from modules names instead of directories Introspect cubicweb, cubes and apphome using pkgutil to generate the full list of modules names for loading the schema. Keep historical behavior and check if source .py file exists if a module is found using python bytecode file (.pyc and .pyo) Loading schema from apphome require apphome to be present in sys.path and that "schema" module resolve to a file located in apphome. Update migraction tests to explicitely update sys.path when loading schema from different apps, use a contextmanager for this so it's more readable. Require updated logilab-common and yams
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11434
f6ba947c11ee [web] Fix bug with usage of os.rename under windows environment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10899
diff changeset
     1
# copyright 2010-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5444
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
11767
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11461
diff changeset
    20
5444
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
10897
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    25
import tempfile
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    26
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
    27
6000
98ca82aae3a1 [uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5938
diff changeset
    28
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
    29
               ('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
    30
               ]
98ca82aae3a1 [uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5938
diff changeset
    31
11434
f6ba947c11ee [web] Fix bug with usage of os.rename under windows environment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10899
diff changeset
    32
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
    33
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
    34
    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
    35
        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
    36
        self.context = context
11434
f6ba947c11ee [web] Fix bug with usage of os.rename under windows environment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10899
diff changeset
    37
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
    38
    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
    39
        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
    40
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
    41
5444
f7fdb5dd82f6 [webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
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
    43
    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
    44
        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
    45
        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
    46
        self.reset()
5444
f7fdb5dd82f6 [webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
        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
    48
        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
    49
        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
    50
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
    51
    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
    52
        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
    53
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
    54
    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
    55
        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
    56
        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
    57
        self._propfile_mtime = {}
5444
f7fdb5dd82f6 [webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    58
f7fdb5dd82f6 [webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    59
    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
    60
        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
    61
        scriptglobals['__file__'] = fpath
10615
6c497fe389d2 [py3k] execfile → exec
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10614
diff changeset
    62
        with open(fpath, 'rb') as fobj:
6c497fe389d2 [py3k] execfile → exec
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10614
diff changeset
    63
            code = compile(fobj.read(), fpath, 'exec')
6c497fe389d2 [py3k] execfile → exec
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10614
diff changeset
    64
        exec(code, scriptglobals, self)
6000
98ca82aae3a1 [uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5938
diff changeset
    65
        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
    66
            if name in self:
98ca82aae3a1 [uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5938
diff changeset
    67
                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
    68
                    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
    69
                    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
    70
        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
    71
        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
    72
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
    73
    def need_reload(self):
10662
10942ed172de [py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10615
diff changeset
    74
        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
    75
            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
    76
                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
    77
        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
    78
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
    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
    80
        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
    81
        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
    82
        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
    83
            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
    84
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
    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
    86
        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
    87
            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
    88
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
    def process_resource(self, rdirectory, rid):
10897
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    90
        cachefile = osp.join(self._cache_directory, rid)
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    91
        self.debug('processing %s/%s into %s',
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    92
                   rdirectory, rid, cachefile)
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    93
        rcachedir = osp.dirname(cachefile)
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    94
        if not osp.exists(rcachedir):
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    95
            os.makedirs(rcachedir)
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    96
        sourcefile = osp.join(rdirectory, rid)
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    97
        with open(sourcefile) as f:
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    98
            content = f.read()
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    99
        # XXX replace % not followed by a paren by %% to avoid having to do
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   100
        # this in the source css file ?
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
   101
        try:
10897
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   102
            content = self.compile(content)
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   103
        except ValueError as ex:
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   104
            self.error("can't process %s/%s: %s", rdirectory, rid, ex)
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   105
            adirectory = rdirectory
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   106
        else:
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   107
            tmpfd, tmpfile = tempfile.mkstemp(dir=rcachedir, prefix=osp.basename(cachefile))
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   108
            with os.fdopen(tmpfd, 'w') as stream:
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
                stream.write(content)
11434
f6ba947c11ee [web] Fix bug with usage of os.rename under windows environment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10899
diff changeset
   110
            try:
f6ba947c11ee [web] Fix bug with usage of os.rename under windows environment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10899
diff changeset
   111
                os.rename(tmpfile, cachefile)
f6ba947c11ee [web] Fix bug with usage of os.rename under windows environment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10899
diff changeset
   112
            except IOError:
f6ba947c11ee [web] Fix bug with usage of os.rename under windows environment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10899
diff changeset
   113
                # Under windows, os.rename won't overwrite an existing file
f6ba947c11ee [web] Fix bug with usage of os.rename under windows environment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10899
diff changeset
   114
                os.unlink(cachefile)
f6ba947c11ee [web] Fix bug with usage of os.rename under windows environment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10899
diff changeset
   115
                os.rename(tmpfile, cachefile)
10897
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   116
            adirectory = self._cache_directory
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   117
        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
   118
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
    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
   120
        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
   121
7083
b8e35cde46e9 help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6000
diff changeset
   122
    # 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
   123
    # 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
   124
    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
   125
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
   126
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
   127
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
   128
set_log_methods(PropertySheet, LOGGER)