[Grok-dev] Manipulating the Grok ZODB via Script.

Jasper Spaans j at jasper.es
Mon Jul 12 00:55:34 EDT 2010

Op 11 jul 2010, om 15:12 heeft Achim Domma het volgende geschreven:

> is it possible to run a script against an existing ZODB, using the complete Grok infrastructure? My idea is to fill an empty application with some sample data to be able to "play" with it. I guess I could do it in an event handler for the ObjectCreated event of the application. But that does not feel god to me. Any hint?

Sure, not a problem. Start by setting up a connection to your ZODB, and fetching the root object:

>>> from ZODB import FileStorage, DB

>>> storage = FileStorage.FileStorage('/path/to/your/Data.fs')
>>> db = DB(storage)
>>> conn = db.open()
>>> dbroot = conn.root()

Now you can add any object you like:

>>> app = dbroot['myapp'] = MyApplication()
>>> app['cave'] = MyCave()

Finally, don't forget to commit your transaction:

>>> import transaction
>>> transaction.commit()

After this, you can start your grok application and everything should be in place.

Jasper Spaans                                          http://jasper.es/
             This line was last modified 0 seconds ago.

More information about the Grok-dev mailing list