From: richard Date: Tue, 24 Jul 2001 01:07:59 +0000 (+0000) Subject: Added command-line arg handling to roundup-server so it's more useful X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=61e2df18dab2163399a27ea4d9af807ce8b79c62;p=roundup.git Added command-line arg handling to roundup-server so it's more useful out-of-the-box. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@65 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/roundup-server b/roundup-server index c67f197..d6a03e0 100755 --- a/roundup-server +++ b/roundup-server @@ -3,7 +3,7 @@ Stolen from CGIHTTPServer -$Id: roundup-server,v 1.4 2001-07-23 10:31:45 richard Exp $ +$Id: roundup-server,v 1.5 2001-07-24 01:07:59 richard Exp $ """ import sys @@ -16,7 +16,7 @@ __version__ = "0.1" __all__ = ["RoundupRequestHandler"] -import os, urllib, StringIO, traceback, cgi, binascii, string +import os, urllib, StringIO, traceback, cgi, binascii, string, getopt import BaseHTTPServer import SimpleHTTPServer @@ -47,6 +47,7 @@ ROUNDUP_INSTANCE_HOMES = { class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): + ROUNDUP_INSTANCE_HOMES = ROUNDUP_INSTANCE_HOMES def send_head(self): """Version of send_head that support CGI scripts""" # TODO: actually do the HEAD ... @@ -95,8 +96,8 @@ class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): raise ValueError, 'No instance specified' l_path = string.split(rest, '/') instance = urllib.unquote(l_path[1]) - if ROUNDUP_INSTANCE_HOMES.has_key(instance): - instance_home = ROUNDUP_INSTANCE_HOMES[instance] + if self.ROUNDUP_INSTANCE_HOMES.has_key(instance): + instance_home = self.ROUNDUP_INSTANCE_HOMES[instance] module_path, instance = os.path.split(instance_home) sys.path.insert(0, module_path) try: @@ -208,15 +209,61 @@ def nobody_uid(): nobody = 1 + max(map(lambda x: x[2], pwd.getpwall())) return nobody -if __name__ == '__main__': - # TODO make this configurable again? command-line seems ok to me... - address = ('', 8080) +def usage(message=''): + if message: message = 'Error: %s\n'%message + print '''%sUsage: +roundup-server [-n hostname] [-p port] [name=instance home]* + + -n: sets the host name + -p: sets the port to listen on + + name=instance home + Sets the instance home(s) to use. The name is how the instance is + identified in the URL (it's the first part of the URL path). The + instance home is the directory that was identified when you did + "roundup-admin init". You may specify any number of these name=home + pairs on the command-line. For convenience, you may edit the + ROUNDUP_INSTANCE_HOMES variable in the roundup-server file instead. +'''%message + sys.exit(0) + +def main(): + hostname = '' + port = 8080 + try: + # handle the command-line args + optlist, args = getopt.getopt(sys.argv[1:], 'n:p:') + for (opt, arg) in optlist: + if opt == '-n': hostname = arg + elif opt == '-p': port = int(arg) + elif opt == '-h': usage() + + # handle instance specs + if args: + d = {} + for arg in args: + name, home = string.split(arg, '=') + d[name] = home + RoundupRequestHandler.ROUNDUP_INSTANCE_HOMES = d + except: + type, value = sys.exc_info()[:2] + usage('%s: %s'%(type, value)) + + # we don't want the cgi module interpreting the command-line args ;) + sys.argv = sys.argv[:1] + address = (hostname, port) httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler) print 'Roundup server started on', address httpd.serve_forever() +if __name__ == '__main__': + main() + # # $Log: not supported by cvs2svn $ +# Revision 1.4 2001/07/23 10:31:45 richard +# disabled the reloading until it can be done properly +# # Revision 1.3 2001/07/23 08:53:44 richard # Fixed the ROUNDUPS decl in roundup-server # Move the installation notes to INSTALL