Last active
October 25, 2021 04:18
-
-
Save akshayrdeodhar/2cfedf2ce0a43a0a2628ea1de5941624 to your computer and use it in GitHub Desktop.
Use jinja for generating files from templates independent of web frameworks
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
import jinja2 | |
from sys import argv, stderr, exit | |
def generate_combined(filename, processors, threads): | |
templateLoader = jinja2.FileSystemLoader(searchpath = './') | |
templateEnv = jinja2.Environment(loader = templateLoader) | |
template = templateEnv.get_template(filename) | |
nodestring = "1:ppn={}".format(threads) | |
data = { | |
"processors": processors, | |
"threads": threads, | |
"res_list": [nodestring + "+" for i in range(processors - 1)] + [nodestring], | |
"minutes": "15", | |
} | |
outputText = template.render(**data) | |
with open("{}-{}-combined.pbs".format(processors, threads), "w") as fp: | |
print(outputText, file = fp) | |
if __name__ == "__main__": | |
n = len(argv) | |
if n != 4: | |
print("usage: python3 generate_combined.py <template> <processors> <threads>", file = stderr) | |
_, filename, processors, threads = argv | |
processors = int(processors) | |
threads = int(threads) | |
generate_combined(filename, processors, threads) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment