comparison roundup/scripts/roundup_server.py @ 1871:db97431125a5

Print a nicer error message (without usage)... ...when the address is already in use [SF#798659]. Factor out error() function to enable this.
author Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
date Sat, 25 Oct 2003 12:26:42 +0000
parents 1545a36ae887
children 0b0cd279780e
comparison
equal deleted inserted replaced
1870:ea63531ddeec 1871:db97431125a5
14 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 14 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
16 # 16 #
17 """ HTTP Server that serves roundup. 17 """ HTTP Server that serves roundup.
18 18
19 $Id: roundup_server.py,v 1.31 2003-10-25 11:41:06 jlgijsbers Exp $ 19 $Id: roundup_server.py,v 1.32 2003-10-25 12:26:42 jlgijsbers Exp $
20 """ 20 """
21 21
22 # python version check 22 # python version check
23 from roundup import version_check 23 from roundup import version_check
24 24
25 import sys, os, urllib, StringIO, traceback, cgi, binascii, getopt, imp 25 import sys, os, urllib, StringIO, traceback, cgi, binascii, getopt, imp
26 import BaseHTTPServer, socket 26 import BaseHTTPServer, socket, errno
27 27
28 # Roundup modules of use here 28 # Roundup modules of use here
29 from roundup.cgi import cgitb, client 29 from roundup.cgi import cgitb, client
30 import roundup.instance 30 import roundup.instance
31 from roundup.i18n import _ 31 from roundup.i18n import _
196 return self.client_address[0] 196 return self.client_address[0]
197 else: 197 else:
198 host, port = self.client_address 198 host, port = self.client_address
199 return socket.getfqdn(host) 199 return socket.getfqdn(host)
200 200
201 def error():
202 exc_type, exc_value = sys.exc_info()[:2]
203 return _('Error: %s: %s' % (exc_type, exc_value))
204
201 def usage(message=''): 205 def usage(message=''):
202 if message: 206 print _('''%(message)s
203 message = _('Error: %(error)s\n\n')%{'error': message} 207
204 print _('''%(message)sUsage: 208 Usage:
205 roundup-server [options] [name=tracker home]* 209 roundup-server [options] [name=tracker home]*
206 210
207 options: 211 options:
208 -n: sets the host name 212 -n: sets the host name
209 -p: sets the port to listen on 213 -p: sets the port to listen on
297 raise ValueError, _("logfile *must* be specified if pidfile is") 301 raise ValueError, _("logfile *must* be specified if pidfile is")
298 302
299 # obtain server before changing user id - allows to use port < 303 # obtain server before changing user id - allows to use port <
300 # 1024 if started as root 304 # 1024 if started as root
301 address = (hostname, port) 305 address = (hostname, port)
302 httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler) 306 try:
307 httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler)
308 except socket.error, e:
309 if e[0] == errno.EADDRINUSE:
310 raise socket.error, \
311 _("Unable to bind to port %s, port already in use." % port)
312 raise
303 313
304 if group is not None and hasattr(os, 'getgid'): 314 if group is not None and hasattr(os, 'getgid'):
305 # if root, setgid to the running user 315 # if root, setgid to the running user
306 if not os.getgid() and user is not None: 316 if not os.getgid() and user is not None:
307 try: 317 try:
345 raise ValueError, _("Instances must be name=home") 355 raise ValueError, _("Instances must be name=home")
346 d[name] = home 356 d[name] = home
347 RoundupRequestHandler.TRACKER_HOMES = d 357 RoundupRequestHandler.TRACKER_HOMES = d
348 except SystemExit: 358 except SystemExit:
349 raise 359 raise
360 except ValueError:
361 usage(error())
350 except: 362 except:
351 exc_type, exc_value = sys.exc_info()[:2] 363 print error()
352 usage('%s: %s'%(exc_type, exc_value)) 364 sys.exit(1)
353 365
354 # we don't want the cgi module interpreting the command-line args ;) 366 # we don't want the cgi module interpreting the command-line args ;)
355 sys.argv = sys.argv[:1] 367 sys.argv = sys.argv[:1]
356 368
357 if pidfile: 369 if pidfile:

Roundup Issue Tracker: http://roundup-tracker.org/