[Zope] Copy to another storage using APE

Gabriel Genellina gagenellina at softlab.com.ar
Mon Dec 6 16:57:53 EST 2004


Hi

I'm trying to copy some objects from a FileStorage (data.fs) to another (a 
file system storage using APE) but I always get this error

File "C:\Archivos de 
programa\ZopeServer\lib\python\Products\Ape\lib\apelib\zodb3\connection.py", 
line 428, in identify
   raise InvalidObjectReference, (ZODB.POSException.InvalidObjectReference: 
Can't refer to <Folder instance at 017C2AD0>, located in Connection at 
015ba8bc>, from <ApeConnection at 0173d03c>

This used to work in previous versions of APE; I'm using now 0.8.1.
I just use _getOb(id) to obtain an object from one place and then 
_setObject(id, aq_base(obj)) to copy it to another place.
With newly created objects the APE storage works fine, only complains when 
copying objects from another storage.
I guess, the object "remembers" its original connection and then cant be 
stored in another place.
But this is exactly what I want, copy things from one storage to another.

This is a test script. Sorry if it's a bit long but I most of the code is 
to set up needed things.

=== begin ===
"""
This script tries to read a Folder from a FileStorage (data.fs)
and write it to a different filesystem-based Ape storage.
How to run: create a Folder inside the root (/test) and put something there.
The script will create a directory in [ZOPE]/var/test-export
which should contain the above folder (but fails).
Another folder /test2 (which is created on-the-fly) works fine.
"""

import os, sys
import Zope
from Products.Ape import apelib
from apelib.zodb3.storage import ApeStorage
from apelib.zope2.mapper import create_fs_mapper
from apelib.fs.connection import FSConnection
from apelib.zodb3.resource import StaticResource
from apelib.zodb3.db import ApeDB
from ZODB.FileStorage import FileStorage
from ZODB.DB import DB
from OFS.Folder import Folder
from Acquisition import aq_base

# Setup FileStorage for reading
path_to_datafs=os.path.join(CLIENT_HOME, 'data.fs')
fs_storage = FileStorage(path_to_datafs, create=0)
dbfs = DB(fs_storage)
connfs = dbfs.open()
rootfs = connfs.root()['Application']

# Setup export directory
path_export=os.path.join(CLIENT_HOME, 'test-export')
if os.path.exists(path_export):
     import shutil
     shutil.rmtree(path_export,1)

# Setup ApeStorage
mapper, conns = create_fs_mapper(path_export)
resource = StaticResource(mapper)
ape_storage = ApeStorage(resource, conns, clear_all=1)
dbape = ApeDB(ape_storage, None)
connape = dbape.open()
if not connape.root().has_key('Application'):
     from OFS.Application import Application
     connape.root()['Application'] = Application()
     get_transaction().commit()
rootape = connape.root()['Application']

# just to verify I can create something inside the export directory
get_transaction().begin()
id = 'test2'
obj = Folder()
obj.id = obj.title = id
rootape._setObject(id, aq_base(obj))
get_transaction().commit()

# copy test folder
get_transaction().begin()
id = 'test'
obj = rootfs[id]  # _getOb(id)
rootape._setObject(id, aq_base(obj))
get_transaction().commit()

dbape.close()
dbfs.close()
=== end ===


Gabriel Genellina
Softlab SRL 



More information about the Zope mailing list