Patrick Williams | 18ce803 | 2020-01-31 18:47:38 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Patrick Williams | a90b01e | 2016-10-09 16:19:52 -0500 | [diff] [blame] | 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 |
Brad Bishop | 3390687 | 2016-11-10 09:29:09 -0500 | [diff] [blame] | 6 | import os |
Patrick Williams | a90b01e | 2016-10-09 16:19:52 -0500 | [diff] [blame] | 7 | |
Patrick Williams | f5c3cde | 2016-10-21 11:49:01 -0500 | [diff] [blame] | 8 | |
Patrick Williams | a90b01e | 2016-10-09 16:19:52 -0500 | [diff] [blame] | 9 | def main(): |
Brad Bishop | ccacc4a | 2016-11-10 17:10:46 -0500 | [diff] [blame] | 10 | module_path = os.path.dirname(sdbusplus.__file__) |
| 11 | |
Patrick Williams | 7d7fda5 | 2016-11-11 16:48:29 -0600 | [diff] [blame] | 12 | valid_types = {'interface': sdbusplus.Interface, |
| 13 | 'error': sdbusplus.Error} |
Patrick Williams | f5c3cde | 2016-10-21 11:49:01 -0500 | [diff] [blame] | 14 | valid_processes = {'markdown': "markdown", |
| 15 | 'server-header': "server_header", |
Patrick Williams | 7d7fda5 | 2016-11-11 16:48:29 -0600 | [diff] [blame] | 16 | 'server-cpp': "server_cpp", |
Patrick Williams | 250654e | 2016-11-11 17:19:43 -0600 | [diff] [blame] | 17 | 'exception-header': "exception_header", |
Lei YU | ddc0eba | 2020-02-13 16:26:46 +0800 | [diff] [blame] | 18 | 'exception-cpp': "exception_cpp", |
| 19 | 'client-header': "client_header"} |
Patrick Williams | a90b01e | 2016-10-09 16:19:52 -0500 | [diff] [blame] | 20 | |
| 21 | parser = argparse.ArgumentParser(description='Process sdbus++ YAML files.') |
| 22 | |
Patrick Williams | 7bfb70a | 2017-07-03 13:56:51 -0500 | [diff] [blame] | 23 | parser.add_argument('-r', '--rootdir', dest='rootdir', default='.', |
Patrick Williams | a90b01e | 2016-10-09 16:19:52 -0500 | [diff] [blame] | 24 | type=str, help='Location of files to process.') |
| 25 | parser.add_argument('-t', '--templatedir', dest='templatedir', |
Brad Bishop | ccacc4a | 2016-11-10 17:10:46 -0500 | [diff] [blame] | 26 | default=os.path.join(module_path, 'templates'), |
Brad Bishop | 3390687 | 2016-11-10 09:29:09 -0500 | [diff] [blame] | 27 | type=str, help='Location of templates files.') |
Patrick Williams | a90b01e | 2016-10-09 16:19:52 -0500 | [diff] [blame] | 28 | 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 Williams | f5c3cde | 2016-10-21 11:49:01 -0500 | [diff] [blame] | 36 | args = parser.parse_args() |
Patrick Williams | a90b01e | 2016-10-09 16:19:52 -0500 | [diff] [blame] | 37 | |
Patrick Williams | 18ce803 | 2020-01-31 18:47:38 -0800 | [diff] [blame] | 38 | lookup = mako.lookup.TemplateLookup(directories=[args.templatedir]) |
Patrick Williams | a90b01e | 2016-10-09 16:19:52 -0500 | [diff] [blame] | 39 | |
| 40 | instance = valid_types[args.typeName].load(args.item, args.rootdir) |
Patrick Williams | 24e8ae6 | 2016-10-14 18:24:38 -0500 | [diff] [blame] | 41 | function = getattr(instance, valid_processes[args.process]) |
Patrick Williams | a90b01e | 2016-10-09 16:19:52 -0500 | [diff] [blame] | 42 | print(function(lookup)) |
| 43 | |
| 44 | if __name__ == '__main__': |
| 45 | main() |