Mercurial > p > roundup > code
comparison roundup/scripts/roundup_server.py @ 3880:2359d6304a4f
Allow template for tracker index page
[SF#058020] requested the ability to have a user-specified template
page for the tracker index that is generated when roundup-server is
handling multiple trackers.
This adds a "-i" option that allows them to specify a template.
| author | Justus Pendleton <jpend@users.sourceforge.net> |
|---|---|
| date | Sun, 02 Sep 2007 16:05:36 +0000 |
| parents | 9d37a6779530 |
| children | 679118b572d5 |
comparison
equal
deleted
inserted
replaced
| 3879:454ee9411e85 | 3880:2359d6304a4f |
|---|---|
| 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 16 # | 16 # |
| 17 | 17 |
| 18 """Command-line script that runs a server over roundup.cgi.client. | 18 """Command-line script that runs a server over roundup.cgi.client. |
| 19 | 19 |
| 20 $Id: roundup_server.py,v 1.88 2007-04-23 19:35:41 forsberg Exp $ | 20 $Id: roundup_server.py,v 1.89 2007-09-02 16:05:36 jpend Exp $ |
| 21 """ | 21 """ |
| 22 __docformat__ = 'restructuredtext' | 22 __docformat__ = 'restructuredtext' |
| 23 | 23 |
| 24 import errno, cgi, getopt, os, socket, sys, traceback, urllib, time | 24 import errno, cgi, getopt, os, socket, sys, traceback, urllib, time |
| 25 import ConfigParser, BaseHTTPServer, SocketServer, StringIO | 25 import ConfigParser, BaseHTTPServer, SocketServer, StringIO |
| 28 from roundup import configuration, version_check | 28 from roundup import configuration, version_check |
| 29 from roundup import __version__ as roundup_version | 29 from roundup import __version__ as roundup_version |
| 30 | 30 |
| 31 # Roundup modules of use here | 31 # Roundup modules of use here |
| 32 from roundup.cgi import cgitb, client | 32 from roundup.cgi import cgitb, client |
| 33 from roundup.cgi.PageTemplates.PageTemplate import PageTemplate | |
| 33 import roundup.instance | 34 import roundup.instance |
| 34 from roundup.i18n import _ | 35 from roundup.i18n import _ |
| 35 | 36 |
| 36 # "default" favicon.ico | 37 # "default" favicon.ico |
| 37 # generate by using "icotool" and tools/base64 | 38 # generate by using "icotool" and tools/base64 |
| 150 self.send_response(302) | 151 self.send_response(302) |
| 151 self.send_header('Location', urllib.quote(keys[0]) + '/index') | 152 self.send_header('Location', urllib.quote(keys[0]) + '/index') |
| 152 self.end_headers() | 153 self.end_headers() |
| 153 else: | 154 else: |
| 154 self.send_response(200) | 155 self.send_response(200) |
| 156 | |
| 155 self.send_header('Content-Type', 'text/html') | 157 self.send_header('Content-Type', 'text/html') |
| 156 self.end_headers() | 158 self.end_headers() |
| 157 w = self.wfile.write | 159 w = self.wfile.write |
| 158 w(_('<html><head><title>Roundup trackers index</title></head>\n' | 160 |
| 159 '<body><h1>Roundup trackers index</h1><ol>\n')) | 161 if self.CONFIG and self.CONFIG['TEMPLATE']: |
| 160 keys.sort() | 162 template = open(self.CONFIG['TEMPLATE']).read() |
| 161 for tracker in keys: | 163 pt = PageTemplate() |
| 162 w('<li><a href="%(tracker_url)s/index">%(tracker_name)s</a>\n'%{ | 164 pt.write(template) |
| 163 'tracker_url': urllib.quote(tracker), | 165 extra = { 'trackers': self.TRACKERS } |
| 164 'tracker_name': cgi.escape(tracker)}) | 166 w(pt.pt_render(extra_context=extra)) |
| 165 w('</ol></body></html>') | 167 else: |
| 168 w(_('<html><head><title>Roundup trackers index</title></head>\n' | |
| 169 '<body><h1>Roundup trackers index</h1><ol>\n')) | |
| 170 keys.sort() | |
| 171 for tracker in keys: | |
| 172 w('<li><a href="%(tracker_url)s/index">%(tracker_name)s</a>\n'%{ | |
| 173 'tracker_url': urllib.quote(tracker), | |
| 174 'tracker_name': cgi.escape(tracker)}) | |
| 175 w('</ol></body></html>') | |
| 166 | 176 |
| 167 def inner_run_cgi(self): | 177 def inner_run_cgi(self): |
| 168 ''' This is the inner part of the CGI handling | 178 ''' This is the inner part of the CGI handling |
| 169 ''' | 179 ''' |
| 170 rest = self.path | 180 rest = self.path |
| 392 (configuration.NullableFilePathOption, "logfile", "", | 402 (configuration.NullableFilePathOption, "logfile", "", |
| 393 "Log file path. If unset, log to stderr."), | 403 "Log file path. If unset, log to stderr."), |
| 394 (configuration.Option, "multiprocess", DEFAULT_MULTIPROCESS, | 404 (configuration.Option, "multiprocess", DEFAULT_MULTIPROCESS, |
| 395 "Set processing of each request in separate subprocess.\n" | 405 "Set processing of each request in separate subprocess.\n" |
| 396 "Allowed values: %s." % ", ".join(MULTIPROCESS_TYPES)), | 406 "Allowed values: %s." % ", ".join(MULTIPROCESS_TYPES)), |
| 407 (configuration.NullableFilePathOption, "template", "", | |
| 408 "Tracker index template. If unset, built-in will be used."), | |
| 397 )), | 409 )), |
| 398 ("trackers", (), "Roundup trackers to serve.\n" | 410 ("trackers", (), "Roundup trackers to serve.\n" |
| 399 "Each option in this section defines single Roundup tracker.\n" | 411 "Each option in this section defines single Roundup tracker.\n" |
| 400 "Option name identifies the tracker and will appear in the URL.\n" | 412 "Option name identifies the tracker and will appear in the URL.\n" |
| 401 "Option value is tracker home directory path.\n" | 413 "Option value is tracker home directory path.\n" |
| 412 "logfile": "l:", | 424 "logfile": "l:", |
| 413 "pidfile": "d:", | 425 "pidfile": "d:", |
| 414 "nodaemon": "D", | 426 "nodaemon": "D", |
| 415 "log_hostnames": "N", | 427 "log_hostnames": "N", |
| 416 "multiprocess": "t:", | 428 "multiprocess": "t:", |
| 429 "template": "i:", | |
| 417 } | 430 } |
| 418 | 431 |
| 419 def __init__(self, config_file=None): | 432 def __init__(self, config_file=None): |
| 420 configuration.Config.__init__(self, config_file, self.SETTINGS) | 433 configuration.Config.__init__(self, config_file, self.SETTINGS) |
| 421 self.sections.append("trackers") | 434 self.sections.append("trackers") |
| 593 -C <fname> use configuration file <fname> | 606 -C <fname> use configuration file <fname> |
| 594 -n <name> set the host name of the Roundup web server instance | 607 -n <name> set the host name of the Roundup web server instance |
| 595 -p <port> set the port to listen on (default: %(port)s) | 608 -p <port> set the port to listen on (default: %(port)s) |
| 596 -l <fname> log to the file indicated by fname instead of stderr/stdout | 609 -l <fname> log to the file indicated by fname instead of stderr/stdout |
| 597 -N log client machine names instead of IP addresses (much slower) | 610 -N log client machine names instead of IP addresses (much slower) |
| 611 -i set tracker index template | |
| 598 -t <mode> multiprocess mode (default: %(mp_def)s). | 612 -t <mode> multiprocess mode (default: %(mp_def)s). |
| 599 Allowed values: %(mp_types)s. | 613 Allowed values: %(mp_types)s. |
| 600 %(os_part)s | 614 %(os_part)s |
| 601 | 615 |
| 602 Long options: | 616 Long options: |
