summaryrefslogtreecommitdiffstats
path: root/repackage/bin/yamltojson
diff options
context:
space:
mode:
authorTony Hansen <tony@att.com>2017-09-18 14:29:30 +0000
committerTony Hansen <tony@att.com>2017-09-18 14:31:40 +0000
commitaeb3db3f70a2465f7cad3a4473a21d603d70b8a5 (patch)
tree742910567b9d864bd772c6af7a63a4dc0f264b2b /repackage/bin/yamltojson
parent66613f4112b0e68f30430944b7d94e6ca14b1f62 (diff)
add tools to support PGaaS integration
add check-blueprint-vs-input, repackage and yamltojson Change-Id: Ibc82e37a3143f8f1567ebd829cfda53001d3ea78 Signed-off-by: Tony Hansen <tony@att.com> Issue: DCAEGEN2-49 Signed-off-by: Tony Hansen <tony@att.com>
Diffstat (limited to 'repackage/bin/yamltojson')
-rwxr-xr-xrepackage/bin/yamltojson39
1 files changed, 39 insertions, 0 deletions
diff --git a/repackage/bin/yamltojson b/repackage/bin/yamltojson
new file mode 100755
index 0000000..0dc85fc
--- /dev/null
+++ b/repackage/bin/yamltojson
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+# -*- indent-tabs-mode: nil -*- vi: set expandtab:
+
+"""
+NAME
+ yamltojson - convert a yaml file to a json file
+
+SYNOPSIS
+ yamltojson file.yaml ...
+
+DESCRIPTION
+ Read in a yaml file (whose name must end with ".yaml") and create cor‐
+ responding json files, whose names will end with ".json".
+"""
+
+import sys, re, yaml
+try:
+ import simplejson as json
+except:
+ import json
+
+def die(msg):
+ """ generate a FATAL message to stdout and exit """
+ print("%s:FATAL:%s" % (date(), msg))
+ sys.exit(2)
+
+for fname in sys.argv[1:]:
+ if fname.endswith(".yaml"):
+ y = None
+ with open(fname, "r") as fd:
+ try:
+ contents = fd.read()
+ contents = re.sub("^\t+", " ", contents, flags=re.M)
+ y = yaml.safe_load(contents)
+ except:
+ die("Invalid yaml in '%s'" % fname)
+ jsonfname = fname[:-5] + ".json"
+ with open(jsonfname, "w") as fd:
+ json.dump(y, fd, indent=4, sort_keys=True)