Mercurial > p > roundup > code
comparison cgi-bin/roundup.cgi @ 1096:fa7df238e2d4
More cleaning up of configuration, and the "instance" -> "tracker" renaming.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 10 Sep 2002 03:01:20 +0000 |
| parents | e5826025eeb7 |
| children | 26c8cb2162d7 |
comparison
equal
deleted
inserted
replaced
| 1095:711f2ecee20f | 1096:fa7df238e2d4 |
|---|---|
| 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 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" | 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, | 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 18 # | 18 # |
| 19 # $Id: roundup.cgi,v 1.30 2002-09-10 01:07:05 richard Exp $ | 19 # $Id: roundup.cgi,v 1.31 2002-09-10 03:01:17 richard Exp $ |
| 20 | 20 |
| 21 # python version check | 21 # python version check |
| 22 from roundup import version_check | 22 from roundup import version_check |
| 23 from roundup.i18n import _ | 23 from roundup.i18n import _ |
| 24 import sys | 24 import sys |
| 30 # Configuration can also be provided through the OS environment (or via | 30 # Configuration can also be provided through the OS environment (or via |
| 31 # the Apache "SetEnv" configuration directive). If the variables | 31 # the Apache "SetEnv" configuration directive). If the variables |
| 32 # documented below are set, they _override_ any configuation defaults | 32 # documented below are set, they _override_ any configuation defaults |
| 33 # given in this file. | 33 # given in this file. |
| 34 | 34 |
| 35 # ROUNDUP_INSTANCE_HOMES is a list of instances, in the form | 35 # TRACKER_HOMES is a list of instances, in the form |
| 36 # "NAME=DIR<sep>NAME2=DIR2<sep>...", where <sep> is the directory path | 36 # "NAME=DIR<sep>NAME2=DIR2<sep>...", where <sep> is the directory path |
| 37 # separator (";" on Windows, ":" on Unix). | 37 # separator (";" on Windows, ":" on Unix). |
| 38 | 38 |
| 39 # ROUNDUP_LOG is the name of the logfile; if it's empty or does not exist, | 39 # ROUNDUP_LOG is the name of the logfile; if it's empty or does not exist, |
| 40 # logging is turned off (unless you changed the default below). | 40 # logging is turned off (unless you changed the default below). |
| 41 | 41 |
| 42 # ROUNDUP_DEBUG is a debug level, currently only 0 (OFF) and 1 (ON) are | 42 # ROUNDUP_DEBUG is a debug level, currently only 0 (OFF) and 1 (ON) are |
| 43 # used in the code. Higher numbers means more debugging output. | 43 # used in the code. Higher numbers means more debugging output. |
| 44 | 44 |
| 45 # This indicates where the Roundup instance lives | 45 # This indicates where the Roundup instance lives |
| 46 ROUNDUP_INSTANCE_HOMES = { | 46 TRACKER_HOMES = { |
| 47 'demo': '/var/roundup/instances/demo', | 47 'demo': '/var/roundup/instances/demo', |
| 48 } | 48 } |
| 49 | 49 |
| 50 # Where to log debugging information to. Use an instance of DevNull if you | 50 # Where to log debugging information to. Use an instance of DevNull if you |
| 51 # don't want to log anywhere. | 51 # don't want to log anywhere. |
| 79 # | 79 # |
| 80 # Check environment for config items | 80 # Check environment for config items |
| 81 # | 81 # |
| 82 def checkconfig(): | 82 def checkconfig(): |
| 83 import os, string | 83 import os, string |
| 84 global ROUNDUP_INSTANCE_HOMES, LOG | 84 global TRACKER_HOMES, LOG |
| 85 | 85 |
| 86 homes = os.environ.get('ROUNDUP_INSTANCE_HOMES', '') | 86 # see if there's an environment var. ROUNDUP_INSTANCE_HOMES is the |
| 87 # old name for it. | |
| 88 if os.environ.has_key('ROUNDUP_INSTANCE_HOMES'): | |
| 89 homes = os.environ.get('ROUNDUP_INSTANCE_HOMES') | |
| 90 else: | |
| 91 homes = os.environ.get('TRACKER_HOMES', '') | |
| 87 if homes: | 92 if homes: |
| 88 ROUNDUP_INSTANCE_HOMES = {} | 93 TRACKER_HOMES = {} |
| 89 for home in string.split(homes, os.pathsep): | 94 for home in string.split(homes, os.pathsep): |
| 90 try: | 95 try: |
| 91 name, dir = string.split(home, '=', 1) | 96 name, dir = string.split(home, '=', 1) |
| 92 except ValueError: | 97 except ValueError: |
| 93 # ignore invalid definitions | 98 # ignore invalid definitions |
| 94 continue | 99 continue |
| 95 if name and dir: | 100 if name and dir: |
| 96 ROUNDUP_INSTANCE_HOMES[name] = dir | 101 TRACKER_HOMES[name] = dir |
| 97 | 102 |
| 98 logname = os.environ.get('ROUNDUP_LOG', '') | 103 logname = os.environ.get('ROUNDUP_LOG', '') |
| 99 if logname: | 104 if logname: |
| 100 LOG = open(logname, 'a') | 105 LOG = open(logname, 'a') |
| 101 | 106 |
| 127 import roundup.instance | 132 import roundup.instance |
| 128 path = string.split(os.environ.get('PATH_INFO', '/'), '/') | 133 path = string.split(os.environ.get('PATH_INFO', '/'), '/') |
| 129 request = RequestWrapper(out) | 134 request = RequestWrapper(out) |
| 130 request.path = os.environ.get('PATH_INFO', '/') | 135 request.path = os.environ.get('PATH_INFO', '/') |
| 131 instance = path[1] | 136 instance = path[1] |
| 132 os.environ['INSTANCE_NAME'] = instance | 137 os.environ['TRACKER_NAME'] = instance |
| 133 os.environ['PATH_INFO'] = string.join(path[2:], '/') | 138 os.environ['PATH_INFO'] = string.join(path[2:], '/') |
| 134 if ROUNDUP_INSTANCE_HOMES.has_key(instance): | 139 if TRACKER_HOMES.has_key(instance): |
| 135 # redirect if we need a trailing '/' | 140 # redirect if we need a trailing '/' |
| 136 if len(path) == 2: | 141 if len(path) == 2: |
| 137 request.send_response(301) | 142 request.send_response(301) |
| 138 absolute_url = 'http://%s%s/'%(os.environ['HTTP_HOST'], | 143 absolute_url = 'http://%s%s/'%(os.environ['HTTP_HOST'], |
| 139 os.environ['REQUEST_URI']) | 144 os.environ['REQUEST_URI']) |
| 140 request.send_header('Location', absolute_url) | 145 request.send_header('Location', absolute_url) |
| 141 request.end_headers() | 146 request.end_headers() |
| 142 out.write('Moved Permanently') | 147 out.write('Moved Permanently') |
| 143 else: | 148 else: |
| 144 instance_home = ROUNDUP_INSTANCE_HOMES[instance] | 149 instance_home = TRACKER_HOMES[instance] |
| 145 instance = roundup.instance.open(instance_home) | 150 instance = roundup.instance.open(instance_home) |
| 146 from roundup.cgi.client import Unauthorised, NotFound | 151 from roundup.cgi.client import Unauthorised, NotFound |
| 147 client = instance.Client(instance, request, os.environ) | 152 client = instance.Client(instance, request, os.environ) |
| 148 try: | 153 try: |
| 149 client.main() | 154 client.main() |
| 164 request.send_header('Content-Type', 'text/html') | 169 request.send_header('Content-Type', 'text/html') |
| 165 request.end_headers() | 170 request.end_headers() |
| 166 w = request.write | 171 w = request.write |
| 167 w(_('<html><head><title>Roundup instances index</title></head>\n')) | 172 w(_('<html><head><title>Roundup instances index</title></head>\n')) |
| 168 w(_('<body><h1>Roundup instances index</h1><ol>\n')) | 173 w(_('<body><h1>Roundup instances index</h1><ol>\n')) |
| 169 homes = ROUNDUP_INSTANCE_HOMES.keys() | 174 homes = TRACKER_HOMES.keys() |
| 170 homes.sort() | 175 homes.sort() |
| 171 for instance in homes: | 176 for instance in homes: |
| 172 w(_('<li><a href="%(instance_url)s/index">%(instance_name)s</a>\n')%{ | 177 w(_('<li><a href="%(instance_url)s/index">%(instance_name)s</a>\n')%{ |
| 173 'instance_url': os.environ['SCRIPT_NAME']+'/'+urllib.quote(instance), | 178 'instance_url': os.environ['SCRIPT_NAME']+'/'+urllib.quote(instance), |
| 174 'instance_name': cgi.escape(instance)}) | 179 'instance_name': cgi.escape(instance)}) |
