#2661 closed defect (wontfix)
(mod_python) TracError: The environment options "TRAC_ENV" ... are missing.
Reported by: | Owned by: | Matthew Good | |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | web frontend/mod_python | Version: | 0.9.3 |
Severity: | normal | Keywords: | needinfo |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
TRAC-0.9.3 / SVN-1.3.0 / Python-2.3.2 / Apache-2.0.55 / Windows-NT
I tried to configure a TRAC environment for multiple projects. But my directory structure isn't compatible to the configuration described in TracModPython. I want to implement the multi project access with RewriteRules of Apache - with these rules it's easy to "construct" the TRAC-path for the current project.
The problem:
In the parameters of a RewriteRule, I can only define environment variables, but not PythonOptions. For the mod_python-access to TRAC, only PythonOptions are relevant: if I try to define the TRAC_ENV like
SetEnv TRAC_ENV "d:/svn/test/trac.db"
this is not accepted by TRAC:
PythonHandler trac.web.modpython_frontend: TracError: The environment options "TRAC_ENV" or "TRAC_ENV_PARENT_DIR" or the mod_python options "TracEnv" or "TracEnvParentDir" are missing. Trac requires one of these options to locate the Trac environment(s).
If I read this error text, I could understand that the definition of TRAC_ENV (= normal environment variable) and TracEnv (= PythonOption) are the same - but it isn't. The TRAC_ENV-definition with SetEnv isn't possible. I haven't found a way to use such an environment variable to declare a PythonOption within the location-directive. The following http.conf doesn't work:
RewriteRule ^/projects/([^/]+)(/?) /projects/$1 [L,E=TRAC_ENV:d:/svn/$1/trac.db,E=TRAC_URI_ROOT:/projects/$1] <LocationMatch "/projects/[^/]+"> SetHandler mod_python PythonHandler trac.web.modpython_frontend PythonOption TracEnv %{TRAC_ENV} PythonOption TracUriRoot %{TRAC_URI_ROOT} </LocationMatch>
The solution could be a little patch of modpython_frontend.py:
def handler(req): options = req.get_options() ... if req.subprocess_env.has_key('TRAC_ENV'): options['TracEnv'] = req.subprocess_env['TRAC_ENV'] if req.subprocess_env.has_key('TRAC_URI_ROOT'): options['TracUriRoot'] = req.subprocess_env['TRAC_URI_ROOT'] ... dict_translate ...
With these lines of code, the two important options "TracEnv" and "TracUriRoot" can be first defined as normal environment variables with a RewriteRule and then be used as PythonOption. My http.conf now:
RewriteRule ^/projects/([^/]+)(/?) /projects/$1 [L,E=TRAC_ENV:d:/svn/$1/trac.db,E=TRAC_URI_ROOT:/projects/$1] <LocationMatch "/projects/[^/]+"> SetHandler mod_python PythonHandler trac.web.modpython_frontend </LocationMatch> <LocationMatch "/projects/[^/]+/login"> AuthType Basic AuthName "TRAC" AuthUserFile d:\svn\.htaccess Require valid-user </LocationMatch>
Now, every directory structure is possible with mod_python.
Attachments (1)
Change History (9)
comment:1 by , 19 years ago
follow-up: 3 comment:2 by , 19 years ago
This patch is more general than my additional code. For me, this ticket can be closed because the problem is solved and will be available for all with the next release …
comment:3 by , 18 years ago
Replying to anonymous:
This patch is more general than my additional code. For me, this ticket can be closed because the problem is solved and will be available for all with the next release …
Do you mean the patch posted by cboos fixed it, or was there another change which has been committed which fixed the problem? I'm actually not sure cboos's patch would help since I believe that the settings would need pulled from req.subprocess_env
, not os.environ
.
If this is working for you I would like to close this ticket, but I'm not sure I understand what solved it for you.
comment:4 by , 18 years ago
I haven't tested the patch of cboos. For the current version (0.10b1), my patch and the patch of cboos can't be used anymore - the code has been changed. Does the object req.subprocess_env
exist? Is a new patch available?
comment:5 by , 18 years ago
Milestone: | → 0.10.1 |
---|---|
Owner: | changed from | to
Well, AFAIK cboos's patch won't work since it's trying to copy the settings from os.environ
, but I believe those options will be set in the mod_python subprocess_env
. I'll see if it's possible to support this for 0.10.1.
comment:6 by , 18 years ago
Keywords: | needinfo added |
---|
Well, options set via SetEnv
are in the subprocess_env
, but the RewriteRule
does not work for me.
I'll attach a patch for reading TRAC_ENV, etc. but since I can't confirm whether it works with RewriteRule
I'll hold off on this.
by , 18 years ago
Attachment: | mod_python_subprocess_options.patch added |
---|
try reading TRAC_ENV from the environment if mod_python's TracEnv
is not set
comment:7 by , 18 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I've tried the RewriteRule
setup described above, but TRAC_ENV
is not present in req.subprocess_env
. Without that working I don't see a reason to actually try to patch this.
comment:8 by , 18 years ago
Milestone: | 0.10.4 |
---|
Can you try this patch:
and retry with:
and without setting
PythonOption TracEnv
.