[Zope-CMF] error installing CMFCalendar in CMF-1.1beta

Tres Seaver tseaver@palladion.com
Sun, 03 Jun 2001 20:29:39 -0400


marc lindahl wrote:

> No prob...
> I'm boned, because I had a pile of stuff in the portal_metadata tool, and
> the updated version is incompatible (I think, due to inheriting Persistent),
> and there's no current way to import/export just the data from the tool,
> independant of the internal structure...  AFAIK!


Marc,

We could probably work out a means of dumping the data.  How about an
ExternalMethod which creates a chunk of Python to replicate it?  Something
like:

#--------------------- snip here --------------------------------
import string

def dumpMetadataTool( self ):
     """
         Extract the contents of the 'portal_metadata' tool as a chunk
         of Python for repopulation.
     """
     tool = self.portal_metadata
     lines = []
     add = lines.append
     add( '## Script (Python) "metadata_load"' )
     add( '##title=Load Metadata Tool' )
     add( '##parameters=' )
     add( 'tool = context.portal_metadata' )

     for element, spec in tool.listElementSpecs():

         for content_type, policy in spec.listPolicies():

             if content_type is not None:

                 add( 'try: tool.removeElementPolicy( "%s", "%s" )'
                    % ( element, content_type ) )
                 add( 'except: pass' )

                 spec_args = ( 'tool.addElementPolicy( "%s", "%s",'
                             % ( element, content_type ) )
             else:
                 spec_args = ( 'tool.updateElementPolicy( "%s", 
"<default>",'
                             % element )

             if policy.isMultiValued():
                 policy_args = ( ' %d, %d, %s, %d, %s )'
                               % ( policy.isRequired()
                                 , policy.supplyDefault()
                                 , policy.defaultValue()
                                 , policy.enforceVocabulary()
                                 , policy.allowedVocabulary()
                                 )
                               )
             else:
                 policy_args = ( ' %d, %d, "%s", %d, %s )'
                               % ( policy.isRequired()
                                 , policy.supplyDefault()
                                 , policy.defaultValue()
                                 , policy.enforceVocabulary()
                                 , policy.allowedVocabulary()
                                 )
                               )

             add( spec_args + policy_args )

     return string.join( lines, '\n' )
#--------------------- snip here --------------------------------

I've just run this, and it seems to work for me.

Tres
-- 
===============================================================
Tres Seaver                                tseaver@digicool.com
Digital Creations     "Zope Dealers"       http://www.zope.org