xref: /openbmc/sdbusplus/tools/sdbusplus/main.py (revision 6403d56f)
1import argparse
2import os
3
4import mako.lookup
5
6import sdbusplus
7
8
9def main():
10    module_path = os.path.dirname(sdbusplus.__file__)
11
12    valid_types = {"interface": sdbusplus.Interface, "error": sdbusplus.Error}
13    valid_processes = {
14        "aserver-header": "async_server_header",
15        "client-header": "client_header",
16        "common-header": "common_header",
17        "exception-cpp": "exception_cpp",
18        "exception-header": "exception_header",
19        "markdown": "markdown",
20        "server-cpp": "server_cpp",
21        "server-header": "server_header",
22    }
23
24    parser = argparse.ArgumentParser(description="Process sdbus++ YAML files.")
25
26    parser.add_argument(
27        "-r",
28        "--rootdir",
29        dest="rootdir",
30        default=".",
31        type=str,
32        help="Location of files to process.",
33    )
34    parser.add_argument(
35        "-t",
36        "--templatedir",
37        dest="templatedir",
38        default=os.path.join(module_path, "templates"),
39        type=str,
40        help="Location of templates files.",
41    )
42    parser.add_argument(
43        "typeName",
44        metavar="TYPE",
45        type=str,
46        choices=valid_types.keys(),
47        help="Type to operate on.",
48    )
49    parser.add_argument(
50        "process",
51        metavar="PROCESS",
52        type=str,
53        choices=valid_processes.keys(),
54        help="Process to apply.",
55    )
56    parser.add_argument(
57        "item",
58        metavar="ITEM",
59        type=str,
60        help="Item to process.",
61    )
62
63    args = parser.parse_args()
64
65    lookup = mako.lookup.TemplateLookup(directories=[args.templatedir])
66
67    instance = valid_types[args.typeName].load(args.item, args.rootdir)
68    function = getattr(instance, valid_processes[args.process])
69    print(function(lookup))
70