Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | import yaml |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame] | 3 | import os |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 4 | |
| 5 | if __name__ == '__main__': |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame] | 6 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 7 | with open(os.path.join(script_dir, 'led.yaml'), 'r') as f: |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 8 | ifile = yaml.safe_load(f) |
| 9 | |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame] | 10 | with open(os.path.join(script_dir, 'led-gen.hpp'), 'w') as ofile: |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 11 | ofile.write('/* !!! WARNING: This is a GENERATED Code..') |
| 12 | ofile.write('Please do NOT Edit !!! */\n\n') |
| 13 | |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 14 | ofile.write('static const std::map<std::string,') |
| 15 | ofile.write(' std::set<phosphor::led::Layout::LedAction>>') |
| 16 | ofile.write(' systemLedMap = {\n\n') |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 17 | for group in ifile.iterkeys(): |
Vishwanatha Subbanna | 8a50a50 | 2017-01-20 18:42:21 +0530 | [diff] [blame^] | 18 | # This section generates an std::map of LedGroupNames to std::set |
| 19 | # of LEDs containing the name and properties |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 20 | ledset = ifile[group] |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame] | 21 | ofile.write(' {\"' + "/xyz/openbmc_project/ledmanager/groups/" + group + '\",{\n') |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 22 | |
| 23 | for led_dict, list_dict in ledset.iteritems(): |
Vishwanatha Subbanna | 8a50a50 | 2017-01-20 18:42:21 +0530 | [diff] [blame^] | 24 | # Need this to make sure the LED name is printed once |
| 25 | name_printed = False |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 26 | for name, value in list_dict.iteritems(): |
Vishwanatha Subbanna | 8a50a50 | 2017-01-20 18:42:21 +0530 | [diff] [blame^] | 27 | if group and led_dict and name: |
| 28 | if name_printed is False: |
| 29 | ofile.write(' {\"' + led_dict + '\",') |
| 30 | name_printed = True |
| 31 | if name == 'Action': |
| 32 | ofile.write('phosphor::led::Layout::') |
| 33 | ofile.write(str(value) + ',') |
| 34 | ofile.write('},\n') |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 35 | ofile.write(' }},\n') |
| 36 | ofile.write('};\n') |
| 37 | |