Chromium Code Reviews| 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 | 10 import tempfile |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 gsutil_path = os.path.join(BASE_DIR, 'third_party', 'catapult', | 301 gsutil_path = os.path.join(BASE_DIR, 'third_party', 'catapult', |
| 302 'third_party', 'gsutil', 'gsutil.py') | 302 'third_party', 'gsutil', 'gsutil.py') |
| 303 subprocess.check_call([ | 303 subprocess.check_call([ |
| 304 sys.executable, gsutil_path, '-h', "Content-Type:%s" % content_type, | 304 sys.executable, gsutil_path, '-h', "Content-Type:%s" % content_type, |
| 305 'cp', temp_file.name, 'gs://%s/%s' % (bucket, dest)]) | 305 'cp', temp_file.name, 'gs://%s/%s' % (bucket, dest)]) |
| 306 | 306 |
| 307 return '%s/%s/%s' % (server_url, bucket, dest) | 307 return '%s/%s/%s' % (server_url, bucket, dest) |
| 308 | 308 |
| 309 def main(): | 309 def main(): |
| 310 parser = argparse.ArgumentParser() | 310 parser = argparse.ArgumentParser() |
| 311 parser.add_argument('--json-file', help='Path of json file.', required=True) | 311 parser.add_argument('--json-file', help='Path of json file.') |
| 312 parser.add_argument('--cs-base-url', help='Base url for code search.', | 312 parser.add_argument('--cs-base-url', help='Base url for code search.', |
| 313 default='http://cs.chromium.org') | 313 default='http://cs.chromium.org') |
| 314 parser.add_argument('--bucket', help='Google storage bucket.', required=True) | 314 parser.add_argument('--bucket', help='Google storage bucket.', required=True) |
| 315 parser.add_argument('--builder-name', help='Builder name.', required=True) | 315 parser.add_argument('--builder-name', help='Builder name.') |
| 316 parser.add_argument('--build-number', help='Build number.', required=True) | 316 parser.add_argument('--build-number', help='Build number.') |
| 317 parser.add_argument('--test-name', help='The name of the test.', | 317 parser.add_argument('--test-name', help='The name of the test.', |
| 318 required=True) | 318 required=True) |
| 319 parser.add_argument('--server-url', help='The url of the server.', | 319 parser.add_argument('--server-url', help='The url of the server.', |
| 320 default='https://storage.cloud.google.com') | 320 default='https://storage.cloud.google.com') |
| 321 parser.add_argument( | 321 parser.add_argument( |
| 322 '--content-type', | 322 '--content-type', |
| 323 help=('Content type, which is used to determine ' | 323 help=('Content type, which is used to determine ' |
| 324 'whether to download the file, or view in browser.'), | 324 'whether to download the file, or view in browser.'), |
| 325 default='text/html', | 325 default='text/html', |
| 326 choices=['text/html', 'application/octet-stream']) | 326 choices=['text/html', 'application/octet-stream']) |
| 327 parser.add_argument( | |
| 328 '-o', '--output-json', | |
| 329 help='(Swarming Isolated Merge Script API)' | |
|
jbudorick
2017/04/17 13:00:46
This should just be "(Swarming Merge Script API)",
BigBossZhiling
2017/04/17 20:23:11
Done.
| |
| 330 ' Output JSON file to create.') | |
| 331 parser.add_argument( | |
| 332 '--build-properties', | |
| 333 help='(Swarming Isolated Merge Script API) ' | |
| 334 'Build property JSON file provided by recipes.') | |
| 335 parser.add_argument( | |
| 336 '--summary-json', | |
| 337 help='(Swarming Isolated Merge Script API)' | |
| 338 ' Summary of shard state running on swarming.' | |
|
mikecase (-- gone --)
2017/04/17 17:59:20
nit, you need a space at the end of this line or b
BigBossZhiling
2017/04/17 20:23:11
Done.
| |
| 339 '(Output of the swarming.py collect' | |
| 340 ' --task-summary-json=XXX command.)') | |
| 341 parser.add_argument( | |
| 342 'positional', nargs='*', | |
|
mikecase (-- gone --)
2017/04/17 17:59:20
Im not familiar with this swarming merge scripts.
BigBossZhiling
2017/04/17 20:23:11
Acknowledged.
| |
| 343 help='output.json from shards.') | |
| 344 | |
| 327 | 345 |
| 328 args = parser.parse_args() | 346 args = parser.parse_args() |
| 329 if os.path.exists(args.json_file): | 347 |
| 330 result_html_string = result_details(args.json_file, args.cs_base_url, | 348 if (args.build_properties and args.output_json and |
|
jbudorick
2017/04/17 13:00:46
Instead of splitting like this, handle these argum
BigBossZhiling
2017/04/17 20:23:11
Done.
| |
| 349 args.summary_json and args.positional): | |
| 350 is_swarming = True | |
| 351 else: | |
| 352 is_swarming = False | |
| 353 | |
| 354 if is_swarming: | |
| 355 build_properties = json.loads(args.build_properties) | |
| 356 build_number = build_properties['buildnumber'] | |
| 357 builder_name = build_properties['buildname'] | |
| 358 output_json = args.output_json | |
| 359 json_file = args.positional[0] | |
| 360 else: | |
| 361 json_file = args.json_file | |
| 362 build_number = args.build_number | |
| 363 builder_name = args.builder_name | |
| 364 | |
| 365 if os.path.exists(json_file): | |
| 366 result_html_string = result_details(json_file, args.cs_base_url, | |
| 331 args.bucket, args.server_url) | 367 args.bucket, args.server_url) |
| 332 print upload_to_google_bucket(result_html_string.encode('UTF-8'), | 368 result_details_link = upload_to_google_bucket( |
| 333 args.test_name, args.builder_name, | 369 result_html_string.encode('UTF-8'), |
| 334 args.build_number, args.bucket, | 370 args.test_name, builder_name, |
| 335 args.server_url, args.content_type) | 371 build_number, args.bucket, |
| 372 args.server_url, args.content_type) | |
| 373 | |
| 374 if is_swarming: | |
|
jbudorick
2017/04/17 13:00:46
Similarly, write the output json if output_json is
BigBossZhiling
2017/04/17 20:23:11
Done.
| |
| 375 with open(json_file) as original_json_file: | |
| 376 json_object = json.loads(original_json_file.read()) | |
| 377 json_object['links'] = {'result_details': result_details_link} | |
| 378 with open(output_json, 'w') as f: | |
| 379 f.write(str(json_object)) | |
| 380 else: | |
| 381 print result_details_link | |
| 336 else: | 382 else: |
| 337 raise IOError('--json-file %s not found.' % args.json_file) | 383 raise IOError('--json-file %s not found.' % args.json_file) |
| 338 | 384 |
| 339 | 385 |
| 340 if __name__ == '__main__': | 386 if __name__ == '__main__': |
| 341 sys.exit(main()) | 387 sys.exit(main()) |
| OLD | NEW |