Created
September 30, 2017 11:05
-
-
Save vifon/4103c149d4b36e7de9e19e82c9a5b1bb to your computer and use it in GitHub Desktop.
Jinja2 environment variable renderer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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