Chromium Code Reviews| Index: build/android/pylib/results/presentation/test_results_presentation.py |
| diff --git a/build/android/pylib/results/presentation/test_results_presentation.py b/build/android/pylib/results/presentation/test_results_presentation.py |
| index 3324784a4040100e77574208024121954943a889..a16170a3a1b98d63939c5bd211ddecf37cde5feb 100755 |
| --- a/build/android/pylib/results/presentation/test_results_presentation.py |
| +++ b/build/android/pylib/results/presentation/test_results_presentation.py |
| @@ -308,12 +308,12 @@ def upload_to_google_bucket(html, test_name, builder_name, build_number, |
| def main(): |
| parser = argparse.ArgumentParser() |
| - parser.add_argument('--json-file', help='Path of json file.', required=True) |
| + parser.add_argument('--json-file', help='Path of json file.') |
| parser.add_argument('--cs-base-url', help='Base url for code search.', |
| default='http://cs.chromium.org') |
| parser.add_argument('--bucket', help='Google storage bucket.', required=True) |
| - parser.add_argument('--builder-name', help='Builder name.', required=True) |
| - parser.add_argument('--build-number', help='Build number.', required=True) |
| + parser.add_argument('--builder-name', help='Builder name.') |
| + parser.add_argument('--build-number', help='Build number.') |
| parser.add_argument('--test-name', help='The name of the test.', |
| required=True) |
| parser.add_argument('--server-url', help='The url of the server.', |
| @@ -324,18 +324,77 @@ def main(): |
| 'whether to download the file, or view in browser.'), |
| default='text/html', |
| choices=['text/html', 'application/octet-stream']) |
| + parser.add_argument( |
| + '-o', '--output-json', |
| + help='(Swarming Merge Script API)' |
| + ' Output JSON file to create.') |
| + parser.add_argument( |
| + '--build-properties', |
| + help='(Swarming Merge Script API) ' |
| + 'Build property JSON file provided by recipes.') |
| + parser.add_argument( |
| + '--summary-json', |
| + help='(Swarming Merge Script API)' |
| + ' Summary of shard state running on swarming.' |
| + ' (Output of the swarming.py collect' |
| + ' --task-summary-json=XXX command.)') |
| + parser.add_argument( |
| + 'positional', nargs='*', |
| + help='output.json from shards.') |
| args = parser.parse_args() |
| - if os.path.exists(args.json_file): |
| - result_html_string = result_details(args.json_file, args.cs_base_url, |
| - args.bucket, args.server_url) |
| - print upload_to_google_bucket(result_html_string.encode('UTF-8'), |
| - args.test_name, args.builder_name, |
| - args.build_number, args.bucket, |
| - args.server_url, args.content_type) |
| - else: |
| - raise IOError('--json-file %s not found.' % args.json_file) |
| + if ((args.build_properties is None) == |
| + (args.build_number is None or args.builder_name is None)): |
| + raise Exception('Exactly one of build_perperties or ' |
|
jbudorick
2017/04/18 23:11:34
nit: switch all of these exceptions you're raising
BigBossZhiling
2017/04/18 23:35:54
Done.
|
| + '(build_number or builder_names) should be given.') |
| + |
| + if (args.build_number is None) != (args.builder_name is None): |
| + raise Exception('args.build_number and args.builder_name ' |
| + 'has to be be given together' |
| + 'or not given at all.') |
| + |
| + if (len(args.positional) == 0) == (args.json_file is None): |
| + raise Exception('Exactly one of args.positional and ' |
| + 'args.json_file should be given.') |
| + |
| + if args.build_properties: |
| + build_properties = json.loads(args.build_properties) |
| + if ((not 'buildnumber' in build_properties) or |
| + (not 'buildername' in build_properties)): |
| + raise Exception('Build number/builder name not specified.') |
| + build_number = build_properties['buildnumber'] |
| + builder_name = build_properties['buildername'] |
| + elif args.build_number and args.builder_name: |
| + build_number = args.build_number |
| + builder_name = args.builder_name |
| + |
| + if args.positional: |
| + if not len(args.positional) == 1: |
| + raise Exception('More than 1 json file specified.') |
| + json_file = args.positional[0] |
| + elif args.json_file: |
| + json_file = args.json_file |
| + |
| + if not os.path.exists(json_file): |
| + raise IOError('--json-file %s not found.' % json_file) |
| + |
| + result_html_string = result_details(json_file, args.cs_base_url, |
| + args.bucket, args.server_url) |
| + result_details_link = upload_to_google_bucket( |
| + result_html_string.encode('UTF-8'), |
| + args.test_name, builder_name, |
| + build_number, args.bucket, |
| + args.server_url, args.content_type) |
| + |
| + if args.output_json: |
| + with open(json_file) as original_json_file: |
| + json_object = json.loads(original_json_file.read()) |
|
jbudorick
2017/04/18 23:11:34
nit: json.load(original_json_file)
BigBossZhiling
2017/04/18 23:35:54
It has to be json.loads(<string>). Otherwise it wi
jbudorick
2017/04/19 00:05:50
json.load and json.loads are two different functio
|
| + json_object['links'] = {'result_details': result_details_link} |
| + with open(args.output_json, 'w') as f: |
| + f.write(str(json_object)) |
|
jbudorick
2017/04/18 23:11:34
json.dump(json_object, f)
BigBossZhiling
2017/04/18 23:35:54
Done.
|
| + else: |
| + print result_details_link |
| if __name__ == '__main__': |
| sys.exit(main()) |