List Info

Thread: access to apache configuration variables under mod_python




access to apache configuration variables under mod_python
country flaguser name
United States
2007-05-31 09:00:17
Howdy,

I've been writing a little CherryPy based application for
the last year 
or so.  Its received a moderate amount of usage and most of
the users of 
the software are not programmers.  They're fine with setting
up Apache 
for proxying the requests through to the cherrypy server,
and can manage 
their way through a cherrypy configuration file, but they'd
rather not 
touch the code of the actual application.

Recently the codebase was upgraded to support CherryPy 3.0
and I've been 
trying to make it so in addition to running as an
independent web 
server, it also can run under mod_python.  Normally to run
the 
application on uses:

python myapp.py -c CONFIGURATIONFILE

Or, they just call their configuration file default.conf and
it reads in 
the configuration automatically.  I'd like to find a way to
do something 
similar to passing this command line argument using
mod_python and cherrypy.

Here's a snippet of what the configuration in httpd.conf may
look like:

         <Location "/gal2">
             PythonPath
"sys.path+['/home/patrick/pennave/src']"
             SetHandler python-program
             PythonHandler cherrypy._cpmodpy::handler
             PythonOption cherrypy.setup
myapp::setup_server
             PythonDebug On
         </Location>

In a CGI environment, I could use the SetEnv directive for
apache to set 
environment variables and then have the application use
os.getenv to 
read the variable back.  But mod_python doesn't handle
environment 
variables.

The mod_python way is to use "PythonOption", which
then allows you to 
get all the PythonOption declarations using
req.get_options().  Which is 
fine in most cases, but again, I can't get access to this
because 
setup_server is called with no arguments and as near as I
can tell, 
_cpmodpy.py doesn't do anything to pass that through. 
There's a 
roundabout way to get access to part of the req object
through the 
cherrypy.request.rfile object, but alas, this does not
expose the 
get_options method.

While it's simple enough for me to modify cpmodpy.py to
allow for 
get_options on the req object, I'd rather find a way to pass
this 
information without requiring my users to modify their
CherryPy 
installations.

Any hints?

Thanks!

--Patrick

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: access to apache configuration variables under mod_python
country flaguser name
United States
2007-05-31 11:42:33
Patrick Wagstrom wrote:
> Normally to run the application one uses:
> 
> python myapp.py -c CONFIGURATIONFILE
> 
> Or, they just call their configuration file
default.conf
> and it reads in the configuration automatically.  I'd
like
> to find a way to do something similar to passing this
> command line argument using mod_python and cherrypy.
> 
> ...
> 
> The mod_python way is to use "PythonOption",
which then
> allows you to get all the PythonOption declarations
using 
> req.get_options()...
> 
> While it's simple enough for me to modify cpmodpy.py
to
> allow for get_options on the req object, I'd rather
find
> a way to pass this information without requiring my
users
> to modify their CherryPy installations.

I'd probably just wrap _cpmodpy.handler:

# mycpapp.py
from cherrypy import _cpmodpy

_isSetUp = False
def mphandler(req):
    global _isSetUp
    if not _isSetUp:
       
load_conf_file(req.get_options()['myapp.config_file'])
        _isSetUp = True
    return _cpmodpy.handler(req)

----

<Location "/gal2">
    PythonPath
"sys.path+['/home/patrick/pennave/src']"
    SetHandler python-program
    
    # These two lines changed:
    PythonHandler mycpapp::mphandler
    PythonOption myapp.config_file
/home/patrick/pennave/app.conf
    
    PythonOption cherrypy.setup myapp::setup_server
    PythonDebug On
</Location>


Robert Brewer
System Architect
Amor Ministries
fumanchuamor.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: access to apache configuration variables under mod_python
country flaguser name
United States
2007-05-31 17:34:14
On Jun 1, 12:00 am, Patrick Wagstrom <patr...wagstrom.net> wrote:
> In a CGI environment, I could use the SetEnv directive
for apache to set
> environment variables and then have the application use
os.getenv to
> read the variable back.  Butmod_pythondoesn't handle
environment
> variables.

In mod_python you can still use SetEnv. Such values will
appear in
req.subprocess_env of mod_pythpon request object. I have
never
actually been able to work out why mod_python has a
separate
PythonOption directive as well. The only reason I have been
able to
think of is so that those Python options don't get passed in
the
environment to CGI scripts or other Apache handlers.

Graham


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )