Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | import yaml |
| 3 | |
| 4 | if __name__ == '__main__': |
| 5 | with open('led.yaml', 'r') as f: |
| 6 | ifile = yaml.safe_load(f) |
| 7 | |
| 8 | with open('led-gen.hpp', 'w') as ofile: |
| 9 | ofile.write('/* !!! WARNING: This is a GENERATED Code..') |
| 10 | ofile.write('Please do NOT Edit !!! */\n\n') |
| 11 | |
| 12 | ofile.write('const std::map<std::string,') |
| 13 | ofile.write(' std::set<phosphor::led::Manager::LedAction>>') |
| 14 | ofile.write(' phosphor::led::Manager::cv_LedMap = {\n\n') |
| 15 | for group in ifile.iterkeys(): |
| 16 | # Value of this group is a std::set<string, led structure> |
| 17 | ledset = ifile[group] |
| 18 | ofile.write(' {\"' + group + '\",{\n') |
| 19 | |
| 20 | for led_dict, list_dict in ledset.iteritems(): |
| 21 | for name, value in list_dict.iteritems(): |
| 22 | if group and led_dict and name and value: |
| 23 | ofile.write(' {\"' + led_dict + '\",') |
| 24 | ofile.write(value.upper() + '},\n') |
| 25 | ofile.write(' }},\n') |
| 26 | ofile.write('};\n') |
| 27 | |