[Zope] Re: Copy from Data.fs to APE

Gabriel Genellina gagenellina at softlab.com.ar
Thu Mar 10 08:24:00 EST 2005


At Thursday 10/3/2005 03:16, markus.luckey at sdm.de wrote:

>I'm currently trying to copy my data from DATA.FS to APE
 with no success.
>Import does not work, copy doesn't either.
>Therefore I search google for it and found your thread. Do you have any 
>hint for me, helping me copy my files?
>But be patient, i'm a newbe :-)

Try this, it's my test example. I hope it's clear enough.

--- begin testexp.py ---
"""
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 a copy of the test folder.
"""

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

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

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

# Setup ApeStorage
print 'Creating mapper'
mapper, conns = create_fs_mapper(path_export)
resource = StaticResource(mapper)
print 'Creating ApeStorage'
ape_storage = ApeStorage(resource, conns, clear_all=1)
dbape = ApeDB(ape_storage, None)
print 'Open ApeStorage'
connape = dbape.open()
if not connape.root().has_key('Application'):
     print 'Creating root object'
     from OFS.Application import Application
     connape.root()['Application'] = Application() # may be any container, 
Folder() is fine
print 'Getting root object of ApeStorage'
rootape = connape.root()['Application']

# just to verify I can create something inside the export directory
print 'Creating a test2 folder inside APE'
id = 'test2'
obj = Folder()
obj.id = obj.title = id
rootape._setObject(id, aq_base(obj))

# copy test folder
print 'Reading test folder'
id = 'test'
obj = rootfs._getOb(id)
print 'Obtaining a copy of test folder'
dup = obj._getCopy(rootape)
print 'Writing copy in APE'
rootape._setObject(id, dup)

print 'Closing all'
dbape.close()
dbfs.close()
print 'Done'
--- end testexp.py ---


Gabriel Genellina
Softlab SRL 



More information about the Zope mailing list