blob: 5392e9798ca6621c2c2fe9480a25d70ac28f9f65 [file] [log] [blame]
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +05301#!/usr/bin/env python
2import yaml
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +05303import os
Vishwanatha Subbannaccbdf672017-01-23 14:39:06 +05304import argparse
Vishwanatha Subbanna32bb6f82017-03-27 18:15:52 +05305from inflection import underscore
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +05306
7if __name__ == '__main__':
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +05308 script_dir = os.path.dirname(os.path.realpath(__file__))
Vishwanatha Subbannaccbdf672017-01-23 14:39:06 +05309 parser = argparse.ArgumentParser()
Brad Bishop9a6220c2017-02-08 13:21:31 -050010 parser.add_argument(
11 "-f", "--filename",
12 default='led.yaml',
13 help="Input File Name")
14 parser.add_argument(
Brad Bishop513f58e2017-02-08 13:25:17 -050015 "-i", "--input-dir",
16 dest='inputdir',
Brad Bishop9a6220c2017-02-08 13:21:31 -050017 default=script_dir,
18 help="Input directory")
Brad Bishop513f58e2017-02-08 13:25:17 -050019 parser.add_argument(
20 '-o', '--output-dir',
21 dest='outputdir',
22 default='.',
23 help='Output directory.')
24
Vishwanatha Subbannaccbdf672017-01-23 14:39:06 +053025 args = parser.parse_args()
26
27 # Default to the one that is in the current.
Brad Bishop9a6220c2017-02-08 13:21:31 -050028 yaml_dir = script_dir
Vishwanatha Subbannaccbdf672017-01-23 14:39:06 +053029 yaml_file = os.path.join(yaml_dir, 'led.yaml')
30
Brad Bishop513f58e2017-02-08 13:25:17 -050031 if args.inputdir:
32 yaml_dir = args.inputdir
Vishwanatha Subbannaccbdf672017-01-23 14:39:06 +053033
34 if args.filename:
35 yaml_file = os.path.join(yaml_dir, args.filename)
36
37 with open(yaml_file, 'r') as f:
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053038 ifile = yaml.safe_load(f)
39
Brad Bishop513f58e2017-02-08 13:25:17 -050040 with open(os.path.join(args.outputdir, 'led-gen.hpp'), 'w') as ofile:
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053041 ofile.write('/* !!! WARNING: This is a GENERATED Code..')
42 ofile.write('Please do NOT Edit !!! */\n\n')
43
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053044 ofile.write('static const std::map<std::string,')
45 ofile.write(' std::set<phosphor::led::Layout::LedAction>>')
46 ofile.write(' systemLedMap = {\n\n')
Patrick Williamsd27c68f2017-05-31 17:12:37 -050047 for group in ifile.keys():
Vishwanatha Subbanna8a50a502017-01-20 18:42:21 +053048 # This section generates an std::map of LedGroupNames to std::set
49 # of LEDs containing the name and properties
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053050 ledset = ifile[group]
Brad Bishop9a6220c2017-02-08 13:21:31 -050051 ofile.write(
52 ' {\"' +
Vishwanatha Subbannaa1c7f6a2017-02-02 14:51:42 +053053 "/xyz/openbmc_project/led/groups/" +
Vishwanatha Subbanna32bb6f82017-03-27 18:15:52 +053054 underscore(group) +
Brad Bishop9a6220c2017-02-08 13:21:31 -050055 '\",{\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053056
Vishwanatha Subbannad53de6f2017-03-30 11:21:37 +053057 # Some LED groups could be empty
58 if not ledset:
59 ofile.write(' }},\n')
60 continue
61
Patrick Williamsd27c68f2017-05-31 17:12:37 -050062 for led_dict, list_dict in ledset.items():
63 ofile.write(' {\"' + underscore(led_dict) + '\",')
64 ofile.write('phosphor::led::Layout::' +
65 str(list_dict.get('Action', 'Off')) + ',')
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +053066 ofile.write(str(list_dict.get('DutyOn', 50)) + ',')
Patrick Williamsd27c68f2017-05-31 17:12:37 -050067 ofile.write(str(list_dict.get('Period', 0)) + ',')
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +053068 priority = str(list_dict.get('Priority', 'Blink'))
69 ofile.write('phosphor::led::Layout::' + priority + ',')
Vishwanatha Subbanna8a50a502017-01-20 18:42:21 +053070 ofile.write('},\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053071 ofile.write(' }},\n')
72 ofile.write('};\n')