blob: af81d62738924ebe99e2194797b81d8cb5537456 [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 Subbannab21fda72016-10-17 17:46:37 +05305
6if __name__ == '__main__':
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +05307 script_dir = os.path.dirname(os.path.realpath(__file__))
Vishwanatha Subbannaccbdf672017-01-23 14:39:06 +05308 parser = argparse.ArgumentParser()
Brad Bishop9a6220c2017-02-08 13:21:31 -05009 parser.add_argument(
10 "-f", "--filename",
11 default='led.yaml',
12 help="Input File Name")
13 parser.add_argument(
Brad Bishop513f58e2017-02-08 13:25:17 -050014 "-i", "--input-dir",
15 dest='inputdir',
Brad Bishop9a6220c2017-02-08 13:21:31 -050016 default=script_dir,
17 help="Input directory")
Brad Bishop513f58e2017-02-08 13:25:17 -050018 parser.add_argument(
19 '-o', '--output-dir',
20 dest='outputdir',
21 default='.',
22 help='Output directory.')
23
Vishwanatha Subbannaccbdf672017-01-23 14:39:06 +053024 args = parser.parse_args()
25
26 # Default to the one that is in the current.
Brad Bishop9a6220c2017-02-08 13:21:31 -050027 yaml_dir = script_dir
Vishwanatha Subbannaccbdf672017-01-23 14:39:06 +053028 yaml_file = os.path.join(yaml_dir, 'led.yaml')
29
Brad Bishop513f58e2017-02-08 13:25:17 -050030 if args.inputdir:
31 yaml_dir = args.inputdir
Vishwanatha Subbannaccbdf672017-01-23 14:39:06 +053032
33 if args.filename:
34 yaml_file = os.path.join(yaml_dir, args.filename)
35
36 with open(yaml_file, 'r') as f:
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053037 ifile = yaml.safe_load(f)
38
Brad Bishop513f58e2017-02-08 13:25:17 -050039 with open(os.path.join(args.outputdir, 'led-gen.hpp'), 'w') as ofile:
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053040 ofile.write('/* !!! WARNING: This is a GENERATED Code..')
41 ofile.write('Please do NOT Edit !!! */\n\n')
42
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053043 ofile.write('static const std::map<std::string,')
44 ofile.write(' std::set<phosphor::led::Layout::LedAction>>')
45 ofile.write(' systemLedMap = {\n\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053046 for group in ifile.iterkeys():
Vishwanatha Subbanna8a50a502017-01-20 18:42:21 +053047 # This section generates an std::map of LedGroupNames to std::set
48 # of LEDs containing the name and properties
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053049 ledset = ifile[group]
Brad Bishop9a6220c2017-02-08 13:21:31 -050050 ofile.write(
51 ' {\"' +
Vishwanatha Subbannaa1c7f6a2017-02-02 14:51:42 +053052 "/xyz/openbmc_project/led/groups/" +
Brad Bishop9a6220c2017-02-08 13:21:31 -050053 group +
54 '\",{\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053055
56 for led_dict, list_dict in ledset.iteritems():
Vishwanatha Subbanna8a50a502017-01-20 18:42:21 +053057 # Need this to make sure the LED name is printed once
58 name_printed = False
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053059 for name, value in list_dict.iteritems():
Vishwanatha Subbanna8a50a502017-01-20 18:42:21 +053060 if group and led_dict and name:
61 if name_printed is False:
62 ofile.write(' {\"' + led_dict + '\",')
63 name_printed = True
64 if name == 'Action':
65 ofile.write('phosphor::led::Layout::')
66 ofile.write(str(value) + ',')
67 ofile.write('},\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053068 ofile.write(' }},\n')
69 ofile.write('};\n')