Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright 2017 The Chromium Authors. All rights reserved. | 3 # Copyright 2017 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 import argparse | 7 import argparse |
| 8 import json | 8 import json |
| 9 import logging | 9 import logging |
| 10 import os | 10 import os |
| 11 import shutil | 11 import shutil |
| 12 import sys | 12 import sys |
| 13 import tempfile | 13 import tempfile |
| 14 import time | |
| 14 | 15 |
| 15 from webkitpy.common.system.log_utils import configure_logging | 16 from webkitpy.common.system.log_utils import configure_logging |
| 16 from webkitpy.layout_tests import merge_results | 17 from webkitpy.layout_tests import merge_results |
| 17 | 18 |
| 18 # ------------------------------------------------------------------------ | 19 # ------------------------------------------------------------------------ |
| 19 | 20 |
| 21 def rmtree(dirname): | |
| 22 # Attempt to remove a directory tree. We try multiple times as on Windows a | |
| 23 # process which is currently closing could still have a file open in the | |
| 24 # directory. | |
| 25 attempts = 0 | |
| 26 while attempts < 5: | |
| 27 try: | |
| 28 shutil.rmtree(dirname) | |
| 29 break | |
| 30 except Exception as e: | |
| 31 logging.exception('Failed to remove %s', dirname) | |
| 32 time.sleep(1) | |
| 33 | |
| 34 # Check the path is gone. | |
| 35 if not os.path.exists(dirname): | |
| 36 return True | |
| 37 | |
| 38 logging.warning('Unable to remove %s!', dirname) | |
| 39 return False | |
| 40 | |
| 20 | 41 |
| 21 def main(argv): | 42 def main(argv): |
| 22 | 43 |
| 23 parser = argparse.ArgumentParser() | 44 parser = argparse.ArgumentParser() |
| 24 parser.description = """\ | 45 parser.description = """\ |
| 25 Merges sharded layout test results into a single output directory. | 46 Merges sharded layout test results into a single output directory. |
| 26 """ | 47 """ |
| 27 parser.epilog = """\ | 48 parser.epilog = """\ |
| 28 | 49 |
| 29 If a post merge script is given, it will be run on the resulting merged output | 50 If a post merge script is given, it will be run on the resulting merged output |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 except NameError: | 172 except NameError: |
| 152 results_json_value_overrides[k] = v | 173 results_json_value_overrides[k] = v |
| 153 logging.debug('results_json_value_overrides: %r', results_json_value_overrid es) | 174 logging.debug('results_json_value_overrides: %r', results_json_value_overrid es) |
| 154 | 175 |
| 155 merger = merge_results.LayoutTestDirMerger( | 176 merger = merge_results.LayoutTestDirMerger( |
| 156 results_json_value_overrides=results_json_value_overrides, | 177 results_json_value_overrides=results_json_value_overrides, |
| 157 results_json_allow_unknown_if_matching=args.results_json_allow_unknown_i f_matching) | 178 results_json_allow_unknown_if_matching=args.results_json_allow_unknown_i f_matching) |
| 158 if os.path.exists(args.output_directory): | 179 if os.path.exists(args.output_directory): |
| 159 logging.warning('Output directory exists %r', args.output_directory) | 180 logging.warning('Output directory exists %r', args.output_directory) |
| 160 if args.remove_existing_output_directory: | 181 if args.remove_existing_output_directory: |
| 161 shutil.rmtree(args.output_directory) | 182 rmtree(args.output_directory) |
|
Dirk Pranke
2017/05/05 01:05:02
if you're actually going to ignore the error in th
| |
| 162 elif not args.allow_existing_output_directory: | 183 elif not args.allow_existing_output_directory: |
| 163 raise IOError( | 184 raise IOError( |
| 164 ('Output directory %s exists!\n' | 185 ('Output directory %s exists!\n' |
| 165 'Use --allow-existing-output-directory to continue') % args.out put_directory) | 186 'Use --allow-existing-output-directory to continue') % args.out put_directory) |
| 166 | 187 |
| 167 merger.merge(args.output_directory, args.input_directories) | 188 merger.merge(args.output_directory, args.input_directories) |
| 168 | 189 |
| 169 merged_output_json = os.path.join(args.output_directory, 'output.json') | 190 merged_output_json = os.path.join(args.output_directory, 'output.json') |
| 170 if os.path.exists(merged_output_json) and args.output_json: | 191 if os.path.exists(merged_output_json) and args.output_json: |
| 171 logging.debug( | 192 logging.debug( |
| 172 'Copying output.json from %s to %s', merged_output_json, args.output _json) | 193 'Copying output.json from %s to %s', merged_output_json, args.output _json) |
| 173 shutil.copyfile(merged_output_json, args.output_json) | 194 shutil.copyfile(merged_output_json, args.output_json) |
| 174 | 195 |
| 175 if args.post_merge_script: | 196 if args.post_merge_script: |
| 176 logging.debug('Changing directory to %s', args.output_directory) | 197 logging.debug('Changing directory to %s', args.output_directory) |
| 177 os.chdir(args.output_directory) | 198 os.chdir(args.output_directory) |
| 178 | 199 |
| 179 post_script = list(args.post_merge_script) | 200 post_script = list(args.post_merge_script) |
| 180 post_script.append('--result-dir', args.output_directory) | 201 post_script.append('--result-dir', args.output_directory) |
| 181 | 202 |
| 182 logging.info('Running post merge script %r', post_script) | 203 logging.info('Running post merge script %r', post_script) |
| 183 os.execlp(post_script) | 204 os.execlp(post_script) |
| 184 | 205 |
| 185 main(sys.argv[1:]) | 206 main(sys.argv[1:]) |
| OLD | NEW |