diff options
author | Deepak Kodihalli <dkodihal@in.ibm.com> | 2017-03-02 04:40:27 -0600 |
---|---|---|
committer | Deepak Kodihalli <dkodihal@in.ibm.com> | 2017-03-15 09:20:15 -0500 |
commit | 5650b3998e1f229ada9d6da557830de7fa623469 (patch) | |
tree | ba1035e742864765dc3b9161be76177617731a1a /callouts | |
parent | 64007ac6ebd88ab2be9b4c0428b289a1c4b06047 (diff) | |
download | phosphor-logging-5650b3998e1f229ada9d6da557830de7fa623469.tar.gz phosphor-logging-5650b3998e1f229ada9d6da557830de7fa623469.zip |
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>
Diffstat (limited to 'callouts')
-rw-r--r-- | callouts/callouts-gen.mako.hpp | 23 | ||||
-rwxr-xr-x | callouts/callouts.py | 32 |
2 files changed, 55 insertions, 0 deletions
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() |