callouts: add script to generate callout mappings
Add a script that can generate callout mappings. The script needs an
input YAML to denote callout mappings. Add an example YAML.
Change-Id: I7b49fe4c586bf7abfed2865cfd776de4d5745ef5
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/callouts/callouts-gen.mako.hpp b/callouts/callouts-gen.mako.hpp
new file mode 100644
index 0000000..7d28a3a
--- /dev/null
+++ b/callouts/callouts-gen.mako.hpp
@@ -0,0 +1,23 @@
+## Note that this file is not auto generated, it is what generates the
+## callouts-gen.hpp file
+// This file was autogenerated. Do not edit!
+// See callouts-gen.py for more details
+#pragma once
+
+#include <string>
+#include <tuple>
+
+namespace phosphor
+{
+namespace logging
+{
+
+constexpr auto callouts =
+{
+% for key, value in sorted(calloutsMap.iteritems()):
+ std::make_tuple("${key}", "${value}"),
+% endfor
+};
+
+} // namespace logging
+} // namespace phosphor
diff --git a/callouts/callouts.py b/callouts/callouts.py
new file mode 100755
index 0000000..c9a5024
--- /dev/null
+++ b/callouts/callouts.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+import os
+import yaml
+from mako.template import Template
+import argparse
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ description="Callout code generator")
+
+ parser.add_argument(
+ '-i', '--callouts_yaml', dest='callouts_yaml',
+ default='callouts-example.yaml', help='input callouts yaml')
+ args = parser.parse_args()
+
+ with open(os.path.join(script_dir, args.callouts_yaml), 'r') as fd:
+ calloutsMap = yaml.safe_load(fd)
+
+ # Render the mako template
+ template = os.path.join(script_dir, 'callouts-gen.mako.hpp')
+ t = Template(filename=template)
+ with open('callouts-gen.hpp', 'w') as fd:
+ fd.write(
+ t.render(
+ calloutsMap=calloutsMap))
+
+
+if __name__ == '__main__':
+ script_dir = os.path.dirname(os.path.realpath(__file__))
+ main()