summaryrefslogtreecommitdiffstats
path: root/control/gen-fan-zone-defs.py
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2018-02-28 16:23:11 -0600
committerMatthew Barth <msbarth@linux.ibm.com>2018-05-11 16:30:36 +0000
commit702c4a55a69915c3ab3506ee552acc5c21e06e2a (patch)
tree45bf5facb710cc3ee303c0bff5f64f329db1a753 /control/gen-fan-zone-defs.py
parent9af27f65bffea7a90d29f4c558a1c4c20616a069 (diff)
downloadphosphor-fan-presence-702c4a55a69915c3ab3506ee552acc5c21e06e2a.tar.gz
phosphor-fan-presence-702c4a55a69915c3ab3506ee552acc5c21e06e2a.zip
Move generated code template to file
In preparation of enhancing the generated code format, the template used has been externalized and will continue to be modified in future commits to parse & generate more efficiently. Tested: Generated code remains unchanged Resolves openbmc/phosphor-fan-presence#8 Change-Id: Ifbf718e8a22acb2f2f939bbdcc2e7fe041e9ed58 Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Diffstat (limited to 'control/gen-fan-zone-defs.py')
-rwxr-xr-xcontrol/gen-fan-zone-defs.py248
1 files changed, 14 insertions, 234 deletions
diff --git a/control/gen-fan-zone-defs.py b/control/gen-fan-zone-defs.py
index 43d98bc..644ce54 100755
--- a/control/gen-fan-zone-defs.py
+++ b/control/gen-fan-zone-defs.py
@@ -10,238 +10,7 @@ import sys
import yaml
from argparse import ArgumentParser
from mako.template import Template
-
-tmpl = '''\
-<%!
-def indent(str, depth):
- return ''.join(4*' '*depth+line for line in str.splitlines(True))
-%>\
-<%def name="genHandler(sig)" buffered="True">
-%if ('type' in sig['sparams']) and \
- (sig['sparams']['type'] is not None):
-${sig['signal']}<${sig['sparams']['type']}>(
-%else:
-${sig['signal']}(
-%endif
-%for spk in sig['sparams']['params']:
-${sig['sparams'][spk]},
-%endfor
-%if ('type' in sig['hparams']) and \
- (sig['hparams']['type'] is not None):
-handler::${sig['handler']}<${sig['hparams']['type']}>(
-%else:
-handler::${sig['handler']}(
-%endif
-%for i, hpk in enumerate(sig['hparams']['params']):
- %if (i+1) != len(sig['hparams']['params']):
- ${sig['hparams'][hpk]},
- %else:
- ${sig['hparams'][hpk]}
- %endif
-%endfor
-))
-</%def>\
-<%def name="genSSE(event)" buffered="True">
-Group{
-%for group in event['groups']:
-%for member in group['members']:
-{
- "${member['object']}",
- {"${member['interface']}",
- "${member['property']}"}
-},
-%endfor
-%endfor
-},
-std::vector<Action>{
-%for a in event['action']:
-%if len(a['parameters']) != 0:
-make_action(action::${a['name']}(
-%else:
-make_action(action::${a['name']}
-%endif
-%for i, p in enumerate(a['parameters']):
-%if (i+1) != len(a['parameters']):
- ${p},
-%else:
- ${p})
-%endif
-%endfor
-),
-%endfor
-},
-Timer{
- ${event['timer']['interval']},
- ${event['timer']['type']}
-},
-std::vector<Signal>{
-%for s in event['signals']:
- Signal{
- match::${s['match']}(
- %for i, mp in enumerate(s['mparams']):
- %if (i+1) != len(s['mparams']):
- "${mp}",
- %else:
- "${mp}"
- %endif
- %endfor
- ),
- make_handler(\
- ${indent(genHandler(sig=s), 3)}\
- )
- },
-%endfor
-}
-</%def>\
-/* This is a generated file. */
-#include "manager.hpp"
-#include "functor.hpp"
-#include "actions.hpp"
-#include "handlers.hpp"
-#include "preconditions.hpp"
-#include "matches.hpp"
-
-using namespace phosphor::fan::control;
-
-const unsigned int Manager::_powerOnDelay{${mgr_data['power_on_delay']}};
-
-const std::vector<ZoneGroup> Manager::_zoneLayouts
-{
-%for zone_group in zones:
- ZoneGroup{
- std::vector<Condition>{
- %for condition in zone_group['conditions']:
- Condition{
- "${condition['type']}",
- std::vector<ConditionProperty>{
- %for property in condition['properties']:
- ConditionProperty{
- "${property['property']}",
- "${property['interface']}",
- "${property['path']}",
- static_cast<${property['type']}>(${property['value']}),
- },
- %endfor
- },
- },
- %endfor
- },
- std::vector<ZoneDefinition>{
- %for zone in zone_group['zones']:
- ZoneDefinition{
- ${zone['num']},
- ${zone['full_speed']},
- ${zone['default_floor']},
- ${zone['increase_delay']},
- ${zone['decrease_interval']},
- std::vector<FanDefinition>{
- %for fan in zone['fans']:
- FanDefinition{
- "${fan['name']}",
- std::vector<std::string>{
- %for sensor in fan['sensors']:
- "${sensor}",
- %endfor
- },
- "${fan['target_interface']}"
- },
- %endfor
- },
- std::vector<SetSpeedEvent>{
- %for event in zone['events']:
- %if ('pc' in event) and \
- (event['pc'] is not None):
- SetSpeedEvent{
- Group{
- %for group in event['pc']['pcgrps']:
- %for member in group['members']:
- {
- "${member['object']}",
- {"${member['interface']}",
- "${member['property']}"}
- },
- %endfor
- %endfor
- },
- std::vector<Action>{
- %for i, a in enumerate(event['pc']['pcact']):
- %if len(a['params']) != 0:
- make_action(
- precondition::${a['name']}(
- %else:
- make_action(
- precondition::${a['name']}
- %endif
- %for p in a['params']:
- ${p['type']}${p['open']}
- %for j, v in enumerate(p['values']):
- %if (j+1) != len(p['values']):
- ${v['value']},
- %else:
- ${v['value']}
- %endif
- %endfor
- ${p['close']},
- %endfor
- %if (i+1) != len(event['pc']['pcact']):
- %if len(a['params']) != 0:
- )),
- %else:
- ),
- %endif
- %endif
- %endfor
- std::vector<SetSpeedEvent>{
- %for pcevt in event['pc']['pcevts']:
- SetSpeedEvent{\
- ${indent(genSSE(event=pcevt), 6)}\
- },
- %endfor
- %else:
- SetSpeedEvent{\
- ${indent(genSSE(event=event), 6)}
- %endif
- %if ('pc' in event) and (event['pc'] is not None):
- }
- %if len(event['pc']['pcact'][-1]['params']) != 0:
- )),
- %else:
- ),
- %endif
- },
- Timer{
- ${event['pc']['pctime']['interval']},
- ${event['pc']['pctime']['type']}
- },
- std::vector<Signal>{
- %for s in event['pc']['pcsigs']:
- Signal{
- match::${s['match']}(
- %for i, mp in enumerate(s['mparams']):
- %if (i+1) != len(s['mparams']):
- "${mp}",
- %else:
- "${mp}"
- %endif
- %endfor
- ),
- make_handler(\
- ${indent(genHandler(sig=s), 9)}\
- )
- },
- %endfor
- }
- %endif
- },
- %endfor
- }
- },
- %endfor
- }
- },
-%endfor
-};
-'''
+from mako.lookup import TemplateLookup
def convertToMap(listOfDict):
@@ -857,7 +626,18 @@ if __name__ == '__main__':
if manager_config.get('power_on_delay') is None:
manager_config['power_on_delay'] = 0
+ tmpls_dir = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ "templates")
output_file = os.path.join(args.output_dir, "fan_zone_defs.cpp")
+ if sys.version_info < (3, 0):
+ lkup = TemplateLookup(
+ directories=tmpls_dir.split(),
+ disable_unicode=True)
+ else:
+ lkup = TemplateLookup(
+ directories=tmpls_dir.split())
+ tmpl = lkup.get_template('fan_zone_defs.mako.cpp')
with open(output_file, 'w') as output:
- output.write(Template(tmpl).render(zones=zone_config,
- mgr_data=manager_config))
+ output.write(tmpl.render(zones=zone_config,
+ mgr_data=manager_config))
OpenPOWER on IntegriCloud