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