durusmail: quixote-users: zodb and scgi design question
zodb and scgi design question
2004-05-22
2004-05-24
2004-05-25
zodb and scgi design question
John Miller
2004-05-22
Moving along the quixote curve. I've succeeded in installing scgi on my
system, and qxdemo now whizzes along remarkably quickly! So, my next
step is to replace the pickling storage system with the zodb 3.2.1
backend. What I'm wondering is how to initialize the database
connection in the context of the scgi server (avoiding reinitializing
it everytime a URL is hit...) Right now, the __init__.py file at the
top of the qxdemo directory is empty, so I thought about putting the
zodb initializing stuff there, but I'm thinking that will be called
with every click, right? But I'm not sure where else to put it. It
seems as though it should be called when the scgi server is started.
I'm planning to use the driver script that came inside quixote/demo:
demo_scgi.py modified like so:

'''
from scgi.quixote_handler import QuixoteHandler, main
from quixote import enable_ptl, Publisher

class QxdemoPublisher(Publisher):
     def __init__(self, *args, **kwargs):
         Publisher.__init__(self, *args, **kwargs)

         # Open the configured log files
         self.setup_logs()

class QxdemoHandler(QuixoteHandler):
     publisher_class = QxdemoPublisher
     root_namespace = "qxdemo.ui"
     prefix = "/qxdemo"

# Install the import hook that enables PTL modules.
enable_ptl()
main(QxdemoHandler)
'''

This works just fine with the pickling version of qxdemo. However,
where inside of this file would I put the following zodb initialization
code:

'''
import ZODB.config
db =
ZODB.config.databaseFromURL('/Library/Python/2.3/qxdemo/data/
data.conf')
conn = db.open()
dbroot = conn.root()

# Ensure that a 'categories' key is present in the root
if not dbroot.has_key('categories'):
     from BTrees.OOBTree import OOBTree
     dbroot['categories'] = OOBTree()

# Ensure that a 'links' key is present in the root
if not dbroot.has_key('links'):
     from BTrees.OOBTree import OOBTree
     dbroot['links'] = OOBTree()

categories = dbroot['categories']
links = dbroot['links']
'''

Just put it at the top before the first class definition? And will
'categories' and 'links' be available in the 'links.ptl' user interface
file to access the database? Or is some other design
preferred/expected? I'd appreciate a bit of guidance here before I go
experimenting and getting totally confused. Thanks!

John Miller



reply