From d08dbe27c2de978b0c4a65c678e678f3260470c0 Mon Sep 17 00:00:00 2001 From: Matt Spinler Date: Tue, 11 Apr 2017 13:52:54 -0500 Subject: Fan control: Python script framework The basics of a python script that will generate the fan zone data structures for the fan control code from zone and fan yaml files using a mako template. Change-Id: I1d92dc55c2b6dd986e5aaae0d3440ef85cbe79c0 Signed-off-by: Matt Spinler --- control/gen-fan-zone-defs.py | 78 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 control/gen-fan-zone-defs.py (limited to 'control/gen-fan-zone-defs.py') diff --git a/control/gen-fan-zone-defs.py b/control/gen-fan-zone-defs.py new file mode 100755 index 0000000..806b484 --- /dev/null +++ b/control/gen-fan-zone-defs.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python + +""" +This script reads in fan definition and zone definition YAML +files and generates a set of structures for use by the fan control code. +""" + +import os +import sys +import yaml +from argparse import ArgumentParser +from mako.template import Template + +#Note: Condition is a TODO +tmpl = '''/* This is a generated file. */ +#include "manager.hpp" + +using namespace phosphor::fan::control; + +const std::vector Manager::_zoneLayouts +{ +%for zone_group in zones: + std::make_tuple( + std::vector{}, + std::vector{ + %for zone in zone_group['zones']: + std::make_tuple(${zone['num']}, + ${zone['initial_speed']}, + std::vector{ + %for fan in zone['fans']: + std::make_tuple("${fan['name']}", + std::vector{ + %for sensor in fan['sensors']: + "${sensor}", + %endfor + } + ), + %endfor + } + ), + %endfor + } + ), +%endfor +}; +''' + +if __name__ == '__main__': + parser = ArgumentParser( + description="Phosphor fan zone definition parser") + + parser.add_argument('-z', '--zone_yaml', dest='zone_yaml', + default="example/zones.yaml", + help='fan zone definitional yaml') + parser.add_argument('-f', '--fan_yaml', dest='fan_yaml', + default="example/fans.yaml", + help='fan definitional yaml') + parser.add_argument('-o', '--output_dir', dest='output_dir', + default=".", + help='output directory') + args = parser.parse_args() + + if not args.zone_yaml or not args.fan_yaml: + parser.print_usage() + sys.exit(-1) + + with open(args.zone_yaml, 'r') as zone_input: + zone_data = yaml.safe_load(zone_input) or {} + + with open(args.fan_yaml, 'r') as fan_input: + fan_data = yaml.safe_load(fan_input) or {} + + #Fill in with using zone_data and fan_data with next commit + zone_data = [] + + output_file = os.path.join(args.output_dir, "fan_zone_defs.cpp") + with open(output_file, 'w') as output: + output.write(Template(tmpl).render(zones=zone_data)) -- cgit v1.2.1