-
Notifications
You must be signed in to change notification settings - Fork 29
/
convert_config_file.py
executable file
·47 lines (34 loc) · 1.33 KB
/
convert_config_file.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
#!/usr/bin/env python3
from configparser import ConfigParser
import yaml # needs the `pyyaml` package
import sys
def main():
if len(sys.argv) < 2:
print("Usage: {} <input-rc> [output-rc.yaml]".format(sys.argv[0]))
sys.exit(1)
old_config = ConfigParser()
old_config.read(sys.argv[1])
global_renamed_fields = {"docker_image": "java_docker_image"}
global_bool_fields = ["run_docker_with_sudo"]
host_bool_fields = ["skip_login", "allow_insecure_ssl", "format_jnlp", "send_post_data_as_json"]
config = {}
general = {global_renamed_fields.get(key, key): value for key, value in old_config["general"].items()}
for x in global_bool_fields:
if x in general:
general[x] = old_config["general"].getboolean(x)
config["general"] = general
config["hosts"] = {}
for x in old_config.sections():
if x == "general":
continue
config["hosts"][x] = dict(old_config[x])
for y in host_bool_fields:
if y in config["hosts"][x]:
config["hosts"][x][y] = old_config[x].getboolean(y)
if len(sys.argv) > 2:
with open(sys.argv[2], "w") as stream:
yaml.dump(config, stream, default_flow_style=False)
else:
print(yaml.dump(config, default_flow_style=False))
if __name__ == "__main__":
main()