Back to index

plone3  3.1.7
FSControllerBase.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE
00011 #
00012 ##########################################################################
00013 
00014 import os
00015 from AccessControl import ClassSecurityInfo
00016 import Globals
00017 from Products.CMFCore.FSMetadata import FSMetadata
00018 from ControllerBase import ControllerBase
00019 
00020 class FSControllerBase(ControllerBase):
00021     """Common functions for filesystem objects controlled by portal_form_controller"""
00022 
00023     security = ClassSecurityInfo()
00024 
00025 
00026     def _setProperties(self, properties=None):
00027         if properties:
00028             # Since props come from the filesystem, this should be
00029             # safe.
00030             self.__dict__.update(properties)
00031             if fullname and properties.get('keep_extension', 0):
00032                 id = fullname
00033 
00034             cache = properties.get('cache')
00035             if cache:
00036                 self.ZCacheable_setManagerId(cache)
00037 
00038     # Refresh our contents from the filesystem if that is newer and we are
00039     # running in debug mode.
00040     # This method replaces FSObject's _updateFromFS.  Because multiple inheritance in 
00041     # Python 2.1 is lame (Zope 2.6.x), I'm renaming this method _baseUpdateFromFS and am
00042     # delegating via an explicit _updateFromFS override in classes that inherit from
00043     # FSControllerBase
00044     def _baseUpdateFromFS(self):
00045         parsed = self._parsed
00046         if not parsed or Globals.DevelopmentMode:
00047             fp = self._filepath
00048             try:
00049                 mtime=os.stat(fp)[8]
00050             except:
00051                 mtime=0
00052             e_fp = fp + '.metadata'
00053             try:
00054                 mmtime = os.stat(e_fp)[8]
00055             except:
00056                 mmtime = 0
00057             if mmtime > mtime:
00058                 mtime = mmtime
00059             if not parsed or mtime != self._file_mod_time:
00060                 # if we have to read the file again, remove the cache
00061                 self.ZCacheable_invalidate()
00062                 self._readFile(1)
00063                 self._file_mod_time = mtime
00064                 self._parsed = 1
00065 
00066     # This method replaces FSMetadata's _readMetadata.  Because multiple inheritance in 
00067     # Python 2.1 is lame (Zope 2.6.x), I'm renaming this method _baseReadMetadata and am
00068     # delegating via an explicit _readMetadata override in classes that inherit from
00069     # FSControllerBase
00070     def _baseReadMetadata(self):
00071         # re-read .metadata file if it exists
00072         e_fp = self._filepath + '.metadata'
00073         if os.path.exists(e_fp):
00074             metadata = FSMetadata(e_fp)
00075             metadata.read()
00076             self._setProperties(metadata.getProperties())
00077     
00078             # re-read actions and validators whenever we re-read the file
00079             self._read_action_metadata(self.getId(), self._filepath)
00080             self._read_validator_metadata(self.getId(), self._filepath)
00081 
00082 Globals.InitializeClass(FSControllerBase)