blob: 6b0a15cc7335dab09abdf945e562b4abb072643d [file] [log] [blame]
Patrick Williamsa90b01e2016-10-09 16:19:52 -05001#!/bin/env python
2import 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():
Patrick Williamsf5c3cde2016-10-21 11:49:01 -050010 valid_types = {'interface': sdbusplus.Interface}
11 valid_processes = {'markdown': "markdown",
12 'server-header': "server_header",
13 'server-cpp': "server_cpp"}
Patrick Williamsa90b01e2016-10-09 16:19:52 -050014
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',
Brad Bishop33906872016-11-10 09:29:09 -050020 default=os.path.join('sdbusplus', 'templates'),
21 type=str, help='Location of templates files.')
Patrick Williamsa90b01e2016-10-09 16:19:52 -050022 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
Patrick Williamsf5c3cde2016-10-21 11:49:01 -050030 args = parser.parse_args()
Patrick Williamsa90b01e2016-10-09 16:19:52 -050031
Patrick Williamsf5c3cde2016-10-21 11:49:01 -050032 if sys.version_info < (3, 0):
Patrick Williamsaffeafa2016-10-17 11:40:13 -050033 lookup = mako.lookup.TemplateLookup(directories=[args.templatedir],
34 disable_unicode=True)
35 else:
36 lookup = mako.lookup.TemplateLookup(directories=[args.templatedir])
Patrick Williamsa90b01e2016-10-09 16:19:52 -050037
38 instance = valid_types[args.typeName].load(args.item, args.rootdir)
Patrick Williams24e8ae62016-10-14 18:24:38 -050039 function = getattr(instance, valid_processes[args.process])
Patrick Williamsa90b01e2016-10-09 16:19:52 -050040 print(function(lookup))
41
42if __name__ == '__main__':
43 main()