blob: c86764c3af7b0b2faa4dc27e82515f9be5391b91 [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
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053014 ofile.write('static const std::map<std::string,')
15 ofile.write(' std::set<phosphor::led::Layout::LedAction>>')
16 ofile.write(' systemLedMap = {\n\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053017 for group in ifile.iterkeys():
Vishwanatha Subbanna8a50a502017-01-20 18:42:21 +053018 # This section generates an std::map of LedGroupNames to std::set
19 # of LEDs containing the name and properties
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053020 ledset = ifile[group]
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053021 ofile.write(' {\"' + "/xyz/openbmc_project/ledmanager/groups/" + group + '\",{\n')
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053022
23 for led_dict, list_dict in ledset.iteritems():
Vishwanatha Subbanna8a50a502017-01-20 18:42:21 +053024 # Need this to make sure the LED name is printed once
25 name_printed = False
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053026 for name, value in list_dict.iteritems():
Vishwanatha Subbanna8a50a502017-01-20 18:42:21 +053027 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 Subbannab21fda72016-10-17 17:46:37 +053035 ofile.write(' }},\n')
36 ofile.write('};\n')
37