blob: e0569429e6a98207c3f9fb56edbc4549d72a5135 [file] [log] [blame]
Patrick Williams1b7a5882020-06-23 07:34:11 -05001import argparse
Patrick Williams1b7a5882020-06-23 07:34:11 -05002import os
3
Patrick Williams6f5ffc62022-03-12 07:58:23 -06004import mako.lookup
Patrick Williams6ec4fd72022-12-05 16:01:54 -06005
Patrick Williams6f5ffc62022-03-12 07:58:23 -06006import sdbusplus
7
Patrick Williams9f77a472020-07-16 14:23:51 -05008
Patrick Williams1b7a5882020-06-23 07:34:11 -05009def main():
10 module_path = os.path.dirname(sdbusplus.__file__)
11
Patrick Williams9f77a472020-07-16 14:23:51 -050012 valid_types = {"interface": sdbusplus.Interface, "error": sdbusplus.Error}
13 valid_processes = {
14 "markdown": "markdown",
15 "server-header": "server_header",
16 "server-cpp": "server_cpp",
17 "exception-header": "exception_header",
18 "exception-cpp": "exception_cpp",
19 "client-header": "client_header",
20 }
Patrick Williams1b7a5882020-06-23 07:34:11 -050021
Patrick Williams9f77a472020-07-16 14:23:51 -050022 parser = argparse.ArgumentParser(description="Process sdbus++ YAML files.")
Patrick Williams1b7a5882020-06-23 07:34:11 -050023
Patrick Williams9f77a472020-07-16 14:23:51 -050024 parser.add_argument(
25 "-r",
26 "--rootdir",
27 dest="rootdir",
28 default=".",
29 type=str,
30 help="Location of files to process.",
31 )
32 parser.add_argument(
33 "-t",
34 "--templatedir",
35 dest="templatedir",
36 default=os.path.join(module_path, "templates"),
37 type=str,
38 help="Location of templates files.",
39 )
40 parser.add_argument(
41 "typeName",
42 metavar="TYPE",
43 type=str,
44 choices=valid_types.keys(),
45 help="Type to operate on.",
46 )
47 parser.add_argument(
48 "process",
49 metavar="PROCESS",
50 type=str,
51 choices=valid_processes.keys(),
52 help="Process to apply.",
53 )
54 parser.add_argument(
55 "item",
56 metavar="ITEM",
57 type=str,
58 help="Item to process.",
59 )
Patrick Williams1b7a5882020-06-23 07:34:11 -050060
61 args = parser.parse_args()
62
63 lookup = mako.lookup.TemplateLookup(directories=[args.templatedir])
64
65 instance = valid_types[args.typeName].load(args.item, args.rootdir)
66 function = getattr(instance, valid_processes[args.process])
67 print(function(lookup))