| OLD | NEW |
| 1 #!/bin/env python | 1 #!/bin/env python |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """A class to help start/stop the lighttpd server used by layout tests.""" | 6 """A class to help start/stop the lighttpd server used by layout tests.""" |
| 7 | 7 |
| 8 | 8 |
| 9 import logging | 9 import logging |
| 10 import optparse | 10 import optparse |
| 11 import os | 11 import os |
| 12 import platform_utils | 12 import platform_utils |
| 13 import subprocess | 13 import subprocess |
| 14 import sys | 14 import sys |
| 15 import tempfile | 15 import tempfile |
| 16 import time | 16 import time |
| 17 import urllib | 17 import urllib |
| 18 | 18 |
| 19 import google.path_utils | 19 import google.path_utils |
| 20 | 20 |
| 21 # This will be a native path to the directory this file resides in. | 21 # This will be a native path to the directory this file resides in. |
| 22 # It can either be relative or absolute depending how it's executed. | 22 # It can either be relative or absolute depending how it's executed. |
| 23 THISDIR = os.path.dirname(os.path.abspath(__file__)) | 23 THISDIR = os.path.dirname(os.path.abspath(__file__)) |
| 24 | 24 |
| 25 def PathFromBase(*pathies): | 25 def PathFromBase(*pathies): |
| 26 return google.path_utils.FindUpward(THISDIR, *pathies) | 26 return google.path_utils.FindUpward(THISDIR, *pathies) |
| 27 | 27 |
| 28 def RemoveLogFiles(folder, starts_with): |
| 29 files = os.listdir(folder) |
| 30 for file in files: |
| 31 if file.startswith(starts_with) : |
| 32 full_path = os.path.join(folder, file) |
| 33 os.remove(full_path) |
| 34 |
| 28 class HttpdNotStarted(Exception): | 35 class HttpdNotStarted(Exception): |
| 29 pass | 36 pass |
| 30 | 37 |
| 31 class Lighttpd: | 38 class Lighttpd: |
| 32 # Webkit tests | 39 # Webkit tests |
| 33 try: | 40 try: |
| 34 _webkit_tests = PathFromBase('webkit', 'data', 'layout_tests', | 41 _webkit_tests = PathFromBase('webkit', 'data', 'layout_tests', |
| 35 'LayoutTests', 'http', 'tests') | 42 'LayoutTests', 'http', 'tests') |
| 36 except google.path_utils.PathNotFound: | 43 except google.path_utils.PathNotFound: |
| 37 # If webkit/data/layout_tests/LayoutTests/http/tests does not exist, assume | 44 # If webkit/data/layout_tests/LayoutTests/http/tests does not exist, assume |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 raise 'Lighttpd already running' | 104 raise 'Lighttpd already running' |
| 98 | 105 |
| 99 base_conf_file = os.path.join(THISDIR, 'lighttpd.conf') | 106 base_conf_file = os.path.join(THISDIR, 'lighttpd.conf') |
| 100 out_conf_file = os.path.join(self._output_dir, 'lighttpd.conf') | 107 out_conf_file = os.path.join(self._output_dir, 'lighttpd.conf') |
| 101 time_str = time.strftime("%d%b%Y-%H%M%S") | 108 time_str = time.strftime("%d%b%Y-%H%M%S") |
| 102 access_file_name = "access.log-" + time_str + ".txt" | 109 access_file_name = "access.log-" + time_str + ".txt" |
| 103 access_log = os.path.join(self._output_dir, access_file_name) | 110 access_log = os.path.join(self._output_dir, access_file_name) |
| 104 log_file_name = "error.log-" + time_str + ".txt" | 111 log_file_name = "error.log-" + time_str + ".txt" |
| 105 error_log = os.path.join(self._output_dir, log_file_name) | 112 error_log = os.path.join(self._output_dir, log_file_name) |
| 106 | 113 |
| 114 # Remove old log files. We only need to keep the last ones. |
| 115 RemoveLogFiles(self._output_dir, "access.log-") |
| 116 RemoveLogFiles(self._output_dir, "error.log-") |
| 117 |
| 107 # Write out the config | 118 # Write out the config |
| 108 f = file(base_conf_file, 'rb') | 119 f = file(base_conf_file, 'rb') |
| 109 base_conf = f.read() | 120 base_conf = f.read() |
| 110 f.close() | 121 f.close() |
| 111 | 122 |
| 112 f = file(out_conf_file, 'wb') | 123 f = file(out_conf_file, 'wb') |
| 113 f.write(base_conf) | 124 f.write(base_conf) |
| 114 | 125 |
| 115 # Write out our cgi handlers. Run perl through env so that it processes | 126 # Write out our cgi handlers. Run perl through env so that it processes |
| 116 # the #! line and runs perl with the proper command line arguments. | 127 # the #! line and runs perl with the proper command line arguments. |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 # Specifying port but no root does not seem meaningful. | 274 # Specifying port but no root does not seem meaningful. |
| 264 raise 'Specifying port requires also a root.' | 275 raise 'Specifying port requires also a root.' |
| 265 httpd = Lighttpd(tempfile.gettempdir(), | 276 httpd = Lighttpd(tempfile.gettempdir(), |
| 266 port=options.port, | 277 port=options.port, |
| 267 root=options.root, | 278 root=options.root, |
| 268 register_cygwin=options.register_cygwin) | 279 register_cygwin=options.register_cygwin) |
| 269 if 'start' == options.server: | 280 if 'start' == options.server: |
| 270 httpd.Start() | 281 httpd.Start() |
| 271 else: | 282 else: |
| 272 httpd.Stop(force=True) | 283 httpd.Stop(force=True) |
| OLD | NEW |