Mercurial > p > roundup > code
comparison roundup/scripts/roundup_server.py @ 1251:347657425a10
Nicer display of tracker list in roundup-server [SF#619769]
Fixed some missed renaming instance -> tracker [SF#619769]
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 08 Oct 2002 03:31:09 +0000 |
| parents | 6c24a86a12ae |
| children | b2d04ce03802 |
comparison
equal
deleted
inserted
replaced
| 1250:deab62016de7 | 1251:347657425a10 |
|---|---|
| 14 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 14 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 16 # | 16 # |
| 17 """ HTTP Server that serves roundup. | 17 """ HTTP Server that serves roundup. |
| 18 | 18 |
| 19 $Id: roundup_server.py,v 1.13 2002-10-07 00:52:51 richard Exp $ | 19 $Id: roundup_server.py,v 1.14 2002-10-08 03:31:09 richard Exp $ |
| 20 """ | 20 """ |
| 21 | 21 |
| 22 # python version check | 22 # python version check |
| 23 from roundup import version_check | 23 from roundup import version_check |
| 24 | 24 |
| 94 sys.stdin = save_stdin | 94 sys.stdin = save_stdin |
| 95 | 95 |
| 96 do_GET = do_POST = do_HEAD = send_head = run_cgi | 96 do_GET = do_POST = do_HEAD = send_head = run_cgi |
| 97 | 97 |
| 98 def index(self): | 98 def index(self): |
| 99 ''' Print up an index of the available instances | 99 ''' Print up an index of the available trackers |
| 100 ''' | 100 ''' |
| 101 self.send_response(200) | 101 self.send_response(200) |
| 102 self.send_header('Content-Type', 'text/html') | 102 self.send_header('Content-Type', 'text/html') |
| 103 self.end_headers() | 103 self.end_headers() |
| 104 w = self.wfile.write | 104 w = self.wfile.write |
| 105 w(_('<html><head><title>Roundup instances index</title></head>\n')) | 105 w(_('<html><head><title>Roundup trackers index</title></head>\n')) |
| 106 w(_('<body><h1>Roundup instances index</h1><ol>\n')) | 106 w(_('<body><h1>Roundup trackers index</h1><ol>\n')) |
| 107 for instance in self.TRACKER_HOMES.keys(): | 107 keys = self.TRACKER_HOMES.keys() |
| 108 w(_('<li><a href="%(instance_url)s/index">%(instance_name)s</a>\n')%{ | 108 keys.sort() |
| 109 'instance_url': urllib.quote(instance), | 109 for tracker in keys: |
| 110 'instance_name': cgi.escape(instance)}) | 110 w(_('<li><a href="%(tracker_url)s/index">%(tracker_name)s</a>\n')%{ |
| 111 'tracker_url': urllib.quote(tracker), | |
| 112 'tracker_name': cgi.escape(tracker)}) | |
| 111 w(_('</ol></body></html>')) | 113 w(_('</ol></body></html>')) |
| 112 | 114 |
| 113 def inner_run_cgi(self): | 115 def inner_run_cgi(self): |
| 114 ''' This is the inner part of the CGI handling | 116 ''' This is the inner part of the CGI handling |
| 115 ''' | 117 ''' |
| 119 if i >= 0: | 121 if i >= 0: |
| 120 rest, query = rest[:i], rest[i+1:] | 122 rest, query = rest[:i], rest[i+1:] |
| 121 else: | 123 else: |
| 122 query = '' | 124 query = '' |
| 123 | 125 |
| 124 # figure the instance | 126 # figure the tracker |
| 125 if rest == '/': | 127 if rest == '/': |
| 126 return self.index() | 128 return self.index() |
| 127 l_path = rest.split('/') | 129 l_path = rest.split('/') |
| 128 instance_name = urllib.unquote(l_path[1]) | 130 tracker_name = urllib.unquote(l_path[1]) |
| 129 if self.TRACKER_HOMES.has_key(instance_name): | 131 if self.TRACKER_HOMES.has_key(tracker_name): |
| 130 instance_home = self.TRACKER_HOMES[instance_name] | 132 tracker_home = self.TRACKER_HOMES[tracker_name] |
| 131 instance = roundup.instance.open(instance_home) | 133 tracker = roundup.instance.open(tracker_home) |
| 132 else: | 134 else: |
| 133 raise client.NotFound | 135 raise client.NotFound |
| 134 | 136 |
| 135 # figure out what the rest of the path is | 137 # figure out what the rest of the path is |
| 136 if len(l_path) > 2: | 138 if len(l_path) > 2: |
| 138 else: | 140 else: |
| 139 rest = '/' | 141 rest = '/' |
| 140 | 142 |
| 141 # Set up the CGI environment | 143 # Set up the CGI environment |
| 142 env = {} | 144 env = {} |
| 143 env['TRACKER_NAME'] = instance_name | 145 env['TRACKER_NAME'] = tracker_name |
| 144 env['REQUEST_METHOD'] = self.command | 146 env['REQUEST_METHOD'] = self.command |
| 145 env['PATH_INFO'] = urllib.unquote(rest) | 147 env['PATH_INFO'] = urllib.unquote(rest) |
| 146 if query: | 148 if query: |
| 147 env['QUERY_STRING'] = query | 149 env['QUERY_STRING'] = query |
| 148 host = self.address_string() | 150 host = self.address_string() |
| 162 env['HTTP_HOST'] = self.headers['host'] | 164 env['HTTP_HOST'] = self.headers['host'] |
| 163 | 165 |
| 164 decoded_query = query.replace('+', ' ') | 166 decoded_query = query.replace('+', ' ') |
| 165 | 167 |
| 166 # do the roundup thang | 168 # do the roundup thang |
| 167 c = instance.Client(instance, self, env) | 169 c = tracker.Client(tracker, self, env) |
| 168 c.main() | 170 c.main() |
| 169 | 171 |
| 170 def usage(message=''): | 172 def usage(message=''): |
| 171 if message: | 173 if message: |
| 172 message = _('Error: %(error)s\n\n')%{'error': message} | 174 message = _('Error: %(error)s\n\n')%{'error': message} |
| 173 print _('''%(message)sUsage: | 175 print _('''%(message)sUsage: |
| 174 roundup-server [-n hostname] [-p port] [-l file] [-d file] [name=instance home]* | 176 roundup-server [-n hostname] [-p port] [-l file] [-d file] [name=tracker home]* |
| 175 | 177 |
| 176 -n: sets the host name | 178 -n: sets the host name |
| 177 -p: sets the port to listen on | 179 -p: sets the port to listen on |
| 178 -l: sets a filename to log to (instead of stdout) | 180 -l: sets a filename to log to (instead of stdout) |
| 179 -d: daemonize, and write the server's PID to the nominated file | 181 -d: daemonize, and write the server's PID to the nominated file |
| 180 | 182 |
| 181 name=instance home | 183 name=tracker home |
| 182 Sets the instance home(s) to use. The name is how the instance is | 184 Sets the tracker home(s) to use. The name is how the tracker is |
| 183 identified in the URL (it's the first part of the URL path). The | 185 identified in the URL (it's the first part of the URL path). The |
| 184 instance home is the directory that was identified when you did | 186 tracker home is the directory that was identified when you did |
| 185 "roundup-admin init". You may specify any number of these name=home | 187 "roundup-admin init". You may specify any number of these name=home |
| 186 pairs on the command-line. For convenience, you may edit the | 188 pairs on the command-line. For convenience, you may edit the |
| 187 TRACKER_HOMES variable in the roundup-server file instead. | 189 TRACKER_HOMES variable in the roundup-server file instead. |
| 188 Make sure the name part doesn't include any url-unsafe characters like | 190 Make sure the name part doesn't include any url-unsafe characters like |
| 189 spaces, as these confuse the cookie handling in browsers like IE. | 191 spaces, as these confuse the cookie handling in browsers like IE. |
| 274 | 276 |
| 275 # People can remove this check if they're really determined | 277 # People can remove this check if they're really determined |
| 276 if not os.getuid() and user is None: | 278 if not os.getuid() and user is None: |
| 277 raise ValueError, _("Can't run as root!") | 279 raise ValueError, _("Can't run as root!") |
| 278 | 280 |
| 279 # handle instance specs | 281 # handle tracker specs |
| 280 if args: | 282 if args: |
| 281 d = {} | 283 d = {} |
| 282 for arg in args: | 284 for arg in args: |
| 283 try: | 285 try: |
| 284 name, home = arg.split('=') | 286 name, home = arg.split('=') |
