cubicweb/web/propertysheet.py
author Philippe Pepiot <ph@itsalwaysdns.eu>
Tue, 31 Mar 2020 19:15:03 +0200
changeset 12957 0c973204033a
parent 12578 d06a2feae373
permissions -rw-r--r--
[server] prevent returning closed cursor to the database pool In since c8c6ad8 init_repository use repo.internal_cnx() instead of repo.system_source.get_connection() so it use the pool and we should not close cursors from the pool before returning it back. Otherwise we may have "connection already closed" error. This bug only trigger when connection-pool-size = 1. Since we are moving to use a dynamic pooler we need to get this fixed. This does not occur with sqlite since the connection wrapper instantiate new cursor everytime, but this occur with other databases.
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
11965
fb03a4113979 [web] fix os.rename usage on windows when destination exists
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    22
import errno
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
    23
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
    24
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
    25
import os.path as osp
10897
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    26
import tempfile
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    27
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
    28
6000
98ca82aae3a1 [uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5938
diff changeset
    29
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
    30
               ('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
    31
               ]
98ca82aae3a1 [uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5938
diff changeset
    32
11434
f6ba947c11ee [web] Fix bug with usage of os.rename under windows environment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10899
diff changeset
    33
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
    34
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
    35
    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
    36
        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
    37
        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
    38
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
    39
    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
    40
        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
    41
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
5444
f7fdb5dd82f6 [webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
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
    44
    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
    45
        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
    46
        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
    47
        self.reset()
5444
f7fdb5dd82f6 [webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
        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
    49
        context['lazystr'] = self.lazystr
12578
d06a2feae373 Fix DeprecationWarning: invalid escape sequence
Nsukami Patrick <ndkpatt at gmail dot com>
parents: 12288
diff changeset
    50
        self._percent_rgx = re.compile(r'%(?!\()')
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
    51
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
    52
    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
    53
        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
    54
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
    55
    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
    56
        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
    57
        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
    58
        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
    59
f7fdb5dd82f6 [webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    60
    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
    61
        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
    62
        scriptglobals['__file__'] = fpath
10615
6c497fe389d2 [py3k] execfile → exec
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10614
diff changeset
    63
        with open(fpath, 'rb') as fobj:
6c497fe389d2 [py3k] execfile → exec
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10614
diff changeset
    64
            code = compile(fobj.read(), fpath, 'exec')
6c497fe389d2 [py3k] execfile → exec
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10614
diff changeset
    65
        exec(code, scriptglobals, self)
6000
98ca82aae3a1 [uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5938
diff changeset
    66
        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
    67
            if name in self:
98ca82aae3a1 [uiprops] check that STYLESHEETS* and JAVASCRIPTS are lists
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5938
diff changeset
    68
                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
    69
                    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
    70
                    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
    71
        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
    72
        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
    73
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
    74
    def need_reload(self):
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):
10897
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    91
        cachefile = osp.join(self._cache_directory, rid)
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    92
        self.debug('processing %s/%s into %s',
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    93
                   rdirectory, rid, cachefile)
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    94
        rcachedir = osp.dirname(cachefile)
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    95
        if not osp.exists(rcachedir):
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    96
            os.makedirs(rcachedir)
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    97
        sourcefile = osp.join(rdirectory, rid)
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    98
        with open(sourcefile) as f:
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
    99
            content = f.read()
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   100
        # 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
   101
        # 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
   102
        try:
10897
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   103
            content = self.compile(content)
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   104
        except ValueError as ex:
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   105
            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
   106
            adirectory = rdirectory
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   107
        else:
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   108
            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
   109
            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
   110
                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
   111
            try:
12288
2c582a242b66 [web] fix css file generation permission bug (closes #17143773)
David Douard <david.douard@logilab.fr>
parents: 11965
diff changeset
   112
                mode = os.stat(sourcefile).st_mode
2c582a242b66 [web] fix css file generation permission bug (closes #17143773)
David Douard <david.douard@logilab.fr>
parents: 11965
diff changeset
   113
                os.chmod(tmpfile, mode)
2c582a242b66 [web] fix css file generation permission bug (closes #17143773)
David Douard <david.douard@logilab.fr>
parents: 11965
diff changeset
   114
            except IOError:
2c582a242b66 [web] fix css file generation permission bug (closes #17143773)
David Douard <david.douard@logilab.fr>
parents: 11965
diff changeset
   115
                self.warning('Cannot set access mode for %s; you may encouter '
2c582a242b66 [web] fix css file generation permission bug (closes #17143773)
David Douard <david.douard@logilab.fr>
parents: 11965
diff changeset
   116
                             'file permissions issues', cachefile)
2c582a242b66 [web] fix css file generation permission bug (closes #17143773)
David Douard <david.douard@logilab.fr>
parents: 11965
diff changeset
   117
            try:
11434
f6ba947c11ee [web] Fix bug with usage of os.rename under windows environment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10899
diff changeset
   118
                os.rename(tmpfile, cachefile)
11965
fb03a4113979 [web] fix os.rename usage on windows when destination exists
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   119
            except OSError as err:
fb03a4113979 [web] fix os.rename usage on windows when destination exists
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   120
                if err.errno != errno.EEXIST:
fb03a4113979 [web] fix os.rename usage on windows when destination exists
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
   121
                    raise
11434
f6ba947c11ee [web] Fix bug with usage of os.rename under windows environment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10899
diff changeset
   122
                # 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
   123
                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
   124
                os.rename(tmpfile, cachefile)
10897
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   125
            adirectory = self._cache_directory
7c386161ebd6 [web] remove PropertySheet._cache
Julien Cristau <julien.cristau@logilab.fr>
parents: 10686
diff changeset
   126
        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
   127
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
    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
   129
        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
   130
7083
b8e35cde46e9 help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6000
diff changeset
   131
    # 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
   132
    # 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
   133
    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
   134
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
   135
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
   136
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
   137
set_log_methods(PropertySheet, LOGGER)