-
Notifications
You must be signed in to change notification settings - Fork 0
/
mungojerrie.py
executable file
·39 lines (29 loc) · 1.08 KB
/
mungojerrie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
import sys
import argparse
import subprocess
import tempfile
import pathlib
mungojerrie_path = "mungojerrie/build/mungojerrie"
def main():
args = sys.argv[1:]
try:
sep_idx = args.index("--")
except ValueError:
raise ValueError("Must use '--' to provide arguments to mungojerrie")
args, mungojerrie_args = args[:sep_idx], args[sep_idx+1:]
model_path = mungojerrie_args[0]
parser = argparse.ArgumentParser()
parser.add_argument('-m','--model-params', nargs='+',
help='Substitute variables in .prism model', dest="model_params", required=False)
args = parser.parse_args(args)
model_params = args.model_params
model_params = dict(x.split("=") for x in model_params)
with tempfile.NamedTemporaryFile(mode='w+') as tmp:
model_str = pathlib.Path(model_path).read_text()
model_str = model_str.format(**model_params)
tmp.write(model_str)
tmp.flush()
return subprocess.check_call([mungojerrie_path, tmp.name] + mungojerrie_args[1:])
if __name__ == '__main__':
main()