Skip to content

Instantly share code, notes, and snippets.

@digitalist
Created October 1, 2017 21:52
Show Gist options
  • Save digitalist/bcd3e59987ebc1bce281e4aac2848130 to your computer and use it in GitHub Desktop.
Save digitalist/bcd3e59987ebc1bce281e4aac2848130 to your computer and use it in GitHub Desktop.
return yaml values by filename + yaml key/path
#!/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