0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-24 00:17:37 +01:00
mongodb/buildscripts/yaml_key_value.py
Steve McClure b4b23946cd SERVER-90570: Enable formatting checks for buildscripts directory, excluding idl (#22254)
GitOrigin-RevId: 9d997a9f44cd43a8dec7c2a17fa2dbcd875e92f6
2024-05-16 22:07:36 +00:00

36 lines
976 B
Python
Executable File

#!/usr/bin/env python3
"""Utility to return YAML value from key in YAML file."""
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()