forked from mskcc/roslin-variant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.py
executable file
·118 lines (82 loc) · 3.31 KB
/
configure.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python
import os, sys
import ruamel.yaml
from jinja2 import Template
def read_from_disk(filename):
"return file contents"
with open(filename, 'r') as file_in:
return file_in.read()
def write_to_disk(filename, content):
"write to file"
with open(filename, 'w') as file_out:
file_out.write(content)
print "Modified: {}".format(filename)
def get_template(filename):
"read template from file and return jinja template object"
with open(filename) as template_file:
return Template(template_file.read())
def configure_setup_settings(settings):
"make /setup/config/settings.sh"
template = get_template("/vagrant/setup/config/settings.template.sh")
# render
content = template.render(
pipeline_description=settings["description"],
pipeline_name=settings["name"],
pipeline_version=settings["version"],
core_min_version=settings["dependencies"]["core"]["version"]["min"],
core_max_version=settings["dependencies"]["core"]["version"]["max"],
pipeline_root=settings["root"],
binding_core=settings["binding"]["core"],
binding_data=settings["binding"]["data"],
binding_output=settings["binding"]["output"],
binding_workspace=settings["binding"]["workspace"],
binding_extra=" ".join(settings["binding"]["extra"]), # to space-separated list
dependencies_cmo_version=settings["dependencies"]["cmo"]["version"],
dependencies_cmo_bin_path=os.path.join(
settings["dependencies"]["cmo"]["install-path"],
settings["dependencies"]["cmo"]["version"],
"bin"
),
dependencies_cmo_python_path=os.path.join(
settings["dependencies"]["cmo"]["install-path"],
settings["dependencies"]["cmo"]["version"],
"lib/python2.7/site-packages"
)
)
write_to_disk("/vagrant/setup/config/settings.sh", content)
def configure_build_settings(settings):
"make /build/scripts/settings.sh"
template = get_template("/vagrant/build/scripts/settings-build.template.sh")
# ------------1
content = template.render(
version=settings["version"]
)
write_to_disk("/vagrant/build/scripts/settings-build.sh", content)
# ------------2
binding_points = [
os.path.join(settings["root"], settings["binding"]["core"]),
os.path.join(settings["root"], settings["binding"]["data"]),
os.path.join(settings["root"], settings["binding"]["output"]),
os.path.join(settings["root"], settings["binding"]["workspace"])
]
for extra in settings["binding"]["extra"]:
binding_points.append(os.path.join(settings["root"], extra))
template = get_template("/vagrant/build/scripts/settings-container.template.sh")
# render
content = template.render(
binding_points=" ".join(binding_points) # to space-separated list
)
write_to_disk("/vagrant/build/scripts/settings-container.sh", content)
def main():
"main function"
if len(sys.argv) < 2:
print "USAGE: config.py configuration_file.yaml"
exit()
settings = ruamel.yaml.load(
read_from_disk(sys.argv[1]),
ruamel.yaml.RoundTripLoader
)
configure_setup_settings(settings)
configure_build_settings(settings)
if __name__ == "__main__":
main()