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