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..6ae79a85448de6c8c131be60b97cc0756f8a7e2f 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,80 @@ def main(): |
'whether to download the file, or view in browser.'), |
default='text/html', |
choices=['text/html', 'application/octet-stream']) |
+ 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.
|
+ '-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) |
+ # 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.
|
+ 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.
|
+ 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.
|
+ raise Exception('Error in build properties arguments.') |
+ |
+ # args.build_number and args.builder_name has to be be given together |
+ # or not given at all. |
mikecase (-- gone --)
2017/04/18 15:39:28
nit: I would move these commnets inside the Except
|
+ 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
|
+ raise Exception('Build number/builder name not specified.') |
+ |
+ # 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.
|
+ 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.
|
+ raise Exception('Error in json file arguments.') |
+ |
+ 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'] |
+ |
+ if args.build_number and args.builder_name: |
jbudorick
2017/04/18 15:59:25
elif
BigBossZhiling
2017/04/18 17:52:29
Done.
|
+ 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] |
+ |
+ if args.json_file: |
jbudorick
2017/04/18 15:59:25
elif
BigBossZhiling
2017/04/18 17:52:28
Done.
|
+ 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()) |
+ json_object['links'] = {'result_details': result_details_link} |
+ with open(args.output_json, 'w') as f: |
+ f.write(str(json_object)) |
+ else: |
+ print result_details_link |
if __name__ == '__main__': |
sys.exit(main()) |