web/webconfig.py
changeset 151 343e7a18675d
parent 30 25ef1dddaab8
child 252 8cd0c2111783
equal deleted inserted replaced
150:1190261a1f13 151:343e7a18675d
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 """
     6 """
     7 __docformat__ = "restructuredtext en"
     7 __docformat__ = "restructuredtext en"
     8 
     8 
     9 import os
     9 import os
    10 from os.path import join, dirname, exists
    10 from os.path import join, dirname, exists, split
    11 from urlparse import urljoin
    11 from urlparse import urljoin
    12 
    12 
    13 from logilab.common.configuration import Method
    13 from logilab.common.configuration import Method
    14 from logilab.common.decorators import cached
    14 from logilab.common.decorators import cached
    15 
    15 
   318                          'IE_STYLESHEETS', 'JAVASCRIPTS'):
   318                          'IE_STYLESHEETS', 'JAVASCRIPTS'):
   319             val = self.ext_resources[resource]
   319             val = self.ext_resources[resource]
   320             if isinstance(val, str):
   320             if isinstance(val, str):
   321                 files = [w.strip() for w in val.split(',') if w.strip()]
   321                 files = [w.strip() for w in val.split(',') if w.strip()]
   322                 self.ext_resources[resource] = files
   322                 self.ext_resources[resource] = files
       
   323 
       
   324 
       
   325     # static files handling ###################################################
       
   326     
       
   327     @property
       
   328     def static_directory(self):
       
   329         return join(self.appdatahome, 'static')
       
   330     
       
   331     def static_file_exists(self, rpath):
       
   332         return exists(join(self.static_directory, rpath))
       
   333 
       
   334     def static_file_open(self, rpath, mode='wb'):
       
   335         staticdir = self.static_directory
       
   336         rdir, filename = split(rpath)
       
   337         if rdir:
       
   338             staticdir = join(staticdir, rdir)
       
   339             os.makedirs(staticdir)
       
   340         return file(join(staticdir, filename), mode)
       
   341 
       
   342     def static_file_add(self, rpath, data):
       
   343         stream = self.static_file_open(rpath)
       
   344         stream.write(data)
       
   345         stream.close()
       
   346 
       
   347     def static_file_del(self, rpath):
       
   348         if static_file_exists(rpath):
       
   349             os.remove(join(self.static_directory, rpath))
       
   350