From: Steve Baker Date: Thu, 22 Nov 2012 19:15:15 +0000 (+1300) Subject: Utility to convert JSON template files to YAML X-Git-Tag: 2014.1~1172 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=87e56e36167e810ca15be825df5a5e1537934f6b;p=openstack-build%2Fheat-build.git Utility to convert JSON template files to YAML Accepts a directory or file path. Change-Id: Icd51db5484283372a2b5fb8c681b0e88c7a9c1d5 --- diff --git a/tools/cfn-json2yaml b/tools/cfn-json2yaml new file mode 100644 index 00000000..19c68610 --- /dev/null +++ b/tools/cfn-json2yaml @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import sys +import os +import yaml +import json +import re +from heat.engine import format + +def main(): + path = sys.argv[1] + if os.path.isdir(path): + convert_directory(path) + elif os.path.isfile(path): + convert_file() + else: + print 'File or directory not valid: %s' % path + +def convert_file(path): + f = open(path, 'r') + print json2yaml(f) + +def convert_directory(dirpath): + for path in os.listdir(dirpath): + if not path.endswith('.template') and not path.endswith('.json'): + continue + yamlpath = re.sub('\..*$', '.yaml', path) + print 'Writing to %s' % yamlpath + f = open(os.path.join(dirpath, path), 'r') + out = open(os.path.join(dirpath, yamlpath), 'w') + yml = format.convert_json_to_yaml(f.read()) + out.write(yml) + out.close() + +if __name__ == '__main__': + main() \ No newline at end of file