blob: fa12677a9e4ee6efa20a1b10b1bbf5fe5a5d02eb [file] [log] [blame]
Patrick Williams18ce8032020-01-31 18:47:38 -08001#!/usr/bin/env python3
Patrick Williamsa90b01e2016-10-09 16:19:52 -05002import sdbusplus
3import mako.lookup
4import argparse
Patrick Williamsaffeafa2016-10-17 11:40:13 -05005import sys
Brad Bishop33906872016-11-10 09:29:09 -05006import os
Patrick Williamsa90b01e2016-10-09 16:19:52 -05007
Patrick Williamsf5c3cde2016-10-21 11:49:01 -05008
Patrick Williamsa90b01e2016-10-09 16:19:52 -05009def main():
Brad Bishopccacc4a2016-11-10 17:10:46 -050010 module_path = os.path.dirname(sdbusplus.__file__)
11
Patrick Williams7d7fda52016-11-11 16:48:29 -060012 valid_types = {'interface': sdbusplus.Interface,
13 'error': sdbusplus.Error}
Patrick Williamsf5c3cde2016-10-21 11:49:01 -050014 valid_processes = {'markdown': "markdown",
15 'server-header': "server_header",
Patrick Williams7d7fda52016-11-11 16:48:29 -060016 'server-cpp': "server_cpp",
Patrick Williams250654e2016-11-11 17:19:43 -060017 'exception-header': "exception_header",
Lei YUddc0eba2020-02-13 16:26:46 +080018 'exception-cpp': "exception_cpp",
19 'client-header': "client_header"}
Patrick Williamsa90b01e2016-10-09 16:19:52 -050020
21 parser = argparse.ArgumentParser(description='Process sdbus++ YAML files.')
22
Patrick Williams7bfb70a2017-07-03 13:56:51 -050023 parser.add_argument('-r', '--rootdir', dest='rootdir', default='.',
Patrick Williamsa90b01e2016-10-09 16:19:52 -050024 type=str, help='Location of files to process.')
25 parser.add_argument('-t', '--templatedir', dest='templatedir',
Brad Bishopccacc4a2016-11-10 17:10:46 -050026 default=os.path.join(module_path, 'templates'),
Brad Bishop33906872016-11-10 09:29:09 -050027 type=str, help='Location of templates files.')
Patrick Williamsa90b01e2016-10-09 16:19:52 -050028 parser.add_argument('typeName', metavar='TYPE', type=str,
29 choices=valid_types.keys(), help='Type to operate on.')
30 parser.add_argument('process', metavar='PROCESS', type=str,
31 choices=valid_processes.keys(),
32 help='Process to apply.')
33 parser.add_argument('item', metavar='ITEM', type=str,
34 help='Item to process.')
35
Patrick Williamsf5c3cde2016-10-21 11:49:01 -050036 args = parser.parse_args()
Patrick Williamsa90b01e2016-10-09 16:19:52 -050037
Patrick Williams18ce8032020-01-31 18:47:38 -080038 lookup = mako.lookup.TemplateLookup(directories=[args.templatedir])
Patrick Williamsa90b01e2016-10-09 16:19:52 -050039
40 instance = valid_types[args.typeName].load(args.item, args.rootdir)
Patrick Williams24e8ae62016-10-14 18:24:38 -050041 function = getattr(instance, valid_processes[args.process])
Patrick Williamsa90b01e2016-10-09 16:19:52 -050042 print(function(lookup))
43
44if __name__ == '__main__':
45 main()