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 | ccbdf67 | 2017-01-23 14:39:06 +0530 | [diff] [blame^] | 4 | import argparse |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 5 | |
| 6 | if __name__ == '__main__': |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame] | 7 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
Vishwanatha Subbanna | ccbdf67 | 2017-01-23 14:39:06 +0530 | [diff] [blame^] | 8 | 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 Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 24 | ifile = yaml.safe_load(f) |
| 25 | |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame] | 26 | 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] | 27 | ofile.write('/* !!! WARNING: This is a GENERATED Code..') |
| 28 | ofile.write('Please do NOT Edit !!! */\n\n') |
| 29 | |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 30 | ofile.write('static const std::map<std::string,') |
| 31 | ofile.write(' std::set<phosphor::led::Layout::LedAction>>') |
| 32 | ofile.write(' systemLedMap = {\n\n') |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 33 | for group in ifile.iterkeys(): |
Vishwanatha Subbanna | 8a50a50 | 2017-01-20 18:42:21 +0530 | [diff] [blame] | 34 | # This section generates an std::map of LedGroupNames to std::set |
| 35 | # of LEDs containing the name and properties |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 36 | ledset = ifile[group] |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame] | 37 | ofile.write(' {\"' + "/xyz/openbmc_project/ledmanager/groups/" + group + '\",{\n') |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 38 | |
| 39 | for led_dict, list_dict in ledset.iteritems(): |
Vishwanatha Subbanna | 8a50a50 | 2017-01-20 18:42:21 +0530 | [diff] [blame] | 40 | # Need this to make sure the LED name is printed once |
| 41 | name_printed = False |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 42 | for name, value in list_dict.iteritems(): |
Vishwanatha Subbanna | 8a50a50 | 2017-01-20 18:42:21 +0530 | [diff] [blame] | 43 | 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 Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 51 | ofile.write(' }},\n') |
| 52 | ofile.write('};\n') |
| 53 | |