durusmail: quixote-users: Re: Request contexts
Request contexts
2003-12-11
Re: Request contexts
2003-12-11
2003-12-11
2003-12-12
2003-12-12
2003-12-13
2003-12-13
2003-12-16
2003-12-16
2003-12-16
2003-12-16
2003-12-15
Re: Request contexts
2003-12-16
2003-12-16
2003-12-24
2003-12-30
2003-12-31
Re: Request contexts
Jason E. Sibre
2003-12-11
> P.S. If I'm just advertising my lousy design habits (and corrections to
> said habits), assuming my problems are common ones, I hope that someone
> will call me on it. Many eyes make fools wiser. ;-)

I think this sounds like a good idea, but I'll mention how I addressed this
same concern, in case it's a boon to anyone.

It's not a modification, just an approach.  Like you, I looked for a way to
pass configuration information to the app, and didn't think the quixote conf
file was a good place for stuff that didn't relate to quixote, so I came up
with the following approach:

I typically have a package that corresponds to the application, and it
contains two modules/sub-packages of interest for this discussion:  api, and
web.  "web" is the quixote UI stuff, and "api" is a module defining a class
that, when it's instantiated (with proper configuration information)
represents a 'live' application, and provides methods and attributes for
interacting with that application (the UI code only interacts with Quixote
and the API).  Within the api module, there is an attribute called
'configuration' which I initialize to contain all the info the class will
need when it is instantiated.  The driver script initializes the contents of
application.api.configuration after importing, but before calling the
Publisher.publish_fcgi().

I think an example may be called for:

excerpt from mp3/mp3player/api.py
############################################################################
import mp3.mp3db
import mp3.mpg123lib

from types import *
from mp3.mpg123lib import MPG123DeadError
from mp3.mpg123lib import PLAYING, PAUSED, STOPPED

configuration = {
    'paths'    : [],
    'dbhost'   : 'localhost',
    'dbname'   : 'mp3s',
    'dbuser'   : '',
    'dbpasswd' : '',
    'zippath'  : None
    }

userManager = None
__player = None

[...]
############################################################################


from the driver script:
############################################################################
[...]
import file_user_manager as fum

mp3.mp3player.api.configuration['paths']=['/mnt/mp3s/Audio']
mp3.mp3player.api.configuration['dbuser']='httpd'
mp3.mp3player.api.configuration['zipospath']='/srv/www/htdocs/pub/tmp'

mp3.mp3player.api.userManager = fum.UserManager('wempy.passwd')

import quixote_session_gadgets as qsg

session_mgr = qsg.get_simple_session_manager("/tmp/quixote-sessions/wempy",
604800)

app = SessionPublisher('mp3.mp3player.web', session_mgr=session_mgr)
app.read_config("wempy.quixote.conf")
app.setup_logs()
app.publish_fcgi()
[...]
############################################################################


It's not perfect, and I'm not advertising it as even being a particulary
good solution, but it is a way of getting the job done.

All things considered, I'd probably like (and use) this context attribute
you've introduced, as it provides a good place for storing not just
configuration info, but also things like my 'live' application instance.

Jason



reply