Patrick Williams | 1b7a588 | 2020-06-23 07:34:11 -0500 | [diff] [blame] | 1 | import argparse |
Patrick Williams | 1b7a588 | 2020-06-23 07:34:11 -0500 | [diff] [blame] | 2 | import os |
| 3 | |
Patrick Williams | 6f5ffc6 | 2022-03-12 07:58:23 -0600 | [diff] [blame] | 4 | import mako.lookup |
Patrick Williams | 6ec4fd7 | 2022-12-05 16:01:54 -0600 | [diff] [blame^] | 5 | |
Patrick Williams | 6f5ffc6 | 2022-03-12 07:58:23 -0600 | [diff] [blame] | 6 | import sdbusplus |
| 7 | |
Patrick Williams | 9f77a47 | 2020-07-16 14:23:51 -0500 | [diff] [blame] | 8 | |
Patrick Williams | 1b7a588 | 2020-06-23 07:34:11 -0500 | [diff] [blame] | 9 | def main(): |
| 10 | module_path = os.path.dirname(sdbusplus.__file__) |
| 11 | |
Patrick Williams | 9f77a47 | 2020-07-16 14:23:51 -0500 | [diff] [blame] | 12 | valid_types = {"interface": sdbusplus.Interface, "error": sdbusplus.Error} |
| 13 | valid_processes = { |
| 14 | "markdown": "markdown", |
| 15 | "server-header": "server_header", |
| 16 | "server-cpp": "server_cpp", |
| 17 | "exception-header": "exception_header", |
| 18 | "exception-cpp": "exception_cpp", |
| 19 | "client-header": "client_header", |
| 20 | } |
Patrick Williams | 1b7a588 | 2020-06-23 07:34:11 -0500 | [diff] [blame] | 21 | |
Patrick Williams | 9f77a47 | 2020-07-16 14:23:51 -0500 | [diff] [blame] | 22 | parser = argparse.ArgumentParser(description="Process sdbus++ YAML files.") |
Patrick Williams | 1b7a588 | 2020-06-23 07:34:11 -0500 | [diff] [blame] | 23 | |
Patrick Williams | 9f77a47 | 2020-07-16 14:23:51 -0500 | [diff] [blame] | 24 | parser.add_argument( |
| 25 | "-r", |
| 26 | "--rootdir", |
| 27 | dest="rootdir", |
| 28 | default=".", |
| 29 | type=str, |
| 30 | help="Location of files to process.", |
| 31 | ) |
| 32 | parser.add_argument( |
| 33 | "-t", |
| 34 | "--templatedir", |
| 35 | dest="templatedir", |
| 36 | default=os.path.join(module_path, "templates"), |
| 37 | type=str, |
| 38 | help="Location of templates files.", |
| 39 | ) |
| 40 | parser.add_argument( |
| 41 | "typeName", |
| 42 | metavar="TYPE", |
| 43 | type=str, |
| 44 | choices=valid_types.keys(), |
| 45 | help="Type to operate on.", |
| 46 | ) |
| 47 | parser.add_argument( |
| 48 | "process", |
| 49 | metavar="PROCESS", |
| 50 | type=str, |
| 51 | choices=valid_processes.keys(), |
| 52 | help="Process to apply.", |
| 53 | ) |
| 54 | parser.add_argument( |
| 55 | "item", |
| 56 | metavar="ITEM", |
| 57 | type=str, |
| 58 | help="Item to process.", |
| 59 | ) |
Patrick Williams | 1b7a588 | 2020-06-23 07:34:11 -0500 | [diff] [blame] | 60 | |
| 61 | args = parser.parse_args() |
| 62 | |
| 63 | lookup = mako.lookup.TemplateLookup(directories=[args.templatedir]) |
| 64 | |
| 65 | instance = valid_types[args.typeName].load(args.item, args.rootdir) |
| 66 | function = getattr(instance, valid_processes[args.process]) |
| 67 | print(function(lookup)) |