[CMF-checkins] SVN: CMF/branches/tseaver-pkg_resources/CMFCore/ - Adjust FSObject derivatives to resource-based loading.

Tres Seaver tseaver at palladion.com
Wed Oct 26 09:39:29 EDT 2005


Log message for revision 39632:
   - Adjust FSObject derivatives to resource-based loading.

Changed:
  U   CMF/branches/tseaver-pkg_resources/CMFCore/DirectoryView.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/FSDTMLMethod.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/FSFile.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/FSImage.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/FSMetadata.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/FSObject.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/FSPageTemplate.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/FSZSQLMethod.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_CachingPolicyManager.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSDTMLMethod.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSFile.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSImage.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSMetadata.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSPageTemplate.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSPropertiesObject.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSPythonScript.py
  U   CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSZSQLMethod.py

-=-
Modified: CMF/branches/tseaver-pkg_resources/CMFCore/DirectoryView.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/DirectoryView.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/DirectoryView.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -236,7 +236,7 @@
                     t = registry.getTypeByMetaType(mt)
                     if t is None:
                         t = DirectoryView
-                    metadata = FSMetadata(filename=entry_filepath)
+                    metadata = FSMetadata(filepath=entry_filepath)
                     metadata.read()
                     ob = t( entry
                           , entry_minimal_fp
@@ -270,11 +270,14 @@
                     t = registry.getTypeByExtension(ext)
 
                 if t is not None:
-                    metadata = FSMetadata(filename=entry_filepath)
+                    metadata = FSMetadata(filepath=entry_filepath)
                     metadata.read()
                     try:
-                        ob = t(name, entry_minimal_fp, fullname=entry,
-                               properties=metadata.getProperties())
+                        ob = t(name,
+                               filepath=entry_minimal_fp,
+                               fullname=entry,
+                               properties=metadata.getProperties(),
+                              )
                     except:
                         import traceback
                         typ, val, tb = exc_info()

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSDTMLMethod.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSDTMLMethod.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSDTMLMethod.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -14,6 +14,7 @@
 
 $Id$
 """
+from pkg_resources import resource_string
 
 import Globals
 from AccessControl import ClassSecurityInfo, getSecurityManager
@@ -65,8 +66,10 @@
 
     _reading = 0
 
-    def __init__(self, id, filepath, fullname=None, properties=None):
-        FSObject.__init__(self, id, filepath, fullname, properties)
+    def __init__(self, id, package=None, entry_subpath=None, filepath=None,
+                 fullname=None, properties=None):
+        FSObject.__init__(self, id, package, entry_subpath, filepath,
+                          fullname, properties)
         # Normally called via HTML.__init__ but we don't need the rest that
         # happens there.
         self.initvars(None, {})
@@ -76,12 +79,15 @@
         return DTMLMethod(self.read(), __name__=self.getId())
 
     def _readFile(self, reparse):
-        fp = expandpath(self._filepath)
-        file = open(fp, 'r')    # not 'rb', as this is a text file!
-        try:
-            data = file.read()
-        finally:
-            file.close()
+        if self._filepath is None:
+            data = resource_string(self._package, self._entry_subpath)
+        else:
+            fp = expandpath(self._filepath)
+            file = open(fp, 'r')    # not 'rb', as this is a text file!
+            try:
+                data = file.read()
+            finally:
+                file.close()
         self.raw = data
         if reparse:
             self._reading = 1  # Avoid infinite recursion

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSFile.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSFile.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSFile.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -48,9 +48,11 @@
     security = ClassSecurityInfo()
     security.declareObjectProtected(View)
 
-    def __init__(self, id, filepath, fullname=None, properties=None):
+    def __init__(self, id, package=None, entry_subpath=None, filepath=None,
+                 fullname=None, properties=None):
         id = fullname or id # Use the whole filename.
-        FSObject.__init__(self, id, filepath, fullname, properties)
+        FSObject.__init__(self, id, package, entry_subpath, filepath,
+                          fullname, properties)
 
     security.declareProtected(ViewManagementScreens, 'manage_main')
     manage_main = Globals.DTMLFile('custfile', _dtmldir)

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSImage.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSImage.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSImage.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -49,9 +49,11 @@
     security = ClassSecurityInfo()
     security.declareObjectProtected(View)
 
-    def __init__(self, id, filepath, fullname=None, properties=None):
+    def __init__(self, id, package=None, entry_subpath=None, filepath=None,
+                 fullname=None, properties=None):
         id = fullname or id # Use the whole filename.
-        FSObject.__init__(self, id, filepath, fullname, properties)
+        FSObject.__init__(self, id, package, entry_subpath, filepath,
+                          fullname, properties)
 
     security.declareProtected(ViewManagementScreens, 'manage_main')
     manage_main = Globals.DTMLFile('custimage', _dtmldir)

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSMetadata.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSMetadata.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSMetadata.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -46,11 +46,11 @@
     # public API
     _package = None
     _entry_subpath = None
-    _filename = None
-    def __init__(self, package=None, entry_subpath=None, filename=None):
-        MESSAGE = ("Either 'filename' or 'package' + 'entry_subpath' must "
+    _filepath = None
+    def __init__(self, package=None, entry_subpath=None, filepath=None):
+        MESSAGE = ("Either 'filepath' or 'package' + 'entry_subpath' must "
                    "be supplied.")
-        if filename is None:
+        if filepath is None:
             if package is None or entry_subpath is None:
                 raise ValueError(MESSAGE)
             self._package = package
@@ -58,7 +58,7 @@
         else:
             if package is not None or entry_subpath is not None:
                 raise ValueError(MESSAGE)
-            self._filename = filename
+            self._filepath = filepath
 
     def read(self):
         """ Find the file(s) and read them.
@@ -128,7 +128,7 @@
             except IOError:
                 return None
         try:
-            return open(self._filename + '.metadata', 'r')
+            return open(self._filepath + '.metadata', 'r')
         except IOError:
             return None
             
@@ -151,7 +151,7 @@
         """
         if data.find(':') < 1:
             raise ValueError, "The security declaration of file " + \
-                  "%r is in the wrong format" % self._filename
+                  "%r is in the wrong format" % self._filepath
 
         acquire, roles = data.split(':')
         roles = [r.strip() for r in roles.split(',') if r.strip()]

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSObject.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSObject.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSObject.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -57,7 +57,7 @@
     _file_mod_time = 0
     _parsed = 0
 
-    def __init__(self, id, filepath=None, package=None, entry_subpath=None,
+    def __init__(self, id, package=None, entry_subpath=None, filepath=None,
                  fullname=None, properties=None):
         MESSAGE = ("Either 'filepath' or 'package' + 'entry_subpath' must "
                    "be supplied.")

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSPageTemplate.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSPageTemplate.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSPageTemplate.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -64,9 +64,9 @@
     # Declare security for unprotected PageTemplate methods.
     security.declarePrivate('pt_edit', 'write')
 
-    def __init__(self, id, filepath=None, package=None, entry_subpath=None,
+    def __init__(self, id, package=None, entry_subpath=None, filepath=None,
                  fullname=None, properties=None):
-        FSObject.__init__(self, id, filepath, package, entry_subpath,
+        FSObject.__init__(self, id, package, entry_subpath, filepath,
                           fullname, properties)
         self.ZBindings_edit(self._default_bindings)
 

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/FSZSQLMethod.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/FSZSQLMethod.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/FSZSQLMethod.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -56,8 +56,10 @@
     security.declareProtected(ViewManagementScreens, 'manage_customise')
     manage_customise = Globals.DTMLFile('custzsql', _dtmldir)
 
-    def __init__(self, id, filepath, fullname=None, properties=None):
-        FSObject.__init__(self, id, filepath, fullname, properties)
+    def __init__(self, id, package=None, entry_subpath=None, filepath=None,
+                 fullname=None, properties=None):
+        FSObject.__init__(self, id, package, entry_subpath, filepath,
+                          fullname, properties)
 
     def _createZODBClone(self):
         """Create a ZODB (editable) equivalent of this object."""

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_CachingPolicyManager.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_CachingPolicyManager.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_CachingPolicyManager.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -607,7 +607,8 @@
         # This is a FSPageTemplate that will be used as the View for 
         # our content objects. It doesn't matter what it returns.
         path = os.path.join(self.skin_path_name, 'testPT2.pt')
-        self.portal._setObject('dummy_view', FSPageTemplate('dummy_view', path))
+        self.portal._setObject('dummy_view',
+                               FSPageTemplate('dummy_view', filepath=path))
 
         uf = self.root.acl_users
         password = 'secret'

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSDTMLMethod.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSDTMLMethod.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSDTMLMethod.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -35,9 +35,10 @@
 
     def _makeOne( self, id, filename ):
         path = path_join(self.skin_path_name, filename)
-        metadata = FSMetadata(path)
+        metadata = FSMetadata(filepath=path)
         metadata.read()
-        return FSDTMLMethod( id, path, properties=metadata.getProperties() )
+        return FSDTMLMethod( id, filepath=path
+                           , properties=metadata.getProperties() )
 
 
 class FSDTMLMethodTests( RequestTest, FSDTMLMaker ):

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSFile.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSFile.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSFile.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -42,10 +42,10 @@
         from Products.CMFCore.FSMetadata import FSMetadata
 
         full_path = path_join(self.skin_path_name, filename)
-        metadata = FSMetadata(full_path)
+        metadata = FSMetadata(filepath=full_path)
         metadata.read()
-        fsfile_ob = FSFile(id, full_path, properties=metadata.getProperties())
-
+        fsfile_ob = FSFile(id, filepath=full_path,
+                           properties=metadata.getProperties())
         return fsfile_ob
 
     def _extractFile( self, filename ):

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSImage.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSImage.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSImage.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -40,7 +40,7 @@
 
         from Products.CMFCore.FSImage import FSImage
 
-        return FSImage( id, path_join(self.skin_path_name, filename) )
+        return FSImage( id, filepath=path_join(self.skin_path_name, filename) )
 
     def _extractFile( self ):
 

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSMetadata.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSMetadata.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSMetadata.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -30,7 +30,8 @@
         # Test proxy roles on the object
         for role in roles:
             if not obj.manage_haveProxy(role):
-                raise 'Object does not have the "%s" role' % role
+                raise AssertionError(
+                        'Object does not have the "%s" role' % role)
 
     def test_basicPermissions(self):
         # Test basic FS permissions

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSPageTemplate.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSPageTemplate.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSPageTemplate.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -36,10 +36,11 @@
 class FSPTMaker(FSDVTest):
 
     def _makeOne( self, id, filename ):
-        path = path_join(self.skin_path_name, filename)
-        metadata = FSMetadata(path)
+        path = path_join( self.skin_path_name, filename )
+        metadata = FSMetadata( filepath=path )
         metadata.read()
-        return FSPageTemplate( id, path, properties=metadata.getProperties() )
+        return FSPageTemplate( id, filepath=path
+                             , properties=metadata.getProperties() )
 
 
 class FSPageTemplateTests( RequestTest, FSPTMaker ):

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSPropertiesObject.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSPropertiesObject.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSPropertiesObject.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -16,7 +16,7 @@
 
     def _makeOne( self, id, filename ):
         path = join(self.skin_path_name, filename)
-        return FSPropertiesObject( id, path ) 
+        return FSPropertiesObject( id, filepath=path ) 
 
 
 class FSPropertiesObjectCustomizationTests(SecurityTest, FSPOMaker):

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSPythonScript.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSPythonScript.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSPythonScript.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -36,10 +36,11 @@
 class FSPSMaker(FSDVTest):
 
     def _makeOne( self, id, filename ):
-        path = join(self.skin_path_name, filename)
-        metadata = FSMetadata(path)
+        path = join( self.skin_path_name, filename )
+        metadata = FSMetadata( filepath=path )
         metadata.read()
-        return FSPythonScript( id, path, properties=metadata.getProperties() ) 
+        return FSPythonScript( id, filepath=path,
+                               properties=metadata.getProperties() ) 
 
 
 class FSPythonScriptTests(FSPSMaker):

Modified: CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSZSQLMethod.py
===================================================================
--- CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSZSQLMethod.py	2005-10-26 13:32:26 UTC (rev 39631)
+++ CMF/branches/tseaver-pkg_resources/CMFCore/tests/test_FSZSQLMethod.py	2005-10-26 13:39:29 UTC (rev 39632)
@@ -15,10 +15,11 @@
 class FSZSQLMaker(FSDVTest):
 
     def _makeOne( self, id, filename ):
-        path = join(self.skin_path_name, filename)
-        metadata = FSMetadata(path)
+        path = join( self.skin_path_name, filename )
+        metadata = FSMetadata( filepath=path )
         metadata.read()
-        return FSZSQLMethod( id, path, properties=metadata.getProperties() )
+        return FSZSQLMethod( id, filepath=path,
+                             properties=metadata.getProperties() )
 
 class FSZSQLMethodTests( FSDVTest ):
 



More information about the CMF-checkins mailing list