-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter.py
57 lines (51 loc) · 1.81 KB
/
converter.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import yaml
import json
def convert_cntl_to_yamljson(cntl_file, out_file):
config = {}
with open(cntl_file, "r") as f:
for line in f:
if line.startswith("#"):
continue
key, value = line.split("=")
value = value.strip()
if value.lower() in ("yes", "no"):
value = {"yes": True, "no": False}[value.lower()]
elif "," in value:
if value.startswith('"'):
value = value[1:]
if value.endswith('"'):
value = value[:-1]
value = value.split(",")
try:
value = [int(v.strip()) for v in value if len(v.strip()) > 0]
except ValueError:
try:
value = [float(v.strip()) for v in value if len(v.strip()) > 0]
except ValueError:
pass
else:
try:
value = int(value.strip())
except ValueError:
try:
value = float(value.strip())
except ValueError:
pass
if key.strip().upper() in (
"WALL_TIME",
"CYCLE_TIME",
"CHECKPOINT_TIME",
"SUBJOBS_BUFFER_SIZE",
"RE_SETUP",
"JOB_TRANSPORT",
):
continue
config[key.strip()] = value
with open(out_file, "w") as f:
if out_file.endswith(".yaml"):
yaml.dump(config, f, default_flow_style=None, sort_keys=False)
elif out_file.endswith(".json"):
json.dump(config, f)
if __name__ == "__main__":
import sys
convert_cntl_to_yamljson(sys.argv[1], sys.argv[2])