diff options
author | Jonathan Abrahams <jonathan@mongodb.com> | 2018-04-03 17:31:54 -0400 |
---|---|---|
committer | Jonathan Abrahams <jonathan@mongodb.com> | 2018-04-03 17:31:54 -0400 |
commit | 5fa649cf8e0b77020d680c554aef1d380605611b (patch) | |
tree | 19fa7f19d182f22d020486f3db888f90b65bca4b /buildscripts/yaml_key_value.py | |
parent | 2dc7d7530efb668c3817dc57bc4dcca36c0c4a07 (diff) | |
download | mongo-5fa649cf8e0b77020d680c554aef1d380605611b.tar.gz |
SERVER-33813 launch_evergreen_ec2_instance.sh should immediately fail if the call to aws_ec2.py is unsuccessful
Diffstat (limited to 'buildscripts/yaml_key_value.py')
-rwxr-xr-x | buildscripts/yaml_key_value.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/buildscripts/yaml_key_value.py b/buildscripts/yaml_key_value.py new file mode 100755 index 00000000000..353e87df7ea --- /dev/null +++ b/buildscripts/yaml_key_value.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +"""Utility to return YAML value from key in YAML file.""" + +from __future__ import print_function + +import optparse + +import yaml + + +def get_yaml_value(yaml_file, yaml_key): + """Return string value for 'yaml_key' from 'yaml_file.'""" + with open(yaml_file, "r") as ystream: + yaml_dict = yaml.safe_load(ystream) + return str(yaml_dict.get(yaml_key, "")) + + +def main(): + """Execute Main program.""" + + parser = optparse.OptionParser(description=__doc__) + parser.add_option("--yamlFile", dest="yaml_file", default=None, help="YAML file to read") + parser.add_option( + "--yamlKey", dest="yaml_key", default=None, help="Top level YAML key to provide the value") + + (options, _) = parser.parse_args() + if not options.yaml_file: + parser.error("Must specifiy '--yamlFile'") + if not options.yaml_key: + parser.error("Must specifiy '--yamlKey'") + + print(get_yaml_value(options.yaml_file, options.yaml_key)) + +if __name__ == "__main__": + main() |