forked from GambitBSM/gambit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyaml_bash.py
More file actions
39 lines (28 loc) · 863 Bytes
/
yaml_bash.py
File metadata and controls
39 lines (28 loc) · 863 Bytes
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
"""
Parse relevant data from YAML file into BASH commands
=====================================================
"""
from sys import argv
from import_yaml import load
BLOCK = "Test"
KEYS = ["gambit", "expected", "rtol", "email"]
def yaml_to_bash(yaml_name):
"""
:param yaml_name: Name of YAML file
:type yaml_name: str
:returns: YAML data in BASH syntax
:rtype: str
"""
with open(yaml_name) as yaml_file:
data = load(yaml_file)
try:
bash = ['{}_{}="{}"'.format(BLOCK, k, data[BLOCK][k]) for k in KEYS]
except (TypeError, IndexError):
error = "YAML didn't contain {} block with {} keys".format(BLOCK, KEYS)
raise RuntimeError(error)
bash = ";".join(bash)
return bash
if __name__ == "__main__":
assert len(argv) == 2
yaml_name = argv[1]
print yaml_to_bash(yaml_name)