forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_sample_to_kwalify.py
70 lines (60 loc) · 1.88 KB
/
config_sample_to_kwalify.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
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
def main():
"""Entry point for conversion procedure."""
found_app_main = False
current_section_desc = []
current_section_options = []
try:
sample = sys.argv[1]
except KeyError:
sample = "config/galaxy.ini.sample"
for line in open(sample):
is_app_main = line.startswith("[app:main]")
if not found_app_main and not is_app_main:
continue
if is_app_main:
found_app_main = True
continue
line = line.strip()
if not line.startswith("#"):
for section_option in current_section_options:
_dump_option(section_option, current_section_desc)
current_section_desc = []
current_section_options = []
if line.startswith("[galaxy_amqp]"):
break
if line.startswith("# ") or "#" == line:
current_section_desc.append(line[2:])
elif line.startswith("#"):
current_section_options.append(line)
def _dump_option(option, current_section_desc):
def print_line(line):
print((" " * 6) + line)
if "=" not in option:
print(option)
key, default = (s.strip() for s in option.split("=", 1))
key = key[1:] # strip #
if default.strip().lower() in ["true", "false"]:
default = default.lower()
type = "bool"
elif default.isdigit():
type = "int"
else:
try:
float(default)
type = "float"
except ValueError:
type = "str"
if default == "None":
default = None
print_line(f"{key}:")
print_line(f" type: {type}")
if default is not None:
print_line(f" default: {default}")
# print_line(" required: false")
print_line(" desc: |")
for line in current_section_desc:
print_line(f" {line}")
print_line("")
if __name__ == "__main__":
main()