Chromium Code Reviews| 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 import logging | 5 import logging |
| 6 import os | |
| 7 import shutil | |
| 6 import sys | 8 import sys |
| 9 import tempfile | |
| 7 import time | 10 import time |
| 8 | 11 |
| 9 from telemetry import all_page_actions # pylint: disable=W0611 | 12 from telemetry import all_page_actions # pylint: disable=W0611 |
| 10 from telemetry import browser_finder | 13 from telemetry import browser_finder |
| 11 from telemetry import browser_options | 14 from telemetry import browser_options |
| 12 from telemetry import discover | 15 from telemetry import discover |
| 13 from telemetry import multi_page_benchmark | 16 from telemetry import multi_page_benchmark |
| 14 from telemetry import page_runner | 17 from telemetry import page_runner |
| 15 from telemetry import page_set | 18 from telemetry import page_set |
| 16 from telemetry import page_test | 19 from telemetry import page_test |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 recorder.AddCommandLineOptions(parser) | 73 recorder.AddCommandLineOptions(parser) |
| 71 | 74 |
| 72 _, args = parser.parse_args() | 75 _, args = parser.parse_args() |
| 73 | 76 |
| 74 if len(args) != 1: | 77 if len(args) != 1: |
| 75 parser.print_usage() | 78 parser.print_usage() |
| 76 sys.exit(1) | 79 sys.exit(1) |
| 77 | 80 |
| 78 ps = page_set.PageSet.FromFile(args[0]) | 81 ps = page_set.PageSet.FromFile(args[0]) |
| 79 | 82 |
| 83 # Set the archive path to something temporary. | |
| 84 temp_target_wpr_file_path = tempfile.mkstemp()[1] | |
| 85 for page in ps.pages: | |
| 86 page.archive_path = temp_target_wpr_file_path | |
| 87 | |
| 88 # Do the actual recording. | |
| 80 options.wpr_mode = wpr_modes.WPR_RECORD | 89 options.wpr_mode = wpr_modes.WPR_RECORD |
| 81 recorder.CustomizeBrowserOptions(options) | 90 recorder.CustomizeBrowserOptions(options) |
| 82 possible_browser = browser_finder.FindBrowser(options) | 91 possible_browser = browser_finder.FindBrowser(options) |
| 83 if not possible_browser: | 92 if not possible_browser: |
| 84 print >> sys.stderr, """No browser found.\n | 93 print >> sys.stderr, """No browser found.\n |
| 85 Use --browser=list to figure out which are available.\n""" | 94 Use --browser=list to figure out which are available.\n""" |
| 86 sys.exit(1) | 95 sys.exit(1) |
| 87 results = page_test.PageTestResults() | 96 results = page_test.PageTestResults() |
| 97 pages_run = [] | |
| 88 with page_runner.PageRunner(ps) as runner: | 98 with page_runner.PageRunner(ps) as runner: |
| 89 runner.Run(options, possible_browser, recorder, results) | 99 runner.Run(options, possible_browser, recorder, results, pages_run) |
| 90 | 100 |
| 91 if len(results.page_failures): | 101 if results.page_failures: |
| 92 logging.warning('Failed pages: %s', '\n'.join( | 102 logging.warning('Failed pages: %s', '\n'.join( |
| 93 [failure['page'].url for failure in results.page_failures])) | 103 [failure['page'].url for failure in results.page_failures])) |
| 94 | 104 |
| 95 if len(results.skipped_pages): | 105 if results.skipped_pages: |
| 96 logging.warning('Skipped pages: %s', '\n'.join( | 106 logging.warning('Skipped pages: %s', '\n'.join( |
| 97 [skipped['page'].url for skipped in results.skipped_pages])) | 107 [skipped['page'].url for skipped in results.skipped_pages])) |
| 108 | |
| 109 if not results.page_failures: | |
| 110 # Update the metadata for the pages which were recorded. | |
| 111 target_wpr_file_path = ps.wpr_archive_info.AddNewRecording(pages_run) | |
|
dtu
2013/01/30 02:19:10
This method could take temp_target_wpr_file_path a
marja
2013/01/30 12:26:22
Done.
| |
| 112 | |
| 113 shutil.move(temp_target_wpr_file_path, target_wpr_file_path) | |
| 114 ps.wpr_archive_info.WriteToFile() | |
| 115 ps.wpr_archive_info.DeleteAbandonedWprFiles() | |
| 116 | |
| 117 else: | |
| 118 os.remove(temp_target_wpr_file_path) | |
| 119 | |
| 98 return min(255, len(results.page_failures)) | 120 return min(255, len(results.page_failures)) |
| OLD | NEW |