blob: b63d4bc2f093550123875ebbca82043b2a7768d1 [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(
14 "-d", "--directory",
15 default=script_dir,
16 help="Input directory")
Vishwanatha Subbannaccbdf672017-01-23 14:39:06 +053017 args = parser.parse_args()
18
19 # Default to the one that is in the current.
Brad Bishop9a6220c2017-02-08 13:21:31 -050020 yaml_dir = script_dir
Vishwanatha Subbannaccbdf672017-01-23 14:39:06 +053021 yaml_file = os.path.join(yaml_dir, 'led.yaml')
22
23 if args.directory:
24 yaml_dir = args.directory
25
26 if args.filename:
27 yaml_file = os.path.join(yaml_dir, args.filename)
28
29 with open(yaml_file, 'r') as f:
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053030 ifile = yaml.safe_load(f)
31
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053032 with open(os.path.join(script_dir, 'led-gen.hpp'), 'w') as ofile:
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053033 ofile.write('/* !!! WARNING: This is a GENERATED Code..')
34 ofile.write('Please do NOT Edit !!! */\n\n')
35
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053036 ofile.write('static const std::map<std::string,')
37 ofile.write(' std::set<phosphor::led::Layout::LedAction>>')
38 ofile.write(' systemLedMap = {\n\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053039 for group in ifile.iterkeys():
Vishwanatha Subbanna8a50a502017-01-20 18:42:21 +053040 # This section generates an std::map of LedGroupNames to std::set
41 # of LEDs containing the name and properties
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053042 ledset = ifile[group]
Brad Bishop9a6220c2017-02-08 13:21:31 -050043 ofile.write(
44 ' {\"' +
45 "/xyz/openbmc_project/ledmanager/groups/" +
46 group +
47 '\",{\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053048
49 for led_dict, list_dict in ledset.iteritems():
Vishwanatha Subbanna8a50a502017-01-20 18:42:21 +053050 # Need this to make sure the LED name is printed once
51 name_printed = False
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053052 for name, value in list_dict.iteritems():
Vishwanatha Subbanna8a50a502017-01-20 18:42:21 +053053 if group and led_dict and name:
54 if name_printed is False:
55 ofile.write(' {\"' + led_dict + '\",')
56 name_printed = True
57 if name == 'Action':
58 ofile.write('phosphor::led::Layout::')
59 ofile.write(str(value) + ',')
60 ofile.write('},\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053061 ofile.write(' }},\n')
62 ofile.write('};\n')