Matthew Barth | db440d4 | 2017-04-17 15:49:37 -0500 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import os |
| 4 | import sys |
| 5 | import yaml |
| 6 | from argparse import ArgumentParser |
| 7 | from mako.template import Template |
| 8 | |
| 9 | |
| 10 | def generate(yaml_file, output_file): |
| 11 | with open(yaml_file, 'r') as yaml_input: |
| 12 | yaml_data = yaml.safe_load(yaml_input) or {} |
| 13 | |
| 14 | with open(output_file, 'w') as gen_out: |
| 15 | gen_out.write(Template(filename='generated.mako.cpp').render( |
| 16 | events=yaml_data)) |
| 17 | |
| 18 | |
| 19 | if __name__ == '__main__': |
| 20 | parser = ArgumentParser() |
| 21 | # Groups of items and how they should be monitored yaml file |
| 22 | parser.add_argument( |
| 23 | "-y", "--yaml", dest="input_yaml", |
| 24 | default="example/monitoring_defs.yaml", |
| 25 | help="Input item monitoring definition yaml to parse") |
| 26 | parser.add_argument( |
| 27 | "-o", "--outdir", dest="output_dir", |
| 28 | default=os.path.abspath('.'), |
| 29 | help="Output directory for source files generated") |
| 30 | args = parser.parse_args(sys.argv[1:]) |
| 31 | |
| 32 | yaml_file = os.path.abspath(args.input_yaml) |
| 33 | generate(yaml_file, os.path.join(args.output_dir, "generated.cpp")) |