Created
June 10, 2018 04:53
-
-
Save iwiwi/14483b199f44da34eae7117d1cfd87dd to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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