<s> import glob <EOL> import sys <EOL> import os <EOL> import yaml <EOL> from jinja2 import Environment , FileSystemLoader , StrictUndefined <EOL> import argparse <EOL> def env_override ( value , key ) : <EOL> return os . getenv ( key , value ) <EOL> def fileglob ( pathname ) : <EOL> return glob . glob ( pathname ) <EOL> def parse_args ( ) : <EOL> parser = argparse . ArgumentParser ( ) <EOL> parser . add_argument ( <EOL> "<STR_LIT>" , "<STR_LIT>" , action = '<STR_LIT>' , <EOL> default = [ ] , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> default = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> default = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return parser . parse_args ( ) <EOL> def setup_jinja ( template_file_name ) : <EOL> jinja = Environment ( loader = FileSystemLoader ( "<STR_LIT:.>" ) , undefined = StrictUndefined ) <EOL> jinja . filters [ '<STR_LIT>' ] = env_override <EOL> jinja . filters [ '<STR_LIT>' ] = fileglob <EOL> return jinja . get_template ( template_file_name ) <EOL> def collect_data ( data_file_names ) : <EOL> data = { } <EOL> for data_file_name in data_file_names : <EOL> if os . path . isfile ( data_file_name ) : <EOL> with open ( data_file_name , "<STR_LIT:r>" ) as fh : <EOL> data . update ( yaml . safe_load ( fh ) ) <EOL> return data <EOL> def write_compose_file ( composition , outputfile ) : <EOL> with open ( outputfile , "<STR_LIT:w>" ) as fh : <EOL> fh . write ( composition ) <EOL> def main ( ) : <EOL> args = parse_args ( ) <EOL> template = setup_jinja ( args . template ) <EOL> data = collect_data ( [ "<STR_LIT>" ] + args . datafile ) <EOL> write_compose_file ( template . render ( data ) , args . outputfile ) </s>
