#!/usr/bin/env python

import yaml
import os
import sys

from jinja2 import Environment, FileSystemLoader

tpl = sys.argv[1]
variables = {}

try:
    env_file = sys.argv[2]
    try:
        with open(env_file) as f:
            variables = yaml.load(f)
    except IOError:
        print('Unable to read environment file "%s"' % env_file)
        sys.exit(1)
except IndexError:
    pass

env = Environment(loader=FileSystemLoader(os.path.dirname(tpl)))
renderer = env.get_template(os.path.basename(tpl))

print(renderer.render(**variables))
