2009/11/15 Jason Garber <
bo...@gahooa.com>:
> Hi Cem,
> Not exactly an "anwser", but we auto-generate a "Local.py" file per
> installation (as well as our apache configuration files). Local.py linked
> to from the main application package directory (you can set the python path
> from apache configuration).
> class App:
> from .Local import MemcachedServers, SecureURL, StandardURL
> Then...
> App.SecureURL
I'd be suggesting something similar, ie., using something that can't
change per request.
That said, when you use SetEnv directive, those variables are
available in the WSGI environ dictionary passed as first argument to
the WSGI application object when called for a request. You could
extract them from the WSGI environ and then use them. Because though
they are per request and only available when application called for a
request, you would need thread locking on the creation of the
singleton.
Option options are to key off value of mod_wsgi.application_group.
This is not the one in WSGI environment though, but from doing:
import mod_wsgi
if mod_wsgi.application_group.find('xxx') != -1:
...
The value of mod_wsgi.application_group by default incorporates site
server name and mount point of WSGI application. If your different
staging environments are on different hosts, then you can distinguish
that way.
One could also use mod_wsgi.process_group. So, if using
WSGIDaemonProcess/WSGIProcessGroup to separate instances, you could
customise behaviour based on name of process group.
import mod_wsgi
if mod_wsgi.process_group == 'development':
...
You need mod_wsgi 2.4 or later to get access to these special module
variables, but you are on 2.4 so okay.
Graham