|
16 | 16 | # |
17 | 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 | 22 | # python version check |
23 | 23 | from roundup import version_check |
24 | 24 |
|
25 | 25 | import sys, os, urllib, StringIO, traceback, cgi, binascii, getopt, imp |
26 | | -import BaseHTTPServer, socket |
| 26 | +import BaseHTTPServer, socket, errno |
27 | 27 |
|
28 | 28 | # Roundup modules of use here |
29 | 29 | from roundup.cgi import cgitb, client |
@@ -198,10 +198,14 @@ def address_string(self): |
198 | 198 | host, port = self.client_address |
199 | 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 | 205 | def usage(message=''): |
202 | | - if message: |
203 | | - message = _('Error: %(error)s\n\n')%{'error': message} |
204 | | - print _('''%(message)sUsage: |
| 206 | + print _('''%(message)s |
| 207 | +
|
| 208 | +Usage: |
205 | 209 | roundup-server [options] [name=tracker home]* |
206 | 210 |
|
207 | 211 | options: |
@@ -299,7 +303,13 @@ def run(port=8080, success_message=None): |
299 | 303 | # obtain server before changing user id - allows to use port < |
300 | 304 | # 1024 if started as root |
301 | 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 | 314 | if group is not None and hasattr(os, 'getgid'): |
305 | 315 | # if root, setgid to the running user |
@@ -347,9 +357,11 @@ def run(port=8080, success_message=None): |
347 | 357 | RoundupRequestHandler.TRACKER_HOMES = d |
348 | 358 | except SystemExit: |
349 | 359 | raise |
| 360 | + except ValueError: |
| 361 | + usage(error()) |
350 | 362 | except: |
351 | | - exc_type, exc_value = sys.exc_info()[:2] |
352 | | - usage('%s: %s'%(exc_type, exc_value)) |
| 363 | + print error() |
| 364 | + sys.exit(1) |
353 | 365 |
|
354 | 366 | # we don't want the cgi module interpreting the command-line args ;) |
355 | 367 | sys.argv = sys.argv[:1] |
|
0 commit comments