summaryrefslogtreecommitdiffstats
path: root/parse_led.py
blob: 5afe4b02299081355ddfc1e8239ff637e082638c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
import yaml
import os
import argparse
from inflection import underscore

if __name__ == '__main__':
    script_dir = os.path.dirname(os.path.realpath(__file__))
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-f", "--filename",
        default='led.yaml',
        help="Input File Name")
    parser.add_argument(
        "-i", "--input-dir",
        dest='inputdir',
        default=script_dir,
        help="Input directory")
    parser.add_argument(
        '-o', '--output-dir',
        dest='outputdir',
        default='.',
        help='Output directory.')

    args = parser.parse_args()

    # Default to the one that is in the current.
    yaml_dir = script_dir
    yaml_file = os.path.join(yaml_dir, 'led.yaml')

    if args.inputdir:
        yaml_dir = args.inputdir

    if args.filename:
        yaml_file = os.path.join(yaml_dir, args.filename)

    with open(yaml_file, 'r') as f:
        ifile = yaml.safe_load(f)

    with open(os.path.join(args.outputdir, 'led-gen.hpp'), 'w') as ofile:
        ofile.write('/* !!! WARNING: This is a GENERATED Code..')
        ofile.write('Please do NOT Edit !!! */\n\n')

        ofile.write('static const std::map<std::string,')
        ofile.write(' std::set<phosphor::led::Layout::LedAction>>')
        ofile.write(' systemLedMap = {\n\n')
        for group in ifile.keys():
            # This section generates an std::map of LedGroupNames to std::set
            # of LEDs containing the name and properties
            ledset = ifile[group]
            ofile.write(
                '   {\"' +
                "/xyz/openbmc_project/led/groups/" +
                underscore(group) +
                '\",{\n')

            # Some LED groups could be empty
            if not ledset:
                ofile.write('   }},\n')
                continue

            for led_dict, list_dict in ledset.items():
                ofile.write('        {\"' + underscore(led_dict) + '\",')
                ofile.write('phosphor::led::Layout::' +
                            str(list_dict.get('Action', 'Off')) + ',')
                ofile.write(str(list_dict.get('DutyOn', 0)) + ',')
                ofile.write(str(list_dict.get('Period', 0)) + ',')

                ofile.write('},\n')
            ofile.write('   }},\n')
        ofile.write('};\n')
OpenPOWER on IntegriCloud