Matt Spinler | 991bb76 | 2020-03-09 13:50:55 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Deepak Kodihalli | 5650b39 | 2017-03-02 04:40:27 -0600 | [diff] [blame] | 2 | |
Deepak Kodihalli | 5650b39 | 2017-03-02 04:40:27 -0600 | [diff] [blame] | 3 | import argparse |
Patrick Williams | d27675d | 2022-12-08 06:18:00 -0600 | [diff] [blame] | 4 | import os |
| 5 | |
| 6 | from mako.template import Template |
| 7 | |
| 8 | import yaml |
Deepak Kodihalli | 5650b39 | 2017-03-02 04:40:27 -0600 | [diff] [blame] | 9 | |
| 10 | |
| 11 | def main(): |
Patrick Williams | e6555f5 | 2022-08-04 13:56:17 -0500 | [diff] [blame] | 12 | parser = argparse.ArgumentParser(description="Callout code generator") |
Deepak Kodihalli | 5650b39 | 2017-03-02 04:40:27 -0600 | [diff] [blame] | 13 | |
| 14 | parser.add_argument( |
Patrick Williams | e6555f5 | 2022-08-04 13:56:17 -0500 | [diff] [blame] | 15 | "-i", |
| 16 | "--callouts_yaml", |
| 17 | dest="callouts_yaml", |
| 18 | default=os.path.join(script_dir, "callouts-example.yaml"), |
| 19 | help="input callouts yaml", |
| 20 | ) |
Patrick Williams | c040d39 | 2021-04-16 10:33:24 -0500 | [diff] [blame] | 21 | parser.add_argument( |
Patrick Williams | e6555f5 | 2022-08-04 13:56:17 -0500 | [diff] [blame] | 22 | "-o", |
| 23 | "--output", |
| 24 | dest="output", |
| 25 | default="callouts-gen.hpp", |
| 26 | help="output file name (default: callouts-gen.hpp)", |
| 27 | ) |
Patrick Williams | c040d39 | 2021-04-16 10:33:24 -0500 | [diff] [blame] | 28 | |
Deepak Kodihalli | 5650b39 | 2017-03-02 04:40:27 -0600 | [diff] [blame] | 29 | args = parser.parse_args() |
| 30 | |
Patrick Williams | e6555f5 | 2022-08-04 13:56:17 -0500 | [diff] [blame] | 31 | with open(args.callouts_yaml, "r") as fd: |
Deepak Kodihalli | 5650b39 | 2017-03-02 04:40:27 -0600 | [diff] [blame] | 32 | calloutsMap = yaml.safe_load(fd) |
| 33 | |
| 34 | # Render the mako template |
Patrick Williams | e6555f5 | 2022-08-04 13:56:17 -0500 | [diff] [blame] | 35 | template = os.path.join(script_dir, "callouts-gen.mako.hpp") |
Deepak Kodihalli | 5650b39 | 2017-03-02 04:40:27 -0600 | [diff] [blame] | 36 | t = Template(filename=template) |
Patrick Williams | e6555f5 | 2022-08-04 13:56:17 -0500 | [diff] [blame] | 37 | with open(args.output, "w") as fd: |
| 38 | fd.write(t.render(calloutsMap=calloutsMap)) |
Deepak Kodihalli | 5650b39 | 2017-03-02 04:40:27 -0600 | [diff] [blame] | 39 | |
| 40 | |
Patrick Williams | e6555f5 | 2022-08-04 13:56:17 -0500 | [diff] [blame] | 41 | if __name__ == "__main__": |
Deepak Kodihalli | 5650b39 | 2017-03-02 04:40:27 -0600 | [diff] [blame] | 42 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 43 | main() |