From db440d4cfe3fa2cba5621342eb58b9928af6912a Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Mon, 17 Apr 2017 15:49:37 -0500 Subject: Base monitoring generation script Monitoring source generation script with mako template to generate an empty set of events. The events will be parsed and added under openbmc/openbmc#1493 Resolves openbmc/openbmc#1343 Change-Id: I40225f070212af36f410d99bc7ead95961e70997 Signed-off-by: Matthew Barth --- configure.ac | 3 +++ src/Makefile.am | 6 ++++++ src/gen-group-defs.py | 33 +++++++++++++++++++++++++++++++++ src/generated.mako.cpp | 25 +++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100755 src/gen-group-defs.py create mode 100644 src/generated.mako.cpp diff --git a/configure.ac b/configure.ac index 816882c..38e8d79 100644 --- a/configure.ac +++ b/configure.ac @@ -12,6 +12,9 @@ AM_PROG_AR AC_PROG_INSTALL AC_PROG_MAKE_SET AC_PROG_AWK +AM_PATH_PYTHON([2.7], + [AC_SUBST([PYTHON], [echo "$PYTHON"])], + [AC_MSG_ERROR([Could not find python-2.7 installed...python-2.7 is required])]) # Checks for libraries. PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus],, AC_MSG_ERROR(["Requires sdbusplus package."])) diff --git a/src/Makefile.am b/src/Makefile.am index 8c57553..233b610 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,3 +14,9 @@ phosphor_dbus_monitor_LDADD = \ phosphor_dbus_monitor_CXXFLAGS = \ $(SDBUSPLUS_CFLAGS) \ $(PHOSPHOR_LOGGING_CFLAGS) + +BUILT_SOURCES = generated.cpp +CLEANFILES = generated.cpp + +generated.cpp: + $(AM_V_GEN)$(PYTHON) ${srcdir}/gen-group-defs.py -y ${srcdir}/example/monitoring_defs.yaml -o ${builddir} diff --git a/src/gen-group-defs.py b/src/gen-group-defs.py new file mode 100755 index 0000000..56ac00f --- /dev/null +++ b/src/gen-group-defs.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +import os +import sys +import yaml +from argparse import ArgumentParser +from mako.template import Template + + +def generate(yaml_file, output_file): + with open(yaml_file, 'r') as yaml_input: + yaml_data = yaml.safe_load(yaml_input) or {} + + with open(output_file, 'w') as gen_out: + gen_out.write(Template(filename='generated.mako.cpp').render( + events=yaml_data)) + + +if __name__ == '__main__': + parser = ArgumentParser() + # Groups of items and how they should be monitored yaml file + parser.add_argument( + "-y", "--yaml", dest="input_yaml", + default="example/monitoring_defs.yaml", + help="Input item monitoring definition yaml to parse") + parser.add_argument( + "-o", "--outdir", dest="output_dir", + default=os.path.abspath('.'), + help="Output directory for source files generated") + args = parser.parse_args(sys.argv[1:]) + + yaml_file = os.path.abspath(args.input_yaml) + generate(yaml_file, os.path.join(args.output_dir, "generated.cpp")) diff --git a/src/generated.mako.cpp b/src/generated.mako.cpp new file mode 100644 index 0000000..a8f6d60 --- /dev/null +++ b/src/generated.mako.cpp @@ -0,0 +1,25 @@ +## This file is a template, the comment below is emitted into the generated file +/* This is an auto generated file. Do not edit. */ +#include "data_types.hpp" +#include "monitor.hpp" +#include "functor.hpp" +#include "conditions.hpp" +#include "actions.hpp" + +namespace phosphor +{ +namespace dbus +{ +namespace monitoring +{ + +const std::vector>, + std::vector>> + Monitor::events +{ + +}; + +} // namespace monitoring +} // namespace dbus +} // namespace phosphor -- cgit v1.2.1