Skip to content

Instantly share code, notes, and snippets.

@geramirez
Created March 25, 2016 17:09
Show Gist options
  • Save geramirez/66a6fda7899c5395d86f to your computer and use it in GitHub Desktop.
Save geramirez/66a6fda7899c5395d86f to your computer and use it in GitHub Desktop.
transformation script
import glob
import yaml
def read_yaml(filename):
""" Read yaml file """
with open(filename, 'r') as data:
return yaml.load(data)
def write_yaml(filename, data):
""" Write data """
with open(filename, 'w') as outfile:
outfile.write(yaml.dump(data, default_flow_style=False))
def convert_dict(dictionary):
text = ''
for key in sorted(dictionary):
text += "#### {0} \n{1} \n".format(key, dictionary[key])
return text
def file_loop():
""" Loop though files """
for component in glob.iglob("*/component.yaml"):
data = read_yaml(component)
for satisfies in data['satisfies']:
if isinstance(satisfies['narrative'], dict):
satisfies['narrative'] = convert_dict(satisfies['narrative'])
write_yaml(component, data)
if __name__ == "__main__":
file_loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment