| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 def __init__(self, archive_path, replay_host, dns_port, http_port, https_port, | 88 def __init__(self, archive_path, replay_host, dns_port, http_port, https_port, |
| 89 replay_options=None, replay_dir=None, | 89 replay_options=None, replay_dir=None, |
| 90 log_path=None): | 90 log_path=None): |
| 91 """Initialize ReplayServer. | 91 """Initialize ReplayServer. |
| 92 | 92 |
| 93 Args: | 93 Args: |
| 94 archive_path: a path to a specific WPR archive (required). | 94 archive_path: a path to a specific WPR archive (required). |
| 95 replay_host: the hostname to serve traffic. | 95 replay_host: the hostname to serve traffic. |
| 96 dns_port: an integer port on which to serve DNS traffic. May be zero | 96 dns_port: an integer port on which to serve DNS traffic. May be zero |
| 97 to let the OS choose an available port. | 97 to let the OS choose an available port. If None DNS forwarding is |
| 98 disabled. |
| 98 http_port: an integer port on which to serve HTTP traffic. May be zero | 99 http_port: an integer port on which to serve HTTP traffic. May be zero |
| 99 to let the OS choose an available port. | 100 to let the OS choose an available port. |
| 100 https_port: an integer port on which to serve HTTPS traffic. May be zero | 101 https_port: an integer port on which to serve HTTPS traffic. May be zero |
| 101 to let the OS choose an available port. | 102 to let the OS choose an available port. |
| 102 replay_options: an iterable of options strings to forward to replay.py. | 103 replay_options: an iterable of options strings to forward to replay.py. |
| 103 replay_dir: directory that has replay.py and related modules. | 104 replay_dir: directory that has replay.py and related modules. |
| 104 log_path: a path to a log file. | 105 log_path: a path to a log file. |
| 105 """ | 106 """ |
| 106 self.archive_path = os.environ.get('WPR_ARCHIVE_PATH', archive_path) | 107 self.archive_path = os.environ.get('WPR_ARCHIVE_PATH', archive_path) |
| 107 self.replay_options = list(replay_options or ()) | 108 self.replay_options = list(replay_options or ()) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 126 self._CheckPath('replay script', self.replay_py) | 127 self._CheckPath('replay script', self.replay_py) |
| 127 | 128 |
| 128 self.log_fh = None | 129 self.log_fh = None |
| 129 self.replay_process = None | 130 self.replay_process = None |
| 130 | 131 |
| 131 def _AddDefaultReplayOptions(self): | 132 def _AddDefaultReplayOptions(self): |
| 132 """Set WPR command-line options. Can be overridden if needed.""" | 133 """Set WPR command-line options. Can be overridden if needed.""" |
| 133 self.replay_options = [ | 134 self.replay_options = [ |
| 134 '--host', str(self._replay_host), | 135 '--host', str(self._replay_host), |
| 135 '--port', str(self.http_port), | 136 '--port', str(self.http_port), |
| 136 '--dns_port', str(self.dns_port), | |
| 137 '--ssl_port', str(self.https_port), | 137 '--ssl_port', str(self.https_port), |
| 138 '--use_closest_match', | 138 '--use_closest_match', |
| 139 '--no-dns_forwarding', | 139 '--no-dns_forwarding', |
| 140 '--log_level', 'warning' | 140 '--log_level', 'warning' |
| 141 ] + self.replay_options | 141 ] + self.replay_options |
| 142 if self.dns_port is not None: |
| 143 self.replay_options.extend(['--dns_port', str(self.dns_port)]) |
| 142 | 144 |
| 143 def _CheckPath(self, label, path): | 145 def _CheckPath(self, label, path): |
| 144 if not os.path.exists(path): | 146 if not os.path.exists(path): |
| 145 raise ReplayNotFoundError(label, path) | 147 raise ReplayNotFoundError(label, path) |
| 146 | 148 |
| 147 def _OpenLogFile(self): | 149 def _OpenLogFile(self): |
| 148 log_dir = os.path.dirname(self.log_path) | 150 log_dir = os.path.dirname(self.log_path) |
| 149 if not os.path.exists(log_dir): | 151 if not os.path.exists(log_dir): |
| 150 os.makedirs(log_dir) | 152 os.makedirs(log_dir) |
| 151 return open(self.log_path, 'w') | 153 return open(self.log_path, 'w') |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 self.log_fh.close() | 246 self.log_fh.close() |
| 245 | 247 |
| 246 def __enter__(self): | 248 def __enter__(self): |
| 247 """Add support for with-statement.""" | 249 """Add support for with-statement.""" |
| 248 self.StartServer() | 250 self.StartServer() |
| 249 return self | 251 return self |
| 250 | 252 |
| 251 def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): | 253 def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): |
| 252 """Add support for with-statement.""" | 254 """Add support for with-statement.""" |
| 253 self.StopServer() | 255 self.StopServer() |
| OLD | NEW |