blob: ea5887612e5291cbf00a2f6e1e29d8c02ef0f377 [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 Subbannab21fda72016-10-17 17:46:37 +05304
5if __name__ == '__main__':
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +05306 script_dir = os.path.dirname(os.path.realpath(__file__))
7 with open(os.path.join(script_dir, 'led.yaml'), 'r') as f:
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +05308 ifile = yaml.safe_load(f)
9
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053010 with open(os.path.join(script_dir, 'led-gen.hpp'), 'w') as ofile:
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053011 ofile.write('/* !!! WARNING: This is a GENERATED Code..')
12 ofile.write('Please do NOT Edit !!! */\n\n')
13
14 ofile.write('const std::map<std::string,')
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053015 ofile.write(' std::set<phosphor::led::Manager::LedAction>>')
16 ofile.write(' phosphor::led::Manager::ledMap = {\n\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053017 for group in ifile.iterkeys():
18 # Value of this group is a std::set<string, led structure>
19 ledset = ifile[group]
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053020 ofile.write(' {\"' + "/xyz/openbmc_project/ledmanager/groups/" + group + '\",{\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053021
22 for led_dict, list_dict in ledset.iteritems():
23 for name, value in list_dict.iteritems():
24 if group and led_dict and name and value:
25 ofile.write(' {\"' + led_dict + '\",')
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053026 ofile.write(value + '},\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053027 ofile.write(' }},\n')
28 ofile.write('};\n')
29