Mercurial > p > roundup > code
comparison roundup/scripts/roundup_server.py @ 2021:f4a16b186efc
proper fix this time
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sun, 15 Feb 2004 21:55:10 +0000 |
| parents | 027b297ce23c |
| children | adaf2a92153c |
comparison
equal
deleted
inserted
replaced
| 2020:027b297ce23c | 2021:f4a16b186efc |
|---|---|
| 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 16 # | 16 # |
| 17 | 17 |
| 18 """Command-line script that runs a server over roundup.cgi.client. | 18 """Command-line script that runs a server over roundup.cgi.client. |
| 19 | 19 |
| 20 $Id: roundup_server.py,v 1.38 2004-02-15 21:44:02 richard Exp $ | 20 $Id: roundup_server.py,v 1.39 2004-02-15 21:55:10 richard Exp $ |
| 21 """ | 21 """ |
| 22 __docformat__ = 'restructuredtext' | 22 __docformat__ = 'restructuredtext' |
| 23 | 23 |
| 24 # python version check | 24 # python version check |
| 25 from roundup import version_check | 25 from roundup import version_check |
| 67 NpvNarUmk0mWZS/yr9frcrmc+iMOh+NWydPp1Ov1SiSSc344HL7fKKfTiSN2u12tVqOcxWJxn6/V | 67 NpvNarUmk0mWZS/yr9frcrmc+iMOh+NWydPp1Ov1SiSSc344HL7fKKfTiSN2u12tVqOcxWJxn6/V |
| 68 ag0GAwxkrlKp5vP5fT7ulMlk6XRar9dLpVIUXi6Xb5Hxa1wul0ajKZVKsVjM7XYXCoVOp3OVPJvN | 68 ag0GAwxkrlKp5vP5fT7ulMlk6XRar9dLpVIUXi6Xb5Hxa1wul0ajKZVKsVjM7XYXCoVOp3OVPJvN |
| 69 AoFAtVo1m825XO7hSODOYrH4kHbxxGAwwODBGI/H6DBs5LNara7yl8slGjIcDsHpdrunU6PRCAP2 | 69 AoFAtVo1m825XO7hSODOYrH4kHbxxGAwwODBGI/H6DBs5LNara7yl8slGjIcDsHpdrunU6PRCAP2 |
| 70 r3fPdUcIYeyEfLSAJ0LeAUZHCAt8Al/8/kLIEWDB5YDj0wm8fAP6fVfo | 70 r3fPdUcIYeyEfLSAJ0LeAUZHCAt8Al/8/kLIEWDB5YDj0wm8fAP6fVfo |
| 71 '''.strip())) | 71 '''.strip())) |
| 72 | |
| 73 class RoundupHTTPServer(SafeLogging, BaseHTTPServer.HTTPServer): | |
| 74 def log_message(self, format, *args): | |
| 75 ''' Try to use the logging package, otherwise *safely* log to | |
| 76 stderr. | |
| 77 ''' | |
| 78 try: | |
| 79 BaseHTTPServer.HTTPServer.log_message(self, format, *args) | |
| 80 except IOError: | |
| 81 # stderr is no longer viable, we can't log | |
| 82 pass | |
| 83 | 72 |
| 84 class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): | 73 class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
| 85 TRACKER_HOMES = TRACKER_HOMES | 74 TRACKER_HOMES = TRACKER_HOMES |
| 86 ROUNDUP_USER = ROUNDUP_USER | 75 ROUNDUP_USER = ROUNDUP_USER |
| 87 | 76 |
| 221 return self.client_address[0] | 210 return self.client_address[0] |
| 222 else: | 211 else: |
| 223 host, port = self.client_address | 212 host, port = self.client_address |
| 224 return socket.getfqdn(host) | 213 return socket.getfqdn(host) |
| 225 | 214 |
| 215 def log_message(self, format, *args): | |
| 216 ''' Try to *safely* log to stderr. | |
| 217 ''' | |
| 218 try: | |
| 219 BaseHTTPServer.BaseHTTPRequestHandler.log_message(self, | |
| 220 format, *args) | |
| 221 except IOError: | |
| 222 # stderr is no longer viable | |
| 223 pass | |
| 224 | |
| 226 def error(): | 225 def error(): |
| 227 exc_type, exc_value = sys.exc_info()[:2] | 226 exc_type, exc_value = sys.exc_info()[:2] |
| 228 return _('Error: %s: %s' % (exc_type, exc_value)) | 227 return _('Error: %s: %s' % (exc_type, exc_value)) |
| 229 | 228 |
| 230 try: | 229 try: |
| 238 from win32event import * | 237 from win32event import * |
| 239 from win32file import * | 238 from win32file import * |
| 240 | 239 |
| 241 SvcShutdown = "ServiceShutdown" | 240 SvcShutdown = "ServiceShutdown" |
| 242 | 241 |
| 243 class RoundupService(win32serviceutil.ServiceFramework, RoundupHTTPServer): | 242 class RoundupService(win32serviceutil.ServiceFramework, |
| 243 BaseHTTPServer.HTTPServer): | |
| 244 ''' A Roundup standalone server for Win32 by Ewout Prangsma | 244 ''' A Roundup standalone server for Win32 by Ewout Prangsma |
| 245 ''' | 245 ''' |
| 246 _svc_name_ = "Roundup Bug Tracker" | 246 _svc_name_ = "Roundup Bug Tracker" |
| 247 _svc_display_name_ = "Roundup Bug Tracker" | 247 _svc_display_name_ = "Roundup Bug Tracker" |
| 248 address = (HOSTNAME, PORT) | 248 address = (HOSTNAME, PORT) |
| 250 # redirect stdout/stderr to our logfile | 250 # redirect stdout/stderr to our logfile |
| 251 if LOGFILE: | 251 if LOGFILE: |
| 252 # appending, unbuffered | 252 # appending, unbuffered |
| 253 sys.stdout = sys.stderr = open(LOGFILE, 'a', 0) | 253 sys.stdout = sys.stderr = open(LOGFILE, 'a', 0) |
| 254 win32serviceutil.ServiceFramework.__init__(self, args) | 254 win32serviceutil.ServiceFramework.__init__(self, args) |
| 255 RoundupHTTPServer.__init__(self, self.address, | 255 BaseHTTPServer.HTTPServer.__init__(self, self.address, |
| 256 RoundupRequestHandler) | 256 RoundupRequestHandler) |
| 257 | 257 |
| 258 # Create the necessary NT Event synchronization objects... | 258 # Create the necessary NT Event synchronization objects... |
| 259 # hevSvcStop is signaled when the SCM sends us a notification | 259 # hevSvcStop is signaled when the SCM sends us a notification |
| 260 # to shutdown the service. | 260 # to shutdown the service. |
| 339 options: | 339 options: |
| 340 -n: sets the host name | 340 -n: sets the host name |
| 341 -p: sets the port to listen on (default: %(port)s) | 341 -p: sets the port to listen on (default: %(port)s) |
| 342 -u: sets the uid to this user after listening on the port | 342 -u: sets the uid to this user after listening on the port |
| 343 -g: sets the gid to this group after listening on the port | 343 -g: sets the gid to this group after listening on the port |
| 344 -l: sets a filename to log to (instead of stdout) | 344 -l: sets a filename to log to (instead of stderr / stdout) |
| 345 -d: run the server in the background and on UN*X write the server's PID | 345 -d: run the server in the background and on UN*X write the server's PID |
| 346 to the nominated file. The -l option *must* be specified if this | 346 to the nominated file. The -l option *must* be specified if this |
| 347 option is. | 347 option is. |
| 348 -N: log client machine names in access log instead of IP addresses (much | 348 -N: log client machine names in access log instead of IP addresses (much |
| 349 slower) | 349 slower) |
| 443 | 443 |
| 444 # obtain server before changing user id - allows to use port < | 444 # obtain server before changing user id - allows to use port < |
| 445 # 1024 if started as root | 445 # 1024 if started as root |
| 446 address = (hostname, port) | 446 address = (hostname, port) |
| 447 try: | 447 try: |
| 448 httpd = RoundupHTTPServer(address, RoundupRequestHandler) | 448 httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler) |
| 449 except socket.error, e: | 449 except socket.error, e: |
| 450 if e[0] == errno.EADDRINUSE: | 450 if e[0] == errno.EADDRINUSE: |
| 451 raise socket.error, \ | 451 raise socket.error, \ |
| 452 _("Unable to bind to port %s, port already in use." % port) | 452 _("Unable to bind to port %s, port already in use." % port) |
| 453 raise | 453 raise |
