OLD | NEW |
---|---|
1 #! /usr/bin/env python | 1 #! /usr/bin/env 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 collections | 8 import collections |
9 import json | 9 import json |
10 import tempfile | |
11 import time | |
10 import os | 12 import os |
13 import subprocess | |
11 import sys | 14 import sys |
12 | 15 |
13 CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) | 16 CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) |
14 BASE_DIR = os.path.abspath(os.path.join( | 17 BASE_DIR = os.path.abspath(os.path.join( |
15 CURRENT_DIR, '..', '..', '..', '..', '..')) | 18 CURRENT_DIR, '..', '..', '..', '..', '..')) |
16 sys.path.append(os.path.join(BASE_DIR, 'third_party')) | 19 sys.path.append(os.path.join(BASE_DIR, 'third_party')) |
17 import jinja2 # pylint: disable=import-error | 20 import jinja2 # pylint: disable=import-error |
18 JINJA_ENVIRONMENT = jinja2.Environment( | 21 JINJA_ENVIRONMENT = jinja2.Environment( |
19 loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), | 22 loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), |
20 autoescape=True) | 23 autoescape=True) |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 | 270 |
268 if not 'per_iteration_data' in json_object: | 271 if not 'per_iteration_data' in json_object: |
269 return 'Error: json file missing per_iteration_data.' | 272 return 'Error: json file missing per_iteration_data.' |
270 | 273 |
271 results_dict = collections.defaultdict(list) | 274 results_dict = collections.defaultdict(list) |
272 for testsuite_run in json_object['per_iteration_data']: | 275 for testsuite_run in json_object['per_iteration_data']: |
273 for test, test_runs in testsuite_run.iteritems(): | 276 for test, test_runs in testsuite_run.iteritems(): |
274 results_dict[test].extend(test_runs) | 277 results_dict[test].extend(test_runs) |
275 return results_to_html(results_dict, cs_base_url, master_name) | 278 return results_to_html(results_dict, cs_base_url, master_name) |
276 | 279 |
280 def upload_to_google_bucket(html, args): | |
281 with tempfile.NamedTemporaryFile(suffix='.html') as temp_file: | |
282 temp_file.write(html) | |
283 dest = 'html/%s/%s_%s_%s.html' % ( | |
284 args.test_name if args.test_name else 'test_name', | |
BigBossZhiling
2017/03/27 22:54:54
I am not sure whether we want to make test_name, (
jbudorick
2017/03/28 02:15:33
I think they should all be mandatory.
| |
285 args.builder_name if args.builder_name else 'builder_name', | |
286 args.build_number if args.build_number else 'builder_number', | |
287 time.strftime('%Y_%m_%d_T%H_%M_%S')) | |
288 gsutil_path = os.path.join(BASE_DIR, 'third_party', 'catapult', | |
289 'third_party', 'gsutil', 'gsutil.py') | |
290 | |
291 subprocess.check_call('python %s cp %s gs://%s/%s' % ( | |
292 gsutil_path, temp_file.name, args.bucket, dest), shell=True) | |
293 return 'https://storage.googleapis.com/%s/%s' % (args.bucket, dest) | |
277 | 294 |
278 def main(): | 295 def main(): |
279 parser = argparse.ArgumentParser() | 296 parser = argparse.ArgumentParser() |
280 parser.add_argument('--json-file', help='Path of json file.', required=True) | 297 parser.add_argument('--json-file', help='Path of json file.', required=True) |
281 parser.add_argument('--cs-base-url', help='Base url for code search.', | 298 parser.add_argument('--cs-base-url', help='Base url for code search.', |
282 default='http://cs.chromium.org') | 299 default='http://cs.chromium.org') |
283 parser.add_argument('--master-name', help='Master name in urls.') | 300 parser.add_argument('--master-name', help='Master name in urls.') |
301 parser.add_argument('--bucket', default='chromium-result-details') | |
302 parser.add_argument('--builder-name', help='Builder name.') | |
303 parser.add_argument('--build-number', help='Build number.') | |
304 parser.add_argument('--test-name', help='The name of the test.') | |
284 | 305 |
285 args = parser.parse_args() | 306 args = parser.parse_args() |
286 if os.path.exists(args.json_file): | 307 if os.path.exists(args.json_file): |
287 result_html_string = result_details(args.json_file, args.cs_base_url, | 308 result_html_string = result_details(args.json_file, args.cs_base_url, |
288 args.master_name) | 309 args.master_name) |
289 print result_html_string.encode('UTF-8') | 310 print upload_to_google_bucket(result_html_string.encode('UTF-8'), |
311 args) | |
jbudorick
2017/03/28 02:15:33
This should pass args.test_name, args.builder_name
| |
290 else: | 312 else: |
291 raise IOError('--json-file %s not found.' % args.json_file) | 313 raise IOError('--json-file %s not found.' % args.json_file) |
292 | 314 |
293 | 315 |
294 if __name__ == '__main__': | 316 if __name__ == '__main__': |
295 sys.exit(main()) | 317 sys.exit(main()) |
OLD | NEW |