using a ZODB standalone app with Zope
Hello All, I'm trying to migrate a ZODB standalone application for use in Zope. I have a module that instantiates a ZODB storage upon import and then has module functions that return the root for this database. --- storage = FileStorage.FileStorage(Config.DB_FILENAME) db = DB(storage) def get_root(): conn = db.open() return conn.root() def commit(): get_transaction().commit() --- The current setup does not work in Zope, I get timeout errors and I'm guessing that the two databases interfere somehow. What I plan to do is to make use of the database created by Zope instead. In a python script how would I go about fetching the root of the database that is used by Zope. thanks, Istvan.
Istvan Albert wrote:
In a python script how would I go about fetching the root of the database that is used by Zope.
container.getPhysicalRoot() ...but it sounds like you're after something else, what are you trying to do? Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Chris Withers wrote:
In a python script how would I go about fetching the root of the database that is used by Zope.
container.getPhysicalRoot()
...but it sounds like you're after something else, what are you trying to do?
Thanks, I think that will work. Instead of using two separate ZODB databases (one for my data and one implicitly used by Zope) I was aiming at store my data in the Zope database as well. best, Istvan.
----- Original Message ----- From: "Istvan Albert" <ialbert@mailblocks.com> To: <zope@zope.org> Sent: February 18, 2005 8:43 AM Subject: [Zope] Re: using a ZODB standalone app with Zope
Chris Withers wrote:
In a python script how would I go about fetching the root of the database that is used by Zope.
container.getPhysicalRoot()
...but it sounds like you're after something else, what are you trying to do?
Thanks, I think that will work.
Instead of using two separate ZODB databases (one for my data and one implicitly used by Zope) I was aiming at store my data in the Zope database as well.
Have you looked at the DBTab product which allows you to mount multiple ZODBs (ie. one for code, one for data)? This works nicely for us. Jonathan
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jonathan Hobbs wrote: | ----- Original Message ----- | From: "Istvan Albert" <ialbert@mailblocks.com> | To: <zope@zope.org> | Sent: February 18, 2005 8:43 AM | Subject: [Zope] Re: using a ZODB standalone app with Zope | | | |>Chris Withers wrote: |> |> |>>>In a python script how would I go about fetching the root |>>>of the database that is used by Zope. |> |>>container.getPhysicalRoot() |>> |>>...but it sounds like you're after something else, what are you trying |>>to do? |> |>Thanks, I think that will work. |> |>Instead of using two separate ZODB databases (one for my data and |>one implicitly used by Zope) I was aiming at store my data in the Zope |>database as well. | | | Have you looked at the DBTab product which allows you to mount multiple | ZODBs (ie. one for code, one for data)? This works nicely for us. Note that the DBTab product is superseded in Zope 2.7.x by equivalent functionality built into Zope itself ("mounting" separate storages is done inside zope.conf). Tres. - -- =============================================================== Tres Seaver tseaver@zope.com Zope Corporation "Zope Dealers" http://www.zope.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCFgXAGqWXf00rNCgRAnhsAKCiSmJgIp4UXJnWMJL5izL4QX2bVQCcDErS fAN+YMum2DPNUIC4qRr4mPM= =sQIp -----END PGP SIGNATURE-----
Jonathan Hobbs wrote:
Have you looked at the DBTab product which allows you to mount multiple ZODBs (ie. one for code, one for data)? This works nicely for us.
Thanks for the suggestion, alas it might not be exactly what I am looking for. I tried to better formulate my problem in a subsequent post. This product is an interesting one nonetheless and I'm sure I'll be making use of it. best, Istvan.
Chris Withers wrote:
container.getPhysicalRoot()
...but it sounds like you're after something else, what are you trying to do?
Turns out this does not quite work as I expected. It returns an Application and not a Zope root. My biggest problem in describing what I want to do is that it is seemingly too simple. Sometimes that gets in the way. Simply put I want to use Zope's ZODB as ZODB and not as a high level Zope object. With a standalone ZODB I would do something like this: from ZODB import FileStorage, DB from BTrees.OOBTree import OOBTree storage = FileStorage.FileStorage('test.fs') db = DB(storage) conn = db.open() dbroot = conn.root() dbroot['foo'] = OOBTree() dbroot['foo'][1] = 'bar' get_transaction().commit() db.pack() print dbroot['foo'][1] how would I achieve this exact same result from within Zope say with a python script that operates on the ZODB that Zope uses to store its objects (usually Data.fs)? thanks, Istvan.
Istvan Albert wrote:
My biggest problem in describing what I want to do is that it is seemingly too simple. Sometimes that gets in the way. Simply put I want to use Zope's ZODB as ZODB and not as a high level Zope object. With a standalone ZODB I would do something like this:
from BTrees.OOBTree import OOBTree replace these bits... from ZODB import FileStorage, DB storage = FileStorage.FileStorage('test.fs') db = DB(storage) conn = db.open() dbroot = conn.root() dbroot['foo'] = OOBTree() dbroot['foo'][1] = 'bar' ...with: dbroot = self.getPhysicalRoot() dbroot.foo = OOBTree() dbroot.foo[1] = 'bar'
You won;t be abel to do this from a python script, since OOBTree and direct attribute assignment are not available to 'untrusted code' (ie: python scripts) Use an external method instead. cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (4)
-
Chris Withers -
Istvan Albert -
Jonathan Hobbs -
Tres Seaver