blob: a8d148a71786435f83795fc36df1aaa8d1598a32 [file] [log] [blame]
Marri Devender Raoa62bacc2017-06-04 23:40:16 -05001#!/usr/bin/env python
2
3import os
4import sys
5import yaml
6import argparse
7from mako.template import Template
8
9
10def generate_cpp(inventory_yaml, output_dir):
Vernon Mauery5f7ac712019-04-30 11:19:08 -070011 with open(inventory_yaml, 'r') as f:
Marri Devender Raoa62bacc2017-06-04 23:40:16 -050012 ifile = yaml.safe_load(f)
13 if not isinstance(ifile, dict):
14 ifile = {}
15
16 # Render the mako template
17
18 t = Template(filename=os.path.join(
19 script_dir,
20 "readfru.mako.cpp"))
21
22 output_hpp = os.path.join(output_dir, "fru-read-gen.cpp")
23 with open(output_hpp, 'w') as fd:
24 fd.write(t.render(fruDict=ifile))
25
26
27def main():
28
29 valid_commands = {
30 'generate-cpp': generate_cpp
31 }
32 parser = argparse.ArgumentParser(
33 description="IPMI FRU map code generator")
34
35 parser.add_argument(
36 '-i', '--inventory_yaml', dest='inventory_yaml',
37 default='example.yaml', help='input inventory yaml file to parse')
38
39 parser.add_argument(
40 "-o", "--output-dir", dest="outputdir",
41 default=".",
42 help="output directory")
43
44 parser.add_argument(
45 'command', metavar='COMMAND', type=str,
46 choices=valid_commands.keys(),
47 help='Command to run.')
48
49 args = parser.parse_args()
50
Vernon Mauery5f7ac712019-04-30 11:19:08 -070051 if (not (os.path.isfile(args.inventory_yaml))):
Marri Devender Raoa62bacc2017-06-04 23:40:16 -050052 sys.exit("Can not find input yaml file " + args.inventory_yaml)
53
54 function = valid_commands[args.command]
55 function(args.inventory_yaml, args.outputdir)
56
57if __name__ == '__main__':
58 script_dir = os.path.dirname(os.path.realpath(__file__))
59 main()