how to export data from ZODB to text files

Josef Meile jmeile at hotmail.com
Fri Jun 10 11:18:25 CEST 2005


Hi again,

> I thought also about Python script like
> 
> 
>  //connect to database 
>  >>> from ZODB import FileStorage, DB
>  >>> storage = FileStorage.FileStorage('Data.fs') 
>  >>> db = DB(storage)
>  >>> conn = db.open()
>  >>> dbroot = conn.root()
I just found an information that may be useful for you:

* ZODB for Python Programmers By Michael Pelletier:
   http://www.informit.com/articles/article.asp?p=23413&rl=1

* A Simple ZODB viewer in wxPython:
   http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409012

The first link contains some useful examples and explanations. The
second one could help you to see how your zodb is organized. In the
links that Peter post, there is also an useful powerpoint presentation.

According to the first link, the ZODB is a persistent dictionary that
you can access like:

 >>> db = DB(storage)
 >>> connection = db.open()
 >>> root = connection.root()

If I'm not wrong, you could see what objects are in root of your zodb by
doing:

 >>> print root.keys()

After that you could get your plone site by doing:

 >>> ploneSite = root['ploneFolder']

Where if I'm not wrong, "ploneFolder" may be a key in the root
dictionary. Then if plone is like CMF, it must have a "portal_catalog"
instance in it, so, you can get it by:

 >>> catalog = getattr(ploneSite,'portal_catalog',None)

If at this point catalog = None, then you have to print the objects in
the plone site by doing:

 >>> print ploneSite.objectIds()

Once you find the catalog object, you could try the script I post before
from the command line.

I haven't tested this, but I hope it helps.

Regards,
Josef Meile




More information about the Python-list mailing list