OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Provides a convenient wrapper for spawning a test lighttpd instance. | 7 """Provides a convenient wrapper for spawning a test lighttpd instance. |
8 | 8 |
9 Usage: | 9 Usage: |
10 lighttpd_server PATH_TO_DOC_ROOT | 10 lighttpd_server PATH_TO_DOC_ROOT |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 return (None, server_msg) | 133 return (None, server_msg) |
134 client_error = ('Bad response: %s %s version %s\n ' % | 134 client_error = ('Bad response: %s %s version %s\n ' % |
135 (r.status, r.reason, r.version) + | 135 (r.status, r.reason, r.version) + |
136 '\n '.join([': '.join(h) for h in r.getheaders()])) | 136 '\n '.join([': '.join(h) for h in r.getheaders()])) |
137 except (httplib.HTTPException, socket.error) as client_error: | 137 except (httplib.HTTPException, socket.error) as client_error: |
138 pass # Probably too quick connecting: try again | 138 pass # Probably too quick connecting: try again |
139 # Check for server startup error messages | 139 # Check for server startup error messages |
140 ix = self.process.expect([pexpect.TIMEOUT, pexpect.EOF, '.+'], | 140 ix = self.process.expect([pexpect.TIMEOUT, pexpect.EOF, '.+'], |
141 timeout=timeout) | 141 timeout=timeout) |
142 if ix == 2: # stdout spew from the server | 142 if ix == 2: # stdout spew from the server |
143 server_msg += self.process.match.group(0) | 143 server_msg += self.process.match.group(0) # pylint: disable=no-member |
144 elif ix == 1: # EOF -- server has quit so giveup. | 144 elif ix == 1: # EOF -- server has quit so giveup. |
145 client_error = client_error or 'Server exited' | 145 client_error = client_error or 'Server exited' |
146 break | 146 break |
147 return (client_error or 'Timeout', server_msg) | 147 return (client_error or 'Timeout', server_msg) |
148 | 148 |
149 @staticmethod | 149 @staticmethod |
150 def _KillProcessListeningOnPort(port): | 150 def _KillProcessListeningOnPort(port): |
151 """Checks if there is a process listening on port number |port| and | 151 """Checks if there is a process listening on port number |port| and |
152 terminates it if found. | 152 terminates it if found. |
153 | 153 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 raw_input('Server running at http://127.0.0.1:%s -' | 247 raw_input('Server running at http://127.0.0.1:%s -' |
248 ' press Enter to exit it.' % server.port) | 248 ' press Enter to exit it.' % server.port) |
249 else: | 249 else: |
250 print 'Server exit code:', server.process.exitstatus | 250 print 'Server exit code:', server.process.exitstatus |
251 finally: | 251 finally: |
252 server.ShutdownHttpServer() | 252 server.ShutdownHttpServer() |
253 | 253 |
254 | 254 |
255 if __name__ == '__main__': | 255 if __name__ == '__main__': |
256 sys.exit(main(sys.argv)) | 256 sys.exit(main(sys.argv)) |
OLD | NEW |