Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: third_party/WebKit/Tools/Scripts/merge-layout-test-results

Issue 2862173002: webkitpy: Merge script fix windows directory removing. (Closed)
Patch Set: Rework error handling. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 errors = []
26 def onerror(func, path, exc_info):
27 errors.append(path)
28 logging.exception('Failed at %s %s: %r', func, path, exc_info)
29
30 attempts = 0
31 while attempts < 5:
32 del errors[:]
33 shutil.rmtree(dirname, onerror=onerror)
34 if not errors:
35 break
36 time.sleep(1)
37
38 # Check the path is gone.
39 if not os.path.exists(dirname):
40 return True
41
42 logging.warning('Unable to remove %s!', dirname)
43 return False
44
20 45
21 def main(argv): 46 def main(argv):
22 47
23 parser = argparse.ArgumentParser() 48 parser = argparse.ArgumentParser()
24 parser.description = """\ 49 parser.description = """\
25 Merges sharded layout test results into a single output directory. 50 Merges sharded layout test results into a single output directory.
26 """ 51 """
27 parser.epilog = """\ 52 parser.epilog = """\
28 53
29 If a post merge script is given, it will be run on the resulting merged output 54 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
151 except NameError: 176 except NameError:
152 results_json_value_overrides[k] = v 177 results_json_value_overrides[k] = v
153 logging.debug('results_json_value_overrides: %r', results_json_value_overrid es) 178 logging.debug('results_json_value_overrides: %r', results_json_value_overrid es)
154 179
155 merger = merge_results.LayoutTestDirMerger( 180 merger = merge_results.LayoutTestDirMerger(
156 results_json_value_overrides=results_json_value_overrides, 181 results_json_value_overrides=results_json_value_overrides,
157 results_json_allow_unknown_if_matching=args.results_json_allow_unknown_i f_matching) 182 results_json_allow_unknown_if_matching=args.results_json_allow_unknown_i f_matching)
158 if os.path.exists(args.output_directory): 183 if os.path.exists(args.output_directory):
159 logging.warning('Output directory exists %r', args.output_directory) 184 logging.warning('Output directory exists %r', args.output_directory)
160 if args.remove_existing_output_directory: 185 if args.remove_existing_output_directory:
161 shutil.rmtree(args.output_directory) 186 rmtree(args.output_directory)
Dirk Pranke 2017/05/05 01:49:49 You're still ignoring the error code. You should p
mithro 2017/05/05 02:29:20 Done.
162 elif not args.allow_existing_output_directory: 187 elif not args.allow_existing_output_directory:
163 raise IOError( 188 raise IOError(
164 ('Output directory %s exists!\n' 189 ('Output directory %s exists!\n'
165 'Use --allow-existing-output-directory to continue') % args.out put_directory) 190 'Use --allow-existing-output-directory to continue') % args.out put_directory)
166 191
167 merger.merge(args.output_directory, args.input_directories) 192 merger.merge(args.output_directory, args.input_directories)
168 193
169 merged_output_json = os.path.join(args.output_directory, 'output.json') 194 merged_output_json = os.path.join(args.output_directory, 'output.json')
170 if os.path.exists(merged_output_json) and args.output_json: 195 if os.path.exists(merged_output_json) and args.output_json:
171 logging.debug( 196 logging.debug(
172 'Copying output.json from %s to %s', merged_output_json, args.output _json) 197 'Copying output.json from %s to %s', merged_output_json, args.output _json)
173 shutil.copyfile(merged_output_json, args.output_json) 198 shutil.copyfile(merged_output_json, args.output_json)
174 199
175 if args.post_merge_script: 200 if args.post_merge_script:
176 logging.debug('Changing directory to %s', args.output_directory) 201 logging.debug('Changing directory to %s', args.output_directory)
177 os.chdir(args.output_directory) 202 os.chdir(args.output_directory)
178 203
179 post_script = list(args.post_merge_script) 204 post_script = list(args.post_merge_script)
180 post_script.append('--result-dir', args.output_directory) 205 post_script.append('--result-dir', args.output_directory)
181 206
182 logging.info('Running post merge script %r', post_script) 207 logging.info('Running post merge script %r', post_script)
183 os.execlp(post_script) 208 os.execlp(post_script)
184 209
185 main(sys.argv[1:]) 210 main(sys.argv[1:])
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698