Code

Forgot to add the support call property to the item page.
[roundup.git] / roundup-server
index c67f197ac3645dcf19c523b13197c3529382eacb..9bebf8e5aaa1a62d7ca08f695cf17d9cb2d4d757 100755 (executable)
@@ -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.6 2001-07-29 07:01:39 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,65 @@ 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.5  2001/07/24 01:07:59  richard
+# Added command-line arg handling to roundup-server so it's more useful
+# out-of-the-box.
+#
+# 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
@@ -231,4 +282,4 @@ if __name__ == '__main__':
 # More Grande Splite stuff
 #
 #
-
+# vim: set filetype=python ts=4 sw=4 et si