Tuesday, November 22, 2005

Deploying ViewCVS with WSGI

In my continuing expermentation with Python Paste I came across the cgiapp module. The module provides a class that acts as a proxy to an existing CGI script, which means you can take an existing CGI script and run it using a WSGI enabled server. Rather than testing it's functionality with a simple cgi script, decided to see if I could run ViewCVS with it. To get it to run was very simple.

Create a app factory wrapper script called viewcvs_wsgi.py


from paste import cgiapp

def app_factory(global_config, **local_config):

viewcvs_app = cgiapp.CGIApplication(global_config, script, path=None, include_os_environ=True, query_string=None)
return viewcvs_app


Create a Paste Deploy configuration file called viewcvs.ini


[app:main]
paste.app_factory = viewcvs_wsgi:app_factory
script = "/usr/local/viewcvs-0.9.4/cgi/viewcvs.cgi"

[server:main]
use = egg:PasteScript#wsgiutils
host = 192.168.1.1
port = 8082


Start the WSGIUtils webserver using paster


paster server viewcvs.ini


Point a browser to the URL and browse the CVS repository.

Apart from images not displaying everything else worked as normal. Now why would I want to do this? Well it means I can now run viewcvs under IIS as an ISAPI extension using my isapi_wsgi adaptor. But thats a future blog entry.

1 comment:

Ian Bicking said...

That might not work... at the bottom of cgiapp is some code copied from subprocess and extended some to allow better piping of data. But it's only the posix select-based code, I didn't copy over the Windows version of that code (which uses threads, I think).

Though, if you didn't mind keeping strings of the entire POST body and response in memory, it would be easy enough to fall back on the normal subprocess communicate method. I just checked in an attempted but untested fix that does that.

Anyway, what I wrote cgiapp for was actually to apply middleware in front of a CGI application -- I was using the Lurker archiver for some private lists, and wanted to use the same authentication code as the rest of the application. It's worked well for that.