Skip to content

Instantly share code, notes, and snippets.

@iwiwi
Created June 10, 2018 04:53
Embed
What would you like to do?
#!/usr/bin/env python
import itertools
import sys
import os
import subprocess
import jinja2
def enumerate_combinations(**params):
product_args = []
for key, vals in params.items():
if not isinstance(vals, tuple) and not isinstance(vals, list):
vals = [vals]
product_args.append([(key, val) for val in vals])
for comb in itertools.product(*product_args):
yield dict(comb)
def qsub(template='-', **params):
if template == '-':
template = sys.stdin.read()
else:
template= open(template).read()
template = jinja2.Template(template)
info = {
'cwd': os.getcwd()
}
os.makedirs('tmp', exist_ok=True)
for comb in enumerate_combinations(**params):
with open('tmp/tmp.sh', 'w') as f:
f.write(template.render(**comb, **info))
subprocess.check_call(['qsub', 'tmp/tmp.sh'])
if __name__ == '__main__':
import fire
fire.Fire(qsub)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment