Skip to content

Commit 4f3fa0f

Browse files
author
Richard Jones
committed
Added command-line arg handling to roundup-server...
...so it's more useful out-of-the-box.
1 parent d897a01 commit 4f3fa0f

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

roundup-server

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
Stolen from CGIHTTPServer
55
6-
$Id: roundup-server,v 1.4 2001-07-23 10:31:45 richard Exp $
6+
$Id: roundup-server,v 1.5 2001-07-24 01:07:59 richard Exp $
77
88
"""
99
import sys
@@ -16,7 +16,7 @@ __version__ = "0.1"
1616

1717
__all__ = ["RoundupRequestHandler"]
1818

19-
import os, urllib, StringIO, traceback, cgi, binascii, string
19+
import os, urllib, StringIO, traceback, cgi, binascii, string, getopt
2020
import BaseHTTPServer
2121
import SimpleHTTPServer
2222

@@ -47,6 +47,7 @@ ROUNDUP_INSTANCE_HOMES = {
4747

4848

4949
class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
50+
ROUNDUP_INSTANCE_HOMES = ROUNDUP_INSTANCE_HOMES
5051
def send_head(self):
5152
"""Version of send_head that support CGI scripts"""
5253
# TODO: actually do the HEAD ...
@@ -95,8 +96,8 @@ class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
9596
raise ValueError, 'No instance specified'
9697
l_path = string.split(rest, '/')
9798
instance = urllib.unquote(l_path[1])
98-
if ROUNDUP_INSTANCE_HOMES.has_key(instance):
99-
instance_home = ROUNDUP_INSTANCE_HOMES[instance]
99+
if self.ROUNDUP_INSTANCE_HOMES.has_key(instance):
100+
instance_home = self.ROUNDUP_INSTANCE_HOMES[instance]
100101
module_path, instance = os.path.split(instance_home)
101102
sys.path.insert(0, module_path)
102103
try:
@@ -208,15 +209,61 @@ def nobody_uid():
208209
nobody = 1 + max(map(lambda x: x[2], pwd.getpwall()))
209210
return nobody
210211

211-
if __name__ == '__main__':
212-
# TODO make this configurable again? command-line seems ok to me...
213-
address = ('', 8080)
212+
def usage(message=''):
213+
if message: message = 'Error: %s\n'%message
214+
print '''%sUsage:
215+
roundup-server [-n hostname] [-p port] [name=instance home]*
216+
217+
-n: sets the host name
218+
-p: sets the port to listen on
219+
220+
name=instance home
221+
Sets the instance home(s) to use. The name is how the instance is
222+
identified in the URL (it's the first part of the URL path). The
223+
instance home is the directory that was identified when you did
224+
"roundup-admin init". You may specify any number of these name=home
225+
pairs on the command-line. For convenience, you may edit the
226+
ROUNDUP_INSTANCE_HOMES variable in the roundup-server file instead.
227+
'''%message
228+
sys.exit(0)
229+
230+
def main():
231+
hostname = ''
232+
port = 8080
233+
try:
234+
# handle the command-line args
235+
optlist, args = getopt.getopt(sys.argv[1:], 'n:p:')
236+
for (opt, arg) in optlist:
237+
if opt == '-n': hostname = arg
238+
elif opt == '-p': port = int(arg)
239+
elif opt == '-h': usage()
240+
241+
# handle instance specs
242+
if args:
243+
d = {}
244+
for arg in args:
245+
name, home = string.split(arg, '=')
246+
d[name] = home
247+
RoundupRequestHandler.ROUNDUP_INSTANCE_HOMES = d
248+
except:
249+
type, value = sys.exc_info()[:2]
250+
usage('%s: %s'%(type, value))
251+
252+
# we don't want the cgi module interpreting the command-line args ;)
253+
sys.argv = sys.argv[:1]
254+
address = (hostname, port)
214255
httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler)
215256
print 'Roundup server started on', address
216257
httpd.serve_forever()
217258

259+
if __name__ == '__main__':
260+
main()
261+
218262
#
219263
# $Log: not supported by cvs2svn $
264+
# Revision 1.4 2001/07/23 10:31:45 richard
265+
# disabled the reloading until it can be done properly
266+
#
220267
# Revision 1.3 2001/07/23 08:53:44 richard
221268
# Fixed the ROUNDUPS decl in roundup-server
222269
# Move the installation notes to INSTALL

0 commit comments

Comments
 (0)