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 stat | |
| 11 import shutil | 12 import shutil |
| 12 import sys | 13 import sys |
| 13 import tempfile | 14 import tempfile |
| 14 import time | 15 import time |
| 15 | 16 |
| 17 from webkitpy.common.system.filesystem import FileSystem | |
| 16 from webkitpy.common.system.log_utils import configure_logging | 18 from webkitpy.common.system.log_utils import configure_logging |
| 17 from webkitpy.layout_tests import merge_results | 19 from webkitpy.layout_tests import merge_results |
| 18 | 20 |
| 19 # ------------------------------------------------------------------------ | 21 # ------------------------------------------------------------------------ |
| 20 | 22 |
| 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 logging.info('Removing %s', dirname) | |
| 26 errors = [] | |
| 27 def onerror(func, path, exc_info): | |
| 28 errors.append(path) | |
| 29 logging.exception('Failed at %s %s: %r', func, path, exc_info) | |
| 30 | |
| 31 attempts = 0 | |
| 32 while attempts < 5: | |
| 33 del errors[:] | |
| 34 shutil.rmtree(dirname, onerror=onerror) | |
| 35 if not errors: | |
| 36 break | |
| 37 attempts += 1 | |
| 38 time.sleep(1) | |
| 39 | |
| 40 # Check the path is gone. | |
| 41 if not os.path.exists(dirname): | |
| 42 return | |
| 43 | |
| 44 logging.warning('Unable to remove %s', dirname) | |
| 45 for dirpath, dirnames, filenames in os.walk(dirname, onerror=onerror, topdow n=False): | |
| 46 for fname in filenames: | |
| 47 logging.warning('File %s still in output dir.', os.path.join(dirpath , fname)) | |
| 48 for dname in dirnames: | |
| 49 logging.warning('Dir %s still in output dir.', os.path.join(dirpath, dname)) | |
| 50 | |
| 51 | |
| 52 def main(argv): | 23 def main(argv): |
| 53 | 24 |
| 54 parser = argparse.ArgumentParser() | 25 parser = argparse.ArgumentParser() |
| 55 parser.description = """\ | 26 parser.description = """\ |
| 56 Merges sharded layout test results into a single output directory. | 27 Merges sharded layout test results into a single output directory. |
| 57 """ | 28 """ |
| 58 parser.epilog = """\ | 29 parser.epilog = """\ |
| 59 | 30 |
| 60 If a post merge script is given, it will be run on the resulting merged output | 31 If a post merge script is given, it will be run on the resulting merged output |
| 61 directory. The script will be given the arguments plus | 32 directory. The script will be given the arguments plus |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 assert k not in results_json_value_overrides | 150 assert k not in results_json_value_overrides |
| 180 try: | 151 try: |
| 181 results_json_value_overrides[k] = eval(v) | 152 results_json_value_overrides[k] = eval(v) |
| 182 except NameError: | 153 except NameError: |
| 183 results_json_value_overrides[k] = v | 154 results_json_value_overrides[k] = v |
| 184 logging.debug('results_json_value_overrides: %r', results_json_value_overrid es) | 155 logging.debug('results_json_value_overrides: %r', results_json_value_overrid es) |
| 185 | 156 |
| 186 merger = merge_results.LayoutTestDirMerger( | 157 merger = merge_results.LayoutTestDirMerger( |
| 187 results_json_value_overrides=results_json_value_overrides, | 158 results_json_value_overrides=results_json_value_overrides, |
| 188 results_json_allow_unknown_if_matching=args.results_json_allow_unknown_i f_matching) | 159 results_json_allow_unknown_if_matching=args.results_json_allow_unknown_i f_matching) |
| 160 | |
| 189 if os.path.exists(args.output_directory): | 161 if os.path.exists(args.output_directory): |
| 190 logging.warning('Output directory exists %r', args.output_directory) | 162 logging.warning('Output directory exists %r', args.output_directory) |
| 191 if args.remove_existing_output_directory: | 163 if not args.allow_existing_output_directory: |
| 192 rmtree(args.output_directory) | |
| 193 elif not args.allow_existing_output_directory: | |
| 194 raise IOError( | 164 raise IOError( |
| 195 ('Output directory %s exists!\n' | 165 ('Output directory %s exists!\n' |
| 196 'Use --allow-existing-output-directory to continue') % args.out put_directory) | 166 'Use --allow-existing-output-directory to continue') % args.out put_directory) |
| 167 else: | |
| 168 os.makedirs(args.output_directory) | |
| 169 | |
| 170 if args.remove_existing_output_directory and not FileSystem().remove_content s(args.output_directory): | |
|
mcgreevy_g
2017/05/29 07:00:54
It's a bit odd to remove the contents of a directo
mithro
2017/05/29 07:14:54
Done.
| |
| 171 raise IOError( | |
| 172 ('Unable to remove output directory %s contents!\n' | |
| 173 'See log output for errors.') % args.output_directory) | |
| 197 | 174 |
| 198 merger.merge(args.output_directory, args.input_directories) | 175 merger.merge(args.output_directory, args.input_directories) |
| 199 | 176 |
| 200 merged_output_json = os.path.join(args.output_directory, 'output.json') | 177 merged_output_json = os.path.join(args.output_directory, 'output.json') |
| 201 if os.path.exists(merged_output_json) and args.output_json: | 178 if os.path.exists(merged_output_json) and args.output_json: |
| 202 logging.debug( | 179 logging.debug( |
| 203 'Copying output.json from %s to %s', merged_output_json, args.output _json) | 180 'Copying output.json from %s to %s', merged_output_json, args.output _json) |
| 204 shutil.copyfile(merged_output_json, args.output_json) | 181 shutil.copyfile(merged_output_json, args.output_json) |
| 205 | 182 |
| 206 if args.post_merge_script: | 183 if args.post_merge_script: |
| 207 logging.debug('Changing directory to %s', args.output_directory) | 184 logging.debug('Changing directory to %s', args.output_directory) |
| 208 os.chdir(args.output_directory) | 185 os.chdir(args.output_directory) |
| 209 | 186 |
| 210 post_script = list(args.post_merge_script) | 187 post_script = list(args.post_merge_script) |
| 211 post_script.append('--result-dir', args.output_directory) | 188 post_script.append('--result-dir', args.output_directory) |
| 212 | 189 |
| 213 logging.info('Running post merge script %r', post_script) | 190 logging.info('Running post merge script %r', post_script) |
| 214 os.execlp(post_script) | 191 os.execlp(post_script) |
| 215 | 192 |
| 216 main(sys.argv[1:]) | 193 main(sys.argv[1:]) |
| OLD | NEW |