Back to home page

EIC code displayed by LXR

 
 

    


Warning, /epic/bin/make_detector_configuration is written in an unsupported language. File is not indexed.

0001 #!/usr/bin/env python3
0002 
0003 import os
0004 import glob
0005 import yaml
0006 import jinja2
0007 import argparse
0008 
0009 # parse arguments
0010 parser = argparse.ArgumentParser()
0011 parser.add_argument('-d', '--dir', type=str, default='templates', help='Template directory.')
0012 parser.add_argument('-t', '--template', type=str, help='Template to render.')
0013 parser.add_argument('-o', '--output', type=str, help='Output file to write.')
0014 parser.add_argument('-c', '--config', type=str, help='Config file to load.')
0015 args = parser.parse_args()
0016 
0017 # template
0018 env = jinja2.Environment(
0019     loader = jinja2.FileSystemLoader(args.dir),
0020 )
0021 template = env.get_template(args.template)
0022 
0023 # detector constants
0024 config = {}
0025 if args.config is not None:
0026     with open(args.config) as f:
0027         config = yaml.safe_load(f)
0028 
0029 # render the template
0030 with open(args.output, 'w') as output:
0031     output.write(template.render(**config))