1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
4 # This module is free software, and you may redistribute it and/or modify
5 # under the same terms as Python, so long as this copyright message and
6 # disclaimer are retained in their original form.
7 #
8 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
9 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
10 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
11 # POSSIBILITY OF SUCH DAMAGE.
12 #
13 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
18 #
19 # $Id: roundup.cgi,v 1.13 2001-10-05 02:23:24 richard Exp $
21 # python version check
22 import sys
23 if int(sys.version[0]) < 2:
24 print "Content-Type: text/plain\n"
25 print "Roundup requires Python 2.0 or newer."
26 sys.exit(0)
28 #
29 ## Configuration
30 #
32 # This indicates where the Roundup instance lives
33 ROUNDUP_INSTANCE_HOMES = {
34 'demo': '/var/roundup/instances/demo',
35 }
37 # Where to log debugging information to. Use an instance of DevNull if you
38 # don't want to log anywhere.
39 class DevNull:
40 def write(self, info):
41 pass
42 #LOG = open('/var/log/roundup.cgi.log', 'a')
43 LOG = DevNull()
45 #
46 ## end configuration
47 #
49 #
50 # Set up the error handler
51 #
52 try:
53 import traceback, StringIO, cgi
54 from roundup import cgitb
55 except:
56 print "Content-Type: text/html\n"
57 print "Failed to import cgitb.<pre>"
58 s = StringIO.StringIO()
59 traceback.print_exc(None, s)
60 print cgi.escape(s.getvalue()), "</pre>"
62 def main(out, err):
63 import os, string
64 import roundup.instance
65 path = string.split(os.environ['PATH_INFO'], '/')
66 instance = path[1]
67 os.environ['INSTANCE_NAME'] = instance
68 os.environ['PATH_INFO'] = string.join(path[2:], '/')
69 if ROUNDUP_INSTANCE_HOMES.has_key(instance):
70 instance_home = ROUNDUP_INSTANCE_HOMES[instance]
71 instance = roundup.instance.open(instance_home)
72 from roundup import cgi_client
73 client = instance.Client(instance, out, os.environ)
74 try:
75 client.main()
76 except cgi_client.Unauthorised:
77 out.write('Content-Type: text/html\n')
78 out.write('Status: 403\n\n')
79 out.write('Unauthorised')
80 except cgi_client.NotFound:
81 out.write('Content-Type: text/html\n')
82 out.write('Status: 404\n\n')
83 out.write('Not found: %s'%client.path)
84 else:
85 import urllib
86 w = out.write
87 w("Content-Type: text/html\n\n")
88 w('<html><head><title>Roundup instances index</title><head>\n')
89 w('<body><h1>Roundup instances index</h1><ol>\n')
90 for instance in ROUNDUP_INSTANCE_HOMES.keys():
91 w('<li><a href="%s/index">%s</a>\n'%(urllib.quote(instance),
92 instance))
93 w('</ol></body></html>')
95 #
96 # Now do the actual CGI handling
97 #
98 out, err = sys.stdout, sys.stderr
99 try:
100 sys.stdout = sys.stderr = LOG
101 main(out, err)
102 except:
103 sys.stdout, sys.stderr = out, err
104 out.write('Content-Type: text/html\n\n')
105 cgitb.handler()
106 sys.stdout.flush()
107 sys.stdout, sys.stderr = out, err
109 #
110 # $Log: not supported by cvs2svn $
111 # Revision 1.12 2001/10/01 05:55:41 richard
112 # Fixes to the top-level index
113 #
114 # Revision 1.11 2001/09/29 13:27:00 richard
115 # CGI interfaces now spit up a top-level index of all the instances they can
116 # serve.
117 #
118 # Revision 1.10 2001/08/07 00:24:42 richard
119 # stupid typo
120 #
121 # Revision 1.9 2001/08/07 00:15:51 richard
122 # Added the copyright/license notice to (nearly) all files at request of
123 # Bizar Software.
124 #
125 # Revision 1.8 2001/08/05 07:43:52 richard
126 # Instances are now opened by a special function that generates a unique
127 # module name for the instances on import time.
128 #
129 # Revision 1.7 2001/08/03 01:28:33 richard
130 # Used the much nicer load_package, pointed out by Steve Majewski.
131 #
132 # Revision 1.6 2001/08/03 00:59:34 richard
133 # Instance import now imports the instance using imp.load_module so that
134 # we can have instance homes of "roundup" or other existing python package
135 # names.
136 #
137 # Revision 1.5 2001/07/29 07:01:39 richard
138 # Added vim command to all source so that we don't get no steenkin' tabs :)
139 #
140 # Revision 1.4 2001/07/23 04:47:27 anthonybaxter
141 # renamed ROUNDUPS to ROUNDUP_INSTANCE_HOMES
142 # sys.exit(0) if python version wrong.
143 #
144 # Revision 1.3 2001/07/23 04:33:30 richard
145 # brought the CGI instance config dict in line with roundup-server
146 #
147 # Revision 1.2 2001/07/23 04:31:40 richard
148 # Fixed the roundup CGI script for updates to cgi_client.py
149 #
150 # Revision 1.1 2001/07/22 11:47:07 richard
151 # More Grande Splite
152 #
153 #
154 # vim: set filetype=python ts=4 sw=4 et si