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 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.') |
327 | 344 |
328 args = parser.parse_args() | 345 args = parser.parse_args() |
329 if os.path.exists(args.json_file): | 346 |
330 result_html_string = result_details(args.json_file, args.cs_base_url, | 347 if ((args.build_properties is None) == |
331 args.bucket, args.server_url) | 348 (args.build_number is None or args.builder_name is None)): |
332 print upload_to_google_bucket(result_html_string.encode('UTF-8'), | 349 raise parser.error('Exactly one of build_perperties or ' |
333 args.test_name, args.builder_name, | 350 '(build_number or builder_names) should be given.') |
334 args.build_number, args.bucket, | 351 |
335 args.server_url, args.content_type) | 352 if (args.build_number is None) != (args.builder_name is None): |
| 353 raise parser.error('args.build_number and args.builder_name ' |
| 354 'has to be be given together' |
| 355 'or not given at all.') |
| 356 |
| 357 if (len(args.positional) == 0) == (args.json_file is None): |
| 358 raise parser.error('Exactly one of args.positional and ' |
| 359 'args.json_file should be given.') |
| 360 |
| 361 if args.build_properties: |
| 362 build_properties = json.loads(args.build_properties) |
| 363 if ((not 'buildnumber' in build_properties) or |
| 364 (not 'buildername' in build_properties)): |
| 365 raise parser.error('Build number/builder name not specified.') |
| 366 build_number = build_properties['buildnumber'] |
| 367 builder_name = build_properties['buildername'] |
| 368 elif args.build_number and args.builder_name: |
| 369 build_number = args.build_number |
| 370 builder_name = args.builder_name |
| 371 |
| 372 if args.positional: |
| 373 if not len(args.positional) == 1: |
| 374 raise parser.error('More than 1 json file specified.') |
| 375 json_file = args.positional[0] |
| 376 elif args.json_file: |
| 377 json_file = args.json_file |
| 378 |
| 379 if not os.path.exists(json_file): |
| 380 raise IOError('--json-file %s not found.' % json_file) |
| 381 |
| 382 result_html_string = result_details(json_file, args.cs_base_url, |
| 383 args.bucket, args.server_url) |
| 384 result_details_link = upload_to_google_bucket( |
| 385 result_html_string.encode('UTF-8'), |
| 386 args.test_name, builder_name, |
| 387 build_number, args.bucket, |
| 388 args.server_url, args.content_type) |
| 389 |
| 390 if args.output_json: |
| 391 with open(json_file) as original_json_file: |
| 392 json_object = json.load(original_json_file) |
| 393 json_object['links'] = {'result_details': result_details_link} |
| 394 with open(args.output_json, 'w') as f: |
| 395 json.dump(json_object, f) |
336 else: | 396 else: |
337 raise IOError('--json-file %s not found.' % args.json_file) | 397 print result_details_link |
338 | |
339 | 398 |
340 if __name__ == '__main__': | 399 if __name__ == '__main__': |
341 sys.exit(main()) | 400 sys.exit(main()) |
OLD | NEW |