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( | |
|
jbudorick
2017/04/18 15:59:25
For future CLs, it's worth noting that argparse ha
BigBossZhiling
2017/04/18 17:52:29
Acknowledged.
| |
| 328 '-o', '--output-json', | |
| 329 help='(Swarming Merge Script API)' | |
| 330 ' Output JSON file to create.') | |
| 331 parser.add_argument( | |
| 332 '--build-properties', | |
| 333 help='(Swarming Merge Script API) ' | |
| 334 'Build property JSON file provided by recipes.') | |
| 335 parser.add_argument( | |
| 336 '--summary-json', | |
| 337 help='(Swarming Merge Script API)' | |
| 338 ' Summary of shard state running on swarming.' | |
| 339 ' (Output of the swarming.py collect' | |
| 340 ' --task-summary-json=XXX command.)') | |
| 341 parser.add_argument( | |
| 342 'positional', nargs='*', | |
| 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 # One of build_perperties or (build_number or builder_names) should be given. |
|
mikecase (-- gone --)
2017/04/18 15:39:27
nit: I would move these commnets inside the Except
BigBossZhiling
2017/04/18 17:52:29
Done.
| |
| 331 args.bucket, args.server_url) | 349 if not (bool(args.build_properties) ^ |
|
jbudorick
2017/04/18 15:59:25
I would shy away from xor here and below. I think
BigBossZhiling
2017/04/18 17:52:29
Done.
| |
| 332 print upload_to_google_bucket(result_html_string.encode('UTF-8'), | 350 bool(args.build_number or args.builder_name)): |
|
mikecase (-- gone --)
2017/04/18 15:39:28
should this be bool(args.build_number AND args.bui
jbudorick
2017/04/18 15:59:25
I think this part is OK as-is.= given the check be
BigBossZhiling
2017/04/18 17:52:29
Acknowledged.
| |
| 333 args.test_name, args.builder_name, | 351 raise Exception('Error in build properties arguments.') |
| 334 args.build_number, args.bucket, | 352 |
| 335 args.server_url, args.content_type) | 353 # args.build_number and args.builder_name has to be be given together |
| 354 # or not given at all. | |
|
mikecase (-- gone --)
2017/04/18 15:39:28
nit: I would move these commnets inside the Except
| |
| 355 if bool(args.build_number) ^ bool(args.builder_name): | |
|
jbudorick
2017/04/18 15:59:25
if (args.build_number is None) != (args.builder_na
| |
| 356 raise Exception('Build number/builder name not specified.') | |
| 357 | |
| 358 # Only one of args.positional and args.json_file should be given. | |
|
mikecase (-- gone --)
2017/04/18 15:39:27
nit: I would move these commnets inside the Except
BigBossZhiling
2017/04/18 17:52:29
Done.
| |
| 359 if not bool(args.positional) ^ bool(args.json_file): | |
|
jbudorick
2017/04/18 15:59:25
(args.positional is None) != (args.json_file is No
BigBossZhiling
2017/04/18 17:52:29
Acknowledged.
| |
| 360 raise Exception('Error in json file arguments.') | |
| 361 | |
| 362 if args.build_properties: | |
| 363 build_properties = json.loads(args.build_properties) | |
| 364 if ((not 'buildnumber' in build_properties) or | |
| 365 (not 'buildername' in build_properties)): | |
| 366 raise Exception('Build number/builder name not specified.') | |
| 367 build_number = build_properties['buildnumber'] | |
| 368 builder_name = build_properties['buildername'] | |
| 369 | |
| 370 if args.build_number and args.builder_name: | |
|
jbudorick
2017/04/18 15:59:25
elif
BigBossZhiling
2017/04/18 17:52:29
Done.
| |
| 371 build_number = args.build_number | |
| 372 builder_name = args.builder_name | |
| 373 | |
| 374 if args.positional: | |
| 375 if not len(args.positional) == 1: | |
| 376 raise Exception('More than 1 json file specified.') | |
| 377 json_file = args.positional[0] | |
| 378 | |
| 379 if args.json_file: | |
|
jbudorick
2017/04/18 15:59:25
elif
BigBossZhiling
2017/04/18 17:52:28
Done.
| |
| 380 json_file = args.json_file | |
| 381 | |
| 382 if not os.path.exists(json_file): | |
| 383 raise IOError('--json-file %s not found.' % json_file) | |
| 384 | |
| 385 result_html_string = result_details(json_file, args.cs_base_url, | |
| 386 args.bucket, args.server_url) | |
| 387 result_details_link = upload_to_google_bucket( | |
| 388 result_html_string.encode('UTF-8'), | |
| 389 args.test_name, builder_name, | |
| 390 build_number, args.bucket, | |
| 391 args.server_url, args.content_type) | |
| 392 | |
| 393 if args.output_json: | |
| 394 with open(json_file) as original_json_file: | |
| 395 json_object = json.loads(original_json_file.read()) | |
| 396 json_object['links'] = {'result_details': result_details_link} | |
| 397 with open(args.output_json, 'w') as f: | |
| 398 f.write(str(json_object)) | |
| 336 else: | 399 else: |
| 337 raise IOError('--json-file %s not found.' % args.json_file) | 400 print result_details_link |
| 338 | |
| 339 | 401 |
| 340 if __name__ == '__main__': | 402 if __name__ == '__main__': |
| 341 sys.exit(main()) | 403 sys.exit(main()) |
| OLD | NEW |