From aa6517844c14e26eaf7ef86cee191e4d459f066b Mon Sep 17 00:00:00 2001 From: jlgijsbers Date: Sat, 25 Oct 2003 12:26:42 +0000 Subject: [PATCH] Print a nicer error message (without usage) when the address is already in use (bug #798659). Factor out error() function to enable this. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1940 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/scripts/roundup_server.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/roundup/scripts/roundup_server.py b/roundup/scripts/roundup_server.py index f87ce02..757951a 100644 --- a/roundup/scripts/roundup_server.py +++ b/roundup/scripts/roundup_server.py @@ -16,14 +16,14 @@ # """ HTTP Server that serves roundup. -$Id: roundup_server.py,v 1.31 2003-10-25 11:41:06 jlgijsbers Exp $ +$Id: roundup_server.py,v 1.32 2003-10-25 12:26:42 jlgijsbers Exp $ """ # python version check from roundup import version_check import sys, os, urllib, StringIO, traceback, cgi, binascii, getopt, imp -import BaseHTTPServer, socket +import BaseHTTPServer, socket, errno # Roundup modules of use here from roundup.cgi import cgitb, client @@ -198,10 +198,14 @@ class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): host, port = self.client_address return socket.getfqdn(host) +def error(): + exc_type, exc_value = sys.exc_info()[:2] + return _('Error: %s: %s' % (exc_type, exc_value)) + def usage(message=''): - if message: - message = _('Error: %(error)s\n\n')%{'error': message} - print _('''%(message)sUsage: + print _('''%(message)s + +Usage: roundup-server [options] [name=tracker home]* options: @@ -299,7 +303,13 @@ def run(port=8080, success_message=None): # obtain server before changing user id - allows to use port < # 1024 if started as root address = (hostname, port) - httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler) + try: + httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler) + except socket.error, e: + if e[0] == errno.EADDRINUSE: + raise socket.error, \ + _("Unable to bind to port %s, port already in use." % port) + raise if group is not None and hasattr(os, 'getgid'): # if root, setgid to the running user @@ -347,9 +357,11 @@ def run(port=8080, success_message=None): RoundupRequestHandler.TRACKER_HOMES = d except SystemExit: raise + except ValueError: + usage(error()) except: - exc_type, exc_value = sys.exc_info()[:2] - usage('%s: %s'%(exc_type, exc_value)) + print error() + sys.exit(1) # we don't want the cgi module interpreting the command-line args ;) sys.argv = sys.argv[:1] -- 2.30.2