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