Use YAML for UCD definitions

Use a Python script to generate the UCD power sequencer information
needed for the pseq-monitor application.

Change-Id: I51f4b61bb4f22705584b73ba599b517780fa9adc
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/power-sequencer/Makefile.am b/power-sequencer/Makefile.am
index a13348b..d9f0324 100644
--- a/power-sequencer/Makefile.am
+++ b/power-sequencer/Makefile.am
@@ -9,7 +9,9 @@
 	main.cpp \
 	pgood_monitor.cpp \
 	runtime_monitor.cpp \
-	ucd90160.cpp \
+	ucd90160.cpp
+
+nodist_pseq_monitor_SOURCES = \
 	ucd90160_defs.cpp
 
 pseq_monitor_LDADD = \
@@ -24,3 +26,8 @@
 	${PHOSPHOR_DBUS_INTERFACES_CFLAGS} \
 	$(SDBUSPLUS_CFLAGS) \
 	$(SDEVENTPLUS_CFLAGS)
+
+BUILT_SOURCES = ucd90160_defs.cpp
+
+ucd90160_defs.cpp: ${srcdir}/gen-ucd90160-defs.py templates/ucd90160_defs.mako.cpp
+	$(AM_V_GEN)$(GEN_UCD90160_DEFS)
diff --git a/power-sequencer/example/ucd90160.yaml b/power-sequencer/example/ucd90160.yaml
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/power-sequencer/example/ucd90160.yaml
diff --git a/power-sequencer/gen-ucd90160-defs.py b/power-sequencer/gen-ucd90160-defs.py
new file mode 100755
index 0000000..1eb0d06
--- /dev/null
+++ b/power-sequencer/gen-ucd90160-defs.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+import os
+import yaml
+from argparse import ArgumentParser
+from mako.template import Template
+from mako.lookup import TemplateLookup
+
+if __name__ == '__main__':
+    parser = ArgumentParser(
+        description="Power sequencer UCD90160 definition parser")
+
+    parser.add_argument('-i', '--input_yaml', dest='input_yaml',
+                        default="example/ucd90160.yaml",
+                        help='UCD90160 definitions YAML')
+
+    parser.add_argument('-o', '--output_dir', dest='output_dir',
+                        default=".",
+                        help='output directory')
+
+    args = parser.parse_args()
+
+    if not args.input_yaml or not args.output_dir:
+        parser.print_usage()
+        sys.exit(1)
+
+    with open(args.input_yaml, 'r') as ucd90160_input:
+        ucd90160_data = yaml.safe_load(ucd90160_input) or {}
+
+    templates_dir = os.path.join(
+            os.path.dirname(os.path.realpath(__file__)),
+            "templates")
+
+    output_file = os.path.join(args.output_dir, "ucd90160_defs.cpp")
+
+    mylookup = TemplateLookup(
+            directories=templates_dir.split())
+    mytemplate = mylookup.get_template('ucd90160_defs.mako.cpp')
+
+    with open(output_file, 'w') as output:
+        output.write(mytemplate.render(ucd90160s=ucd90160_data))
diff --git a/power-sequencer/ucd90160_defs.cpp b/power-sequencer/templates/ucd90160_defs.mako.cpp
similarity index 83%
rename from power-sequencer/ucd90160_defs.cpp
rename to power-sequencer/templates/ucd90160_defs.mako.cpp
index 531a989..3aea9a6 100644
--- a/power-sequencer/ucd90160_defs.cpp
+++ b/power-sequencer/templates/ucd90160_defs.mako.cpp
@@ -1,21 +1,6 @@
-/**
- * Copyright © 2017 IBM Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "ucd90160.hpp"
+/* This is a generated file. */
 
-// Separated out to facilitate possible future generation of file.
+#include "ucd90160.hpp"
 
 namespace witherspoon
 {