Changeset 2048

Show
Ignore:
Timestamp:
06/18/09 13:38:51 (9 months ago)
Author:
JensDiemer
Message:

headfile cache: Try to create the out path, if it's not exist.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/0.9/pylucid_project/apps/pylucid/models.py

    r2040 r2048  
    2121 
    2222import os 
     23import errno 
    2324import warnings 
    2425import posixpath 
     
    517518         
    518519    def save_cache_file(self): 
    519         """ Try to cache the head file into filesystem (Only worked, if python process has write rights) """ 
     520        """ 
     521        Try to cache the head file into filesystem (Only worked, if python process has write rights) 
     522        Try to create the out path, if it's not exist. 
     523        """ 
    520524        cachepath = self.get_cachepath() 
     525         
     526        def _save_cache_file(auto_create_dir=True): 
     527            try: 
     528                f = file(cachepath, "w") 
     529                f.write(self.content) 
     530                f.close() 
     531            except IOError, err: 
     532                if auto_create_dir and err.errno == errno.ENOENT: # No 2: No such file or directory 
     533                    # Try to create the out dir and save the cache file   
     534                    path = os.path.dirname(cachepath) 
     535                    if not os.path.isdir(path): 
     536                        # Try to create cache path and save file 
     537                        os.makedirs(path) 
     538                        user_message_or_warn("Cache path %s created" % path) 
     539                        _save_cache_file(auto_create_dir=False) 
     540                        return 
     541                raise 
     542 
    521543        try: 
    522             f = file(cachepath, "w") 
    523             f.write(self.content) 
    524             f.close() 
    525         except Exception, err: 
     544            _save_cache_file() 
     545        except IOError, err: 
    526546            user_message_or_warn("Can't cache EditableHtmlHeadFile into %r: %s" % (cachepath, err)) 
    527547        else: