blob: 8ecfb949d8ba6ef20f61888afd190093a30e8c0e [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()
9 parser.add_argument("-f","--filename", default='led.yaml', help="Input File Name")
10 parser.add_argument("-d","--directory", default=script_dir, help="Input directory")
11 args = parser.parse_args()
12
13 # Default to the one that is in the current.
14 yaml_dir = script_dir;
15 yaml_file = os.path.join(yaml_dir, 'led.yaml')
16
17 if args.directory:
18 yaml_dir = args.directory
19
20 if args.filename:
21 yaml_file = os.path.join(yaml_dir, args.filename)
22
23 with open(yaml_file, 'r') as f:
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053024 ifile = yaml.safe_load(f)
25
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053026 with open(os.path.join(script_dir, 'led-gen.hpp'), 'w') as ofile:
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053027 ofile.write('/* !!! WARNING: This is a GENERATED Code..')
28 ofile.write('Please do NOT Edit !!! */\n\n')
29
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053030 ofile.write('static const std::map<std::string,')
31 ofile.write(' std::set<phosphor::led::Layout::LedAction>>')
32 ofile.write(' systemLedMap = {\n\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053033 for group in ifile.iterkeys():
Vishwanatha Subbanna8a50a502017-01-20 18:42:21 +053034 # This section generates an std::map of LedGroupNames to std::set
35 # of LEDs containing the name and properties
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053036 ledset = ifile[group]
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053037 ofile.write(' {\"' + "/xyz/openbmc_project/ledmanager/groups/" + group + '\",{\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053038
39 for led_dict, list_dict in ledset.iteritems():
Vishwanatha Subbanna8a50a502017-01-20 18:42:21 +053040 # Need this to make sure the LED name is printed once
41 name_printed = False
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053042 for name, value in list_dict.iteritems():
Vishwanatha Subbanna8a50a502017-01-20 18:42:21 +053043 if group and led_dict and name:
44 if name_printed is False:
45 ofile.write(' {\"' + led_dict + '\",')
46 name_printed = True
47 if name == 'Action':
48 ofile.write('phosphor::led::Layout::')
49 ofile.write(str(value) + ',')
50 ofile.write('},\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053051 ofile.write(' }},\n')
52 ofile.write('};\n')
53