[CMF-checkins] CVS: CMF/CMFSetup - interfaces.py:1.1 rolemap.py:1.3

Tres Seaver tseaver at zope.com
Tue May 18 18:14:04 EDT 2004


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

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


  - Add entry points for import / export of role / permission map.

  - Document plugin / context interfaces.


=== Added File CMF/CMFSetup/interfaces.py ===
""" CMFSetup product interfaces

$Id: interfaces.py,v 1.1 2004/05/18 22:14:03 tseaver Exp $
"""

from Interface import Interface

class ISetupContext( Interface ):

    """ Context used for export / import plugins.
    """
    def getSite():

        """ Return the site object being configured / dumped.
        """

class IImportContext( ISetupContext ):

    def readDatafile( filename, subdir=None ):

        """ Search the current configuration for the requested file.

        o Search each profile in the configuration in order.

        o 'filename' is the name (without path elements) of the file.

        o 'subdir' is an optional subdirectory;  if not supplied, search
          only the "root" directory of each configured profile.

        o Return the file contents as a string, or None if the
          file cannot be found.
        """

    def getLastModified( path ):

        """ Return the modification timestamp of the item at 'path'.

        o Search profiles in the configuration in order.

        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
          of the object to which 'path' points.

        o Return None if 'path' does not point to any object in any profile.
        """

    def isDirectory( path ):

        """ Test whether path points to a directory / folder in a profile

        o If the profile is filesystem based, check that 'path' points to
          a subdirectory within the "root" directory of the profile.

        o If the profile is ZODB-based, check that 'path' points to a
          "container" under the profile.
        """

    def listDirectory( path, skip=('CVS',) ):

        """ List IDs of the contents of a profile directory / folder.

        o Omit names in 'skip'.
        """

    def shouldPurge():

        """ When installing, should the existing setup be purged?
        """

def IExportContext( ISetupContext ):

    def writeDataFile( filename, text, content_type, subdir=None ):

        """ Write data into the specified location.

        o 'filename' is the unqualified name of the file.

        o 'text' is the content of the file.

        o 'content_type' is the MIMEtype of the file.

        o 'subdir', if passed, is a path to a subdirectory / folder in
          which to write the file;  if not passed, write the file to the
          "root" of the target.
        """


class IPseudoInterface( Interface ):

    """ API documentation;  not testable / enforceable.
    """


class IImportPlugin( IPseudoInterface ):

    """ API for initializing / configuring a site from a profile.

    o 'context' must implement IImportContext.
    """
    def __call__( context ):

        """ Use data from 'context' to do initialization / configuration.
        """

class IExportPlugin( IPseudoInterface ):

    """ API for exporting a site to a serialization.
    """
    def __call__( context ):

        """ Use data from 'context' to do initialization / configuration.

        o 'context' must implement IExportContext.
        """


=== CMF/CMFSetup/rolemap.py 1.2 => 1.3 ===
--- CMF/CMFSetup/rolemap.py:1.2	Tue May 18 16:46:01 2004
+++ CMF/CMFSetup/rolemap.py	Tue May 18 18:14:03 2004
@@ -149,9 +149,38 @@
 
 InitializeClass( RolemapConfigurator )
 
-def exportRolemap(site):
+
+#
+#   Configurator entry points
+#
+_FILENAME = 'rolemap.xml'
+
+def importRolemap( context ):
+
+    """ Export roles / permission map as an XML file
+
+    o 'context' must implement IImportContext.
+    """
+    site = context.getSite()
+    text = context.readDatafile( FILENAME )
+
+    if text is not None:
+
+        rc = RolemapConfigurator( site ).__of__( site )
+        rc.parseXML( text )
+
+    return 'Role / permission map imported.'
+
+
+def exportRolemap( context ):
 
     """ Export roles / permission map as an XML file
+
+    o 'context' must implement IExportContext.
     """
-    rpe = RolemapConfigurator( site ).__of__( site )
-    return rpe.generateXML(), 'text/xml', 'rolemap.xml'
+    rc = RolemapConfigurator( site ).__of__( site )
+    text = rc.generateXML()
+
+    context.writeDataFile( _FILENAME, text, 'text/xml' )
+
+    return 'Role / permission map exported.'




More information about the CMF-checkins mailing list