Edgewall Software
Modify

Opened 18 years ago

Closed 17 years ago

Last modified 17 years ago

#2661 closed defect (wontfix)

(mod_python) TracError: The environment options "TRAC_ENV" ... are missing.

Reported by: schuetze@… 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)

mod_python_subprocess_options.patch (1.9 KB ) - added by Matthew Good 18 years ago.
try reading TRAC_ENV from the environment if mod_python's TracEnv is not set

Download all attachments as: .zip

Change History (9)

comment:1 by Christian Boos, 18 years ago

Can you try this patch:

Index: modpython_frontend.py
===================================================================
--- modpython_frontend.py	(revision 2797)
+++ modpython_frontend.py	(working copy)
@@ -172,8 +172,7 @@
             self.list.append(util.Field(key, StringIO(value), 'text/plain',
                              {}, None, {}))
 
-def dict_translate(orig, *mappings):
-    result = {}
+def dict_translate(result, orig, *mappings):
     for src, dest in mappings:
         if src in orig:
             result[dest] = orig[src]
@@ -191,7 +190,7 @@
         os.environ['PYTHON_EGG_CACHE'] = req.subprocess_env['PYTHON_EGG_CACHE']
 
     mpr = ModPythonRequest(req, options)
-    project_opts = dict_translate(options,
+    project_opts = dict_translate(dict(os.environ), options,
             ('TracEnv', 'TRAC_ENV'),
             ('TracEnvParentDir', 'TRAC_ENV_PARENT_DIR'),
             ('TracEnvIndexTemplate', 'TRAC_ENV_INDEX_TEMPLATE'),

and retry with:

SetEnv TRAC_ENV "d:/svn/test/trac.db"

and without setting PythonOption TracEnv.

comment:2 by anonymous, 18 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 …

in reply to:  2 comment:3 by Matthew Good, 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 schuetze@…, 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 Matthew Good, 18 years ago

Milestone: 0.10.1
Owner: changed from Christopher Lenz to Matthew Good

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 Matthew Good, 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 Matthew Good, 18 years ago

try reading TRAC_ENV from the environment if mod_python's TracEnv is not set

comment:7 by Matthew Good, 17 years ago

Resolution: wontfix
Status: newclosed

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 Matthew Good, 17 years ago

Milestone: 0.10.4

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Matthew Good.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Matthew Good to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.