[CMF-checkins] CVS: CMF/CMFSetup - context.py:1.1 interfaces.py:1.2

Tres Seaver tseaver at zope.com
Fri May 21 17:13:10 EDT 2004


Update of /cvs-repository/CMF/CMFSetup
In directory cvs.zope.org:/tmp/cvs-serv6424

Modified Files:
	interfaces.py 
Added Files:
	context.py 
Log Message:


  - interfaces.py:

    o s/readDatafile/readDataFile/g

    o Expand description of error cases.

  - context.py:

    o Create filesystem-based implementations of IImportContext
      and IExportContext.


  - tests/conformance.py:

    o Base classes for testing interface conformance.


=== Added File CMF/CMFSetup/context.py ===
""" Classes:  ImportContext, ExportContext

Wrappers representing the state of an import / export operation.

$Id: context.py,v 1.1 2004/05/21 21:12:39 tseaver Exp $
"""
import os

from AccessControl import ClassSecurityInfo
from Acquisition import Implicit
from Acquisition import aq_inner
from Acquisition import aq_parent
from Globals import InitializeClass

from permissions import ManagePortal
from interfaces import IImportContext
from interfaces import IExportContext

class ImportContext( Implicit ):

    __implements__ = ( IImportContext, )

    security = ClassSecurityInfo()

    def __init__( self, tool, profile_path, should_purge=False ):

        self._site = aq_parent( aq_inner( tool ) )
        self._profile_path = profile_path
        self._should_purge = bool( should_purge )

    security.declareProtected( ManagePortal, 'getSite' )
    def getSite():

        """ See ISetupContext.
        """
        return self._site

    security.declareProtected( ManagePortal, 'readDataFile' )
    def readDataFile( self, filename, subdir=None ):

        """ See IImportContext.
        """
        if subdir is None:
            full_path = os.path.join( self._profile_path, filename )
        else:
            full_path = os.path.join( self._profile_path, subdir, filename )

        if not os.path.exists( full_path ):
            return None

        file = open( full_path, 'rb' )
        result = file.read()
        file.close()

        return result

    security.declareProtected( ManagePortal, 'getLastModified' )
    def getLastModified( self, path ):

        """ See IImportContext.
        """
        full_path = os.path.join( self._profile_path, path )

        if not os.path.exists( full_path ):
            return None

        return os.path.getmtime( full_path )

    security.declareProtected( ManagePortal, 'isDirectory' )
    def isDirectory( self, path ):

        """ See IImportContext.
        """
        full_path = os.path.join( self._profile_path, path )

        if not os.path.exists( full_path ):
            return None

        return os.path.isdir( full_path )

    security.declareProtected( ManagePortal, 'listDirectory' )
    def listDirectory( self, path, skip=('CVS',) ):

        """ See IImportContext.
        """
        full_path = os.path.join( self._profile_path, path )

        if not os.path.exists( full_path ) or not os.path.isdir( full_path ):
            return None

        names = os.listdir( full_path )

        return [ name for name in names if name not in skip ]

    security.declareProtected( ManagePortal, 'shouldPurge' )
    def shouldPurge( self ):

        """ See IImportContext.
        """
        return self._should_purge

InitializeClass( ImportContext )

class ExportContext( Implicit ):

    __implements__ = ( IExportContext, )

    security = ClassSecurityInfo()

    def __init__( self, tool, profile_path ):

        self._site = aq_parent( aq_inner( tool ) )
        self._profile_path = profile_path

    security.declareProtected( ManagePortal, 'getSite' )
    def getSite():

        """ See ISetupContext.
        """
        return self._site


    security.declareProtected( ManagePortal, 'writeDataFile' )
    def writeDataFile( self, filename, text, content_type, subdir=None ):

        """ See IExportContext.
        """
        if subdir is None:
            prefix = self._profile_path
        else:
            prefix = os.path.join( self._profile_path, subdir )

        full_path = os.path.join( prefix, filename )

        if not os.path.exists( prefix ):
            os.makedirs( prefix )

        mode = content_type.startswith( 'text/' ) and 'w' or 'wb'

        file = open( full_path, mode )
        file.write( text )
        file.close()

InitializeClass( ExportContext )


=== CMF/CMFSetup/interfaces.py 1.1 => 1.2 ===
--- CMF/CMFSetup/interfaces.py:1.1	Tue May 18 18:14:03 2004
+++ CMF/CMFSetup/interfaces.py	Fri May 21 17:12:39 2004
@@ -16,7 +16,7 @@
 
 class IImportContext( ISetupContext ):
 
-    def readDatafile( filename, subdir=None ):
+    def readDataFile( filename, subdir=None ):
 
         """ Search the current configuration for the requested file.
 
@@ -40,7 +40,7 @@
         o If the profile is filesystem based, return the 'stat' timestamp
           of the file / directory to which 'path' points.
 
-        o If the profile is ZODB-based, return the Zopd modification time
+        o If the profile is ZODB-based, return the Zope modification time
           of the object to which 'path' points.
 
         o Return None if 'path' does not point to any object in any profile.
@@ -55,6 +55,9 @@
 
         o If the profile is ZODB-based, check that 'path' points to a
           "container" under the profile.
+
+        o Return None if 'path' does not resolve;  otherwise, return a
+          bool.
         """
 
     def listDirectory( path, skip=('CVS',) ):
@@ -62,6 +65,8 @@
         """ List IDs of the contents of a profile directory / folder.
 
         o Omit names in 'skip'.
+
+        o If 'path' does not point to a directory / folder, return None.
         """
 
     def shouldPurge():
@@ -69,7 +74,7 @@
         """ When installing, should the existing setup be purged?
         """
 
-def IExportContext( ISetupContext ):
+class IExportContext( ISetupContext ):
 
     def writeDataFile( filename, text, content_type, subdir=None ):
 




More information about the CMF-checkins mailing list