xref: /openbmc/sdbusplus/tools/sdbus++ (revision 33906871)
1#!/bin/env python
2import sdbusplus
3import mako.lookup
4import argparse
5import sys
6import os
7
8
9def main():
10    valid_types = {'interface': sdbusplus.Interface}
11    valid_processes = {'markdown': "markdown",
12                       'server-header': "server_header",
13                       'server-cpp': "server_cpp"}
14
15    parser = argparse.ArgumentParser(description='Process sdbus++ YAML files.')
16
17    parser.add_argument('-r', '--rootdir', dest='rootdir', default='example',
18                        type=str, help='Location of files to process.')
19    parser.add_argument('-t', '--templatedir', dest='templatedir',
20                        default=os.path.join('sdbusplus', 'templates'),
21                        type=str, help='Location of templates files.')
22    parser.add_argument('typeName', metavar='TYPE', type=str,
23                        choices=valid_types.keys(), help='Type to operate on.')
24    parser.add_argument('process', metavar='PROCESS', type=str,
25                        choices=valid_processes.keys(),
26                        help='Process to apply.')
27    parser.add_argument('item', metavar='ITEM', type=str,
28                        help='Item to process.')
29
30    args = parser.parse_args()
31
32    if sys.version_info < (3, 0):
33        lookup = mako.lookup.TemplateLookup(directories=[args.templatedir],
34                                            disable_unicode=True)
35    else:
36        lookup = mako.lookup.TemplateLookup(directories=[args.templatedir])
37
38    instance = valid_types[args.typeName].load(args.item, args.rootdir)
39    function = getattr(instance, valid_processes[args.process])
40    print(function(lookup))
41
42if __name__ == '__main__':
43    main()
44