Skip to content

Instantly share code, notes, and snippets.

@vifon
Created September 30, 2017 11:05
Show Gist options
  • Save vifon/4103c149d4b36e7de9e19e82c9a5b1bb to your computer and use it in GitHub Desktop.
Save vifon/4103c149d4b36e7de9e19e82c9a5b1bb to your computer and use it in GitHub Desktop.
Jinja2 environment variable renderer
#!/usr/bin/env python3
from jinja2 import Template
import argparse
import os
def main(argv=None):
parser = argparse.ArgumentParser()
parser.add_argument('input_file', type=argparse.FileType('r'))
parser.add_argument('output_file', type=argparse.FileType('w'))
args = parser.parse_args()
print(
Template(
args.input_file.read(),
keep_trailing_newline=True,
).render(**os.environ),
file=args.output_file,
end='',
)
if __name__ == '__main__':
from sys import argv
main(argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment