xref: /openbmc/phosphor-settingsd/settings.py (revision bbeb9bdd)
1#!/usr/bin/env python3
2
3import argparse
4import os
5
6import yaml
7from mako.template import Template
8
9
10def main():
11    parser = argparse.ArgumentParser(
12        description="Settings YAML parser and code generator"
13    )
14
15    parser.add_argument(
16        "-i",
17        "--settings_yaml",
18        dest="settings_yaml",
19        default="settings_example.yaml",
20        help="settings yaml file to parse",
21    )
22    args = parser.parse_args()
23
24    with open(os.path.join(script_dir, args.settings_yaml), "r") as fd:
25        yamlDict = yaml.safe_load(fd)
26
27        # Render the mako template
28        template = os.path.join(script_dir, "settings_manager.mako.hpp")
29        t = Template(filename=template)
30        with open("settings_manager.hpp", "w") as fd:
31            fd.write(t.render(settingsDict=yamlDict))
32
33
34if __name__ == "__main__":
35    script_dir = os.path.dirname(os.path.realpath(__file__))
36    main()
37