Created
October 1, 2017 21:52
-
-
Save digitalist/bcd3e59987ebc1bce281e4aac2848130 to your computer and use it in GitHub Desktop.
return yaml values by filename + yaml key/path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#pip install dpath | |
def get_yaml_config(path: str): | |
import yaml | |
with open(path, 'r') as ymlfile: | |
cfg = yaml.load(ymlfile) | |
return cfg | |
def get_config(file_path, yaml_path): | |
""" | |
passing yaml config options to bash | |
:param file_path: path to yaml file | |
:param yaml_path: path inside yaml file | |
""" | |
import dpath.util | |
config = get_yaml_config(file_path) | |
print(dpath.util.get(config, yaml_path)) | |
if __name__ == '__main__': | |
import sys | |
# usage: | |
## !/bin/bash | |
## ! config | |
## DB_USER =$(gc.py config.yml "path/to/yaml/key") | |
get_config(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment