Re: [viewvc-dev] [PATCH] mod_python configuration

Alon Bar-Lev <[email protected]> Sat, 24 Sep 2011 00:22:19 +0300
Newsgroups gmane.comp.version-control.cvs.viewcvs.devel
Message-ID <CAOazyz0P0BUzY2pwfT00=VSXuqMRv4kvS1UsR1anMtsf0Z+Zow@mail.gmail.com>
Done [1].

[1] http://viewvc.tigris.org/issues/show_bug.cgi?id=494

On Fri, Sep 23, 2011 at 6:28 PM, C. Michael Pilato <[email protected]> wrote:
> Sorry, Alon.  Been busy doing other things and haven't had a chance to
> comment on this.
>
> I do believe there is value in being able to programmatically define the
> configuration file under mod_python (and mod_wsgi, and FastCGI, etc.).  At
> this time, the most useful thing you could do would be a file an issue in
> the ViewVC tracker for this enhancement, hang your latest patch on it, and
> point to this mailing list thread.
> (http://viewvc.tigris.org/ds/viewMessage.do?dsForumId=4251&dsMessageId=2839188)
>
>
> On 09/23/2011 06:42 AM, Alon Bar-Lev wrote:
>> Hello,
>> I don't want to nag...
>> Just wanted to know if adding the ability to send config file via the
>> mod_python/cgi interface is something that will be considered and if I
>> can help further to push this forward.
>> Thanks!
>>
>> On Sun, Sep 18, 2011 at 6:17 PM, Alon Bar-Lev <[email protected]> wrote:
>>>
>>> Can I help further in this issue?
>>>
>>> On Thu, Sep 15, 2011 at 8:11 PM, Alon Bar-Lev <[email protected]> wrote:
>>>>
>>>> On Thu, Sep 15, 2011 at 7:51 PM, C. Michael Pilato <[email protected]> wrote:
>>>>> On 09/15/2011 11:19 AM, Alon Bar-Lev wrote:
>>>>>>> That said, in reviewing your patch, it occurs to me that the code in
>>>>>>> viewvc.load_config() probably shouldn't use os.environ() to check for that
>>>>>>> variable, but (if a 'server' is provided') should use server.getenv()
>>>>>>> instead.  That way, the appropriate environment-checking function for the
>>>>>>> deployment type (mod_python, CGI, IIS, etc.) is used.
>>>>>>>
>>>>>>> Would you be willing to explore this idea a bit to see if it makes sense?
>>>>>>
>>>>>> Well,
>>>>>>
>>>>>> SetEnv does not work in mod_python, at least not in my setup.
>>>>>
>>>>> How do you know that SetEnv doesn't work for mod_python?  How are you
>>>>> testing that?
>>>>
>>>> Apache
>>>> ---
>>>> <Location /viewvc>
>>>>       DirectoryIndex viewvc.py
>>>> #       PythonOption org.viewvc.conf_file "/var/www/localhost/conf/viewvc.conf"
>>>>       SetEnv VIEWVC_CONF_PATHNAME "/var/www/localhost/conf/viewvc.conf"
>>>> </Location>
>>>> ---
>>>>
>>>> Viewvc
>>>> ---
>>>>     pathname = (server.getenv("VIEWVC_CONF_PATHNAME")
>>>>                 or os.environ.get("VIEWVC_CONF_PATHNAME")
>>>>                 or os.environ.get("VIEWCVS_CONF_PATHNAME")
>>>>                 or os.path.join(os.path.dirname(os.path.dirname(__file__)),
>>>>                                 "viewvc.conf"))
>>>> ---
>>>>
>>>> Well, I am more like C guy but it looks right and does not work.
>>>> I may miss something?
>>>> Does it work for you?
>>>>
>>>>>
>>>>>> So we need something like:
>>>>>>
>>>>>>   if pathname is None:
>>>>>>     pathname = (server.get_options()["org.viewvc.conf_file"]              <----
>>>>>>                 or os.environ.get("VIEWVC_CONF_PATHNAME")
>>>>>>                 or os.environ.get("VIEWCVS_CONF_PATHNAME")
>>>>>>                 or os.path.join(os.path.dirname(os.path.dirname(__file__)),
>>>>>>                                 "viewvc.conf"))
>>>>>>
>>>>>> However
>>>>
>>>> Correction, the server is your own viewvc object... so it actually need to be:
>>>>
>>>>  pathname = (server.request.get_options()["org.viewvc.conf_file"]
>>>>                or os.environ.get("VIEWVC_CONF_PATHNAME")
>>>>                or os.environ.get("VIEWCVS_CONF_PATHNAME")
>>>>                or os.path.join(os.path.dirname(os.path.dirname(__file__)),
>>>>                                "viewvc.conf"))
>>>>
>>>>
>>>>>>
>>>>>> 1. The python throws and exception if element within hash is not found
>>>>>> (I expect it to return None...) so I leave it for you...
>>>>>
>>>>> server.get_options().get("org.viewvc.conf_file") returns None of the key
>>>>> doesn't exist in the dictionary/hash.
>>>>
>>>> Strange, I getting an exception.
>>>> ---
>>>>  File "/usr/lib64/python2.7/site-packages/viewvc/viewvc.py", line
>>>> 4411, in load_config
>>>>    pathname = (server.request.get_options()["org.viewvc.conf_file44"]
>>>>
>>>> KeyError: 'org.viewvc.conf_file44'
>>>> ---
>>>>
>>>> Not python developer...
>>>>
>>>> But I can add get_option in the ModPythonServer object that returns
>>>> None if not exists.
>>>>
>>>>>
>>>>>> 2. Correct me if I am wrong but this does not overrides the default
>>>>>> within file, it does set if config is null, and it never is as the
>>>>>> viewvc-install sets CONF_PATHNAME to none null.
>>>>>> I expect environment / option to override the hard coded anyway, so
>>>>>> remove the "if pathname is None:" (and of course un-indent...).
>>>>>
>>>>> You are correct.  I read that wrongly.
>>>>>
>>>>>> 3. Environment(or options) should be documented in INSTALL.... A
>>>>>> complete <Directory sample would be nice! :)
>>>>>
>>>>> Fair enough.  :-)
>>>>>
>>>>> --
>>>>> C. Michael Pilato <[email protected]>
>>>>> CollabNet   <>   www.collab.net   <>   Distributed Development On Demand
>>>>>
>>>>>
>
>
> --
> C. Michael Pilato <[email protected]>
> CollabNet   <>   www.collab.net   <>   Distributed Development On Demand
>
>

------------------------------------------------------
http://viewvc.tigris.org/ds/viewMessage.do?dsForumId=4251&dsMessageId=2844037

To unsubscribe from this discussion, e-mail: [[email protected]].
viewvc-config.patch (text/x-patch, 1.1 KB)
diff --git a/lib/sapi.py b/lib/sapi.py
index 28d0f3b..5df8a26 100644
--- a/lib/sapi.py
+++ b/lib/sapi.py
@@ -368,7 +368,7 @@ class ModPythonServer(ThreadedServer):
 
   def getenv(self, name, value = None):
     try:
-      return self.request.subprocess_env[name]
+      return self.request.get_options()[name];
     except KeyError:
       return value
 
diff --git a/lib/viewvc.py b/lib/viewvc.py
index 4cce07f..30ab9dc 100644
--- a/lib/viewvc.py
+++ b/lib/viewvc.py
@@ -4491,9 +4491,10 @@ def locate_root(cfg, rootname):
 def load_config(pathname=None, server=None):
   debug.t_start('load-config')
 
-  if pathname is None:
-    pathname = (os.environ.get("VIEWVC_CONF_PATHNAME")
-                or os.environ.get("VIEWCVS_CONF_PATHNAME")
+  pathname = (server.getenv("org.viewvc.conf_pathname")
+                or server.getenv("VIEWVC_CONF_PATHNAME")
+                or server.getenv("VIEWCVS_CONF_PATHNAME")
+                or pathname
                 or os.path.join(os.path.dirname(os.path.dirname(__file__)),
                                 "viewvc.conf"))