OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Start and stop Web Page Replay. | 6 """Start and stop Web Page Replay. |
7 | 7 |
8 Of the public module names, the following one is key: | 8 Of the public module names, the following one is key: |
9 ReplayServer: a class to start/stop Web Page Replay. | 9 ReplayServer: a class to start/stop Web Page Replay. |
10 """ | 10 """ |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 raise ReplayNotFoundError(label, path) | 120 raise ReplayNotFoundError(label, path) |
121 | 121 |
122 def _OpenLogFile(self): | 122 def _OpenLogFile(self): |
123 log_dir = os.path.dirname(self.log_path) | 123 log_dir = os.path.dirname(self.log_path) |
124 if not os.path.exists(log_dir): | 124 if not os.path.exists(log_dir): |
125 os.makedirs(log_dir) | 125 os.makedirs(log_dir) |
126 return open(self.log_path, 'w') | 126 return open(self.log_path, 'w') |
127 | 127 |
128 def IsStarted(self): | 128 def IsStarted(self): |
129 """Checks to see if the server is up and running.""" | 129 """Checks to see if the server is up and running.""" |
130 for _ in range(10): | 130 for _ in range(30): |
131 if self.replay_process.poll() is not None: | 131 if self.replay_process.poll() is not None: |
132 # The process has exited. | 132 # The process has exited. |
133 break | 133 break |
134 try: | 134 try: |
135 up_url = '%s://localhost:%s/web-page-replay-generate-200' | 135 up_url = '%s://localhost:%s/web-page-replay-generate-200' |
136 http_up_url = up_url % ('http', self._http_port) | 136 http_up_url = up_url % ('http', self._http_port) |
137 https_up_url = up_url % ('https', self._https_port) | 137 https_up_url = up_url % ('https', self._https_port) |
138 if (200 == urllib.urlopen(http_up_url, None, {}).getcode() and | 138 if (200 == urllib.urlopen(http_up_url, None, {}).getcode() and |
139 200 == urllib.urlopen(https_up_url, None, {}).getcode()): | 139 200 == urllib.urlopen(https_up_url, None, {}).getcode()): |
140 return True | 140 return True |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 self.log_fh.close() | 175 self.log_fh.close() |
176 | 176 |
177 def __enter__(self): | 177 def __enter__(self): |
178 """Add support for with-statement.""" | 178 """Add support for with-statement.""" |
179 self.StartServer() | 179 self.StartServer() |
180 return self | 180 return self |
181 | 181 |
182 def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): | 182 def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): |
183 """Add support for with-statement.""" | 183 """Add support for with-statement.""" |
184 self.StopServer() | 184 self.StopServer() |
OLD | NEW |