Re: [Zope-dev] serialization with Ape

2003-06-11 Thread Shane Hathaway
Christian Scholz wrote:
I then detected the fascades in io.py which I tried to use (dunno if they're
thought to be used for such a purpose actually ;-):
root_mapper, conns = createMapper(fspath)
ei=ExportImport(root_mapper,conns)
ei.exportObject(object)
This is *exactly* the purpose ExportImport is meant for, but it's quite 
new and unfinished.  I'm glad you found it, although it's only in CVS, 
not in the released version of Ape.

Unfortunately this results in an exception 

Type: MappingError
Error Value: Path keychains require a name
So can maybe somebody point me to the easiest way to serialize an object
using the fsmapper (Shane? ;-) ?
You're on the right track.  I wonder what went wrong.

I am also interested in reading a serialized object from the fs again
and writing it to the fs. Also I wonder if I need to delete objects which
have been modified before another export or if there's a possibility to
just change it).
Ape will assign new OIDs on import, so you don't have to delete objects 
first.

(and the best would be of course some simple methods for reading/writing
a whole directory recursively. I don't know if something like this is already
in there somehow or how it works internally.. seems all a bit magic to me ;-)
Again, ExportImport is designed to do this.

Shane

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] serialization with Ape

2003-06-11 Thread Christian Scholz
Hi!

I actually now have a (as it seems) working version of my first
approach, just using _setObject() etc. which even works recursively.
Has this some drawbacks except it looks a bit like a hack due to the
call of commit()?
I also have the deserialization working and basically it's just a 
copying between two ZODBs I'd say.

On Wed, Jun 11, 2003 at 10:12:46AM -0400, Shane Hathaway wrote:
 Christian Scholz wrote:
  I then detected the fascades in io.py which I tried to use (dunno if they're
  thought to be used for such a purpose actually ;-):
  
  root_mapper, conns = createMapper(fspath)
  ei=ExportImport(root_mapper,conns)
  ei.exportObject(object)
 
 This is *exactly* the purpose ExportImport is meant for, but it's quite 
 new and unfinished.  I'm glad you found it, although it's only in CVS, 
 not in the released version of Ape.

Well, I am looking a bit on the repository and was reading
log messages ;-)

  Unfortunately this results in an exception 
  
  Type: MappingError
  Error Value: Path keychains require a name
  
  So can maybe somebody point me to the easiest way to serialize an object
  using the fsmapper (Shane? ;-) ?
 
 You're on the right track.  I wonder what went wrong.

I looked into that a bit and in core/io.py line 316 you do

   return kgen.makeKeychain(event, None, 1)

so name is None here as it seems. I just dunno if it's a special case
because I was doing something wrong or not ;-)

  I am also interested in reading a serialized object from the fs again
  and writing it to the fs. Also I wonder if I need to delete objects which
  have been modified before another export or if there's a possibility to
  just change it).
 
 Ape will assign new OIDs on import, so you don't have to delete objects 
 first.

Well, at least with my first approach I need to do that because I just
do a folder._setObject() and this fails then of course.

  (and the best would be of course some simple methods for reading/writing
  a whole directory recursively. I don't know if something like this is already
  in there somehow or how it works internally.. seems all a bit magic to me ;-)
 
 Again, ExportImport is designed to do this.

Will it also do it recursively? I found out that when I do it via
folder._setObject() it will also serialize all content which is quite
nice :)
What is actually the result of an export? Where in the fs is it stored then?
Is the whole path to the object in ZODB is taken ?

But thanks for the answer and thanks for Ape! :)

-- christian

-- 
COM.lounge  http://comlounge.net/
communication  design [EMAIL PROTECTED]

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] serialization with Ape

2003-06-11 Thread Shane Hathaway
Christian Scholz wrote:
I actually now have a (as it seems) working version of my first
approach, just using _setObject() etc. which even works recursively.
Has this some drawbacks except it looks a bit like a hack due to the
call of commit()?
I also have the deserialization working and basically it's just a 
copying between two ZODBs I'd say.
This will work if you duplicate the objects first.  apelib.zodb3.utils 
has a copyOf() function that reliably duplicates ZODB objects.

Doing it this way uses the whole ZODB machinery to import/export. 
There's nothing wrong with that other than it being a lot of extra work.

Unfortunately this results in an exception 

   Type: MappingError
   Error Value: Path keychains require a name
So can maybe somebody point me to the easiest way to serialize an object
using the fsmapper (Shane? ;-) ?
You're on the right track.  I wonder what went wrong.


I looked into that a bit and in core/io.py line 316 you do

   return kgen.makeKeychain(event, None, 1)

so name is None here as it seems. I just dunno if it's a special case
because I was doing something wrong or not ;-)
It's intentional, but perhaps it needs to explain itself better.  It's 
trying to figure out what OID to assign an object and there isn't enough 
information available.

(and the best would be of course some simple methods for reading/writing
a whole directory recursively. I don't know if something like this is already
in there somehow or how it works internally.. seems all a bit magic to me ;-)
Again, ExportImport is designed to do this.


Will it also do it recursively? I found out that when I do it via
folder._setObject() it will also serialize all content which is quite
nice :)
Yes, it's recursive.

What is actually the result of an export? Where in the fs is it stored then?
Is the whole path to the object in ZODB is taken ?
I don't know where it would try to export--I haven't thought about that 
yet. ;-)

But thanks for the answer and thanks for Ape! :)
You're welcome!

Shane

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] serialization with Ape

2003-06-11 Thread Shane Hathaway
Christian Scholz wrote:
root_mapper, conns = createMapper(fspath)
ei=ExportImport(root_mapper,conns)
ei.exportObject(object)
Ah-ha, I just realized what went wrong.  You need to tell exportObject() 
where to export.  PathKeychainGenerator refused to guess.  Try changing 
the last line to:

ei.exportObject(object, keychain=('some/path/under/fspath',))

It's still obtuse.  I'll think about how to make that cleaner.

Shane

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] serialization with Ape

2003-06-11 Thread Christian Scholz
Hi again!

 Christian Scholz wrote:
  root_mapper, conns = createMapper(fspath)
  ei=ExportImport(root_mapper,conns)
  ei.exportObject(object)
 
 Ah-ha, I just realized what went wrong.  You need to tell exportObject() 
 where to export.  PathKeychainGenerator refused to guess.  Try changing 
 the last line to:
 
  ei.exportObject(object, keychain=('some/path/under/fspath',))

I now tested it and had the following results:

- the last item of the path needs to be the same id as the object has
- only objects derived from Objectmanager in the end can be serialized.
- they are not written to disk as long as I don't do

conns['fs'].vote()
conns['fs'].finish()

After that it worked quite well :)

I now did the import the other way round with

obj=ei.importObject(keychain)

and then using _setObject with that object in order to store it again
in the usual ZODB (Data.fs). Is this ok? Or do I again need to do some copy?

 It's still obtuse.  I'll think about how to make that cleaner.

Well, for me the whole thing actually is magic. But maybe it helps
if there is an example of usage in the docstring. 

But it seems working now, so fine :-)

Thanks again!

Christian

-- 
COM.lounge  http://comlounge.net/
communication  design [EMAIL PROTECTED]

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )