-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Paul Smith wrote:
> Hi,
> 
> We've been playing with the FSDump product
> (http://www.zope.org/Members/tseaver/FSDump) over the last few days, and
> all appears to be working fine, except for exporting ZClass based objects.
> 
> The 'offending' part of the Dumper.py script appears to be:
> 
> def _dumpZClass( self, obj, path=None ):
>         #   Dump properties of obj (assumed to be a ZClass) to the
>         #   filesystem as a directory, including propertysheets and
>         #   methods, as well as any nested ZClasses.
>         if path is None:
>             path = ''
>         path = os.path.join( path, obj.id )
>         file = self._createMetadataFile( path, '' )
>         file.write( 'title:string=%s\n' % obj.title )
> 
> ### only getting this far as _zclass_ causes attribute error
> 
>         file.write( 'metatype:string=%s\n' % obj._zclass_.meta_type )
>         file.write( 'bases:tokens=%s\n'
>                   % ','.join( map( lambda klass: str(klass), obj._zbases
> ) )
>                   )
>         file.write( 'class_id:int=%s\n' % obj._zclass_.__module__ )
>         file.close()
> 
> I've indicated within the code snippet above that when parsing ZClass
> objects, it's only working to the point where it's successfully written
> out the title to the .metadata file, but then fails. We put in some
> debug logging, which reveals:
> 
> exceptions.AttributeError _zclass_[('zope/Products/FSDump/Dumper.py',
> 158, '_dumpObject', 'handler( object, path )'),
> ('zope/Products/FSDump/Dumper.py', 454, '_dumpZClass', "file.write(
> 'metatype:string=%s\\n' % obj._zclass_.meta_type )")])
> 
> which suggests _zclass_ is an attribute not available on our objects.
> 
> These are fairly basic ZClass objects for news items, and I've tried
> creating several additional test Products to try and determine what is
> required to get this to work, but to no avail.
> 
> If anyone has any pointers as to what needs doing to get FSDump to dump
> out ZClass objects, I'd be more than happy to hear suggestions!

Hmmm, I don't recall for sure, but I *think* the dumper is expecting to
dump the actual ZClass (as in '/Control_Panel/YourProduct/YourClass'),
rather than instances made from it.  The '_zclass_' attribute is not
found on the instances.

I *think* you need to write your own dumper function, and "register" it
(via monkey-patch) into Products.FSDump.Dumper.Dumper._handlers for the
meta_type of your instances.  E.g., in a filesystem product (or
ExternalMethod)::

- -------------------------- 8< ---------------------------
def _dumpMyZClassInstances(dumper, object, path):
    """ Create a file or files on the filesystem
    """

def initialize(context):  # could be the ExternalMethod, too

    from Products.FSDump.Dumper import Dumper

    handler_overrides = {'My ZClass' : _dumpMyZClassInstances,
                      # register others here
                        }

    Dumper._handlers.update(handler_overrides)

- -------------------------- 8< ---------------------------


Tres.
- --
===================================================================
Tres Seaver          +1 202-558-7113          [EMAIL PROTECTED]
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFC/LSi+gerLs4ltQ4RAjV0AJ9f/DGN9Ux0xJ8NiK1kvxvuUxG3jACdEE8l
1d2YeXPaIzSuAWzEUndGM2c=
=BLTZ
-----END PGP SIGNATURE-----

_______________________________________________
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to