Code

Fixed some problems with installation.
[roundup.git] / roundup-server
index 3c30c63008d63bc691cea25e6936f98d61ef6ebe..d6a03e0eb0eeeb9807cf4a5ad4b9fa3a3f12d98b 100755 (executable)
@@ -3,7 +3,7 @@
 
 Stolen from CGIHTTPServer
 
-$Id: roundup-server,v 1.3 2001-07-23 08:53:44 richard Exp $
+$Id: roundup-server,v 1.5 2001-07-24 01:07:59 richard Exp $
 
 """
 import sys
@@ -16,23 +16,20 @@ __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
 
 # Roundup modules of use here
 from roundup import cgitb, cgi_client
 
-# These are here temporarily until I get a real reload system in place
-from roundup import date, hyperdb, hyper_bsddb, roundupdb, htmltemplate
-
 #
 ##  Configuration
 #
 
 # This indicates where the Roundup instance lives
 ROUNDUP_INSTANCE_HOMES = {
-    'test': '/tmp/roundup_test',
+    'bar': '/tmp/bar',
 }
 
 # Where to log debugging information to. Use an instance of DevNull if you
@@ -50,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 ...
@@ -98,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:
@@ -146,16 +144,16 @@ class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
 
         # reload all modules
         # TODO check for file timestamp changes and dependencies
-        reload(date)
-        reload(hyperdb)
-        reload(roundupdb)
-        reload(htmltemplate)
-        reload(cgi_client)
-        sys.path.insert(0, module_path)
-        try:
-            reload(instance)
-        finally:
-            del sys.path[0]
+        #reload(date)
+        #reload(hyperdb)
+        #reload(roundupdb)
+        #reload(htmltemplate)
+        #reload(cgi_client)
+        #sys.path.insert(0, module_path)
+        #try:
+        #    reload(instance)
+        #finally:
+        #    del sys.path[0]
 
         # initialise the roundupdb, check for auth
         db = instance.open('admin')
@@ -211,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.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
+#
 # Revision 1.2  2001/07/23 04:05:05  anthonybaxter
 # actually quit if python version wrong
 #