1717
1818"""Command-line script that runs a server over roundup.cgi.client.
1919
20- $Id: roundup_server.py,v 1.67 2004-10-29 13:41:25 a1s Exp $
20+ $Id: roundup_server.py,v 1.68 2004-10-29 17:57:17 a1s Exp $
2121"""
2222__docformat__ = 'restructuredtext'
2323
24- import socket
25- import sys , os , urllib , StringIO , traceback , cgi , binascii , getopt , imp
26- import SocketServer , BaseHTTPServer , socket , errno , ConfigParser
24+ import errno , cgi , getopt , os , socket , sys , traceback , urllib
25+ import ConfigParser , BaseHTTPServer , SocketServer , StringIO
2726
2827# python version check
2928from roundup import configuration , version_check
3433import roundup .instance
3534from roundup .i18n import _
3635
37- try :
38- import signal
39- except :
40- signal = None
41-
4236# "default" favicon.ico
4337# generate by using "icotool" and tools/base64
4438import zlib , base64
@@ -146,7 +140,8 @@ def inner_run_cgi(self):
146140
147141 # no tracker - spit out the index
148142 if rest == '/' :
149- return self .index ()
143+ self .index ()
144+ return
150145
151146 # figure the tracker
152147 l_path = rest .split ('/' )
@@ -182,7 +177,6 @@ def inner_run_cgi(self):
182177 env ['PATH_INFO' ] = urllib .unquote (rest )
183178 if query :
184179 env ['QUERY_STRING' ] = query
185- host = self .address_string ()
186180 if self .headers .typeheader is None :
187181 env ['CONTENT_TYPE' ] = self .headers .type
188182 else :
@@ -199,14 +193,8 @@ def inner_run_cgi(self):
199193 env ['SERVER_PORT' ] = str (self .server .server_port )
200194 env ['HTTP_HOST' ] = self .headers ['host' ]
201195
202- decoded_query = query .replace ('+' , ' ' )
203-
204196 # do the roundup thang
205- if hasattr (tracker , 'Client' ):
206- c = tracker .Client (tracker , self , env )
207- else :
208- c = client .Client (tracker , self , env )
209- c .main ()
197+ tracker .Client (tracker , self , env ).main ()
210198
211199 def address_string (self ):
212200 if self .LOG_IPADDRESS :
@@ -366,7 +354,7 @@ def getopt(self, args, short_options="", long_options=(),
366354 ):
367355 options .update (self .OPTIONS )
368356 return configuration .Config .getopt (self , args ,
369- short_options , long_options , ** options )
357+ short_options , long_options , config_load_options , ** options )
370358
371359 def _get_name (self ):
372360 return "Roundup server"
@@ -383,44 +371,46 @@ def get_server(self):
383371 """Return HTTP server object to run"""
384372 # redirect stdout/stderr to our logfile
385373 # this is done early to have following messages go to this logfile
386- if self . LOGFILE :
374+ if self [ " LOGFILE" ] :
387375 # appending, unbuffered
388376 sys .stdout = sys .stderr = open (self ["LOGFILE" ], 'a' , 0 )
389377 # we don't want the cgi module interpreting the command-line args ;)
390378 sys .argv = sys .argv [:1 ]
391379 # build customized request handler class
392380 class RequestHandler (RoundupRequestHandler ):
393- LOG_IPADDRESS = not self . LOG_HOSTNAMES
381+ LOG_IPADDRESS = not self [ " LOG_HOSTNAMES" ]
394382 TRACKER_HOMES = dict (self .trackers ())
395383 # obtain request server class
396- if self . MULTIPROCESS not in MULTIPROCESS_TYPES :
384+ if self [ " MULTIPROCESS" ] not in MULTIPROCESS_TYPES :
397385 print _ ("Multiprocess mode \" %s\" is not available, "
398- "switching to single-process" ) % self . MULTIPROCESS
399- self . MULTIPROCESS = "none"
386+ "switching to single-process" ) % self [ " MULTIPROCESS" ]
387+ self [ " MULTIPROCESS" ] = "none"
400388 server_class = BaseHTTPServer .HTTPServer
401- elif self . MULTIPROCESS == "fork" :
402- class server_class (SocketServer .ForkingMixIn ,
389+ elif self [ " MULTIPROCESS" ] == "fork" :
390+ class ForkingServer (SocketServer .ForkingMixIn ,
403391 BaseHTTPServer .HTTPServer ):
404392 pass
405- elif self .MULTIPROCESS == "thread" :
406- class server_class (SocketServer .ThreadingMixIn ,
393+ server_class = ForkingServer
394+ elif self ["MULTIPROCESS" ] == "thread" :
395+ class ThreadingServer (SocketServer .ThreadingMixIn ,
407396 BaseHTTPServer .HTTPServer ):
408397 pass
398+ server_class = ThreadingServer
409399 else :
410400 server_class = BaseHTTPServer .HTTPServer
411401 # obtain server before changing user id - allows to
412402 # use port < 1024 if started as root
413403 try :
414- httpd = server_class ((self . HOST , self . PORT ), RequestHandler )
404+ httpd = server_class ((self [ " HOST" ] , self [ " PORT" ] ), RequestHandler )
415405 except socket .error , e :
416406 if e [0 ] == errno .EADDRINUSE :
417407 raise socket .error , \
418408 _ ("Unable to bind to port %s, port already in use." ) \
419- % self . PORT
409+ % self [ " PORT" ]
420410 raise
421411 # change user and/or group
422- setgid (self . GROUP )
423- setuid (self . USER )
412+ setgid (self [ " GROUP" ] )
413+ setuid (self [ " USER" ] )
424414 # return the server
425415 return httpd
426416
@@ -435,7 +425,8 @@ class server_class(SocketServer.ThreadingMixIn,
435425 import win32event
436426 import win32file
437427
438- SvcShutdown = "ServiceShutdown"
428+ class SvcShutdown (Exception ):
429+ pass
439430
440431 class RoundupService (win32serviceutil .ServiceFramework ,
441432 BaseHTTPServer .HTTPServer ):
@@ -630,8 +621,9 @@ def run(port=undefined, success_message=None):
630621
631622 # if running in windows service mode, don't do any other stuff
632623 if ("-c" , "" ) in optlist :
633- return win32serviceutil .HandleCommandLine (RoundupService ,
624+ win32serviceutil .HandleCommandLine (RoundupService ,
634625 argv = sys .argv [:1 ] + args )
626+ return
635627
636628 # add tracker names from command line.
637629 # this is done early to let '--save-config' handle the trackers.
@@ -663,13 +655,13 @@ def run(port=undefined, success_message=None):
663655 config .PORT = port
664656
665657 # fork the server from our parent if a pidfile is specified
666- if config . PIDFILE :
658+ if config [ " PIDFILE" ] :
667659 if not hasattr (os , 'fork' ):
668660 print _ ("Sorry, you can't run the server as a daemon"
669661 " on this Operating System" )
670662 sys .exit (0 )
671663 else :
672- daemonize (config . PIDFILE )
664+ daemonize (config [ " PIDFILE" ] )
673665
674666 # create the server
675667 httpd = config .get_server ()
0 commit comments