-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure.py
executable file
·67 lines (44 loc) · 1.6 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
#!/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):
template = get_template("config/settings.template.sh")
# render
content = template.render(
core_version=settings["version"],
roslin_core_root=os.path.abspath(settings["root"]),
roslin_root=os.path.abspath(settings["ROSLIN_CORE_ROOT"]),
core_mongo_host=settings["mongo"]["host"],
core_mongo_port=settings["mongo"]["port"],
core_mongo_database=settings["mongo"]["database"],
core_mongo_username=settings["mongo"]["username"],
core_mongo_password=settings["mongo"]["password"]
)
write_to_disk("config/settings.sh", content)
def main():
"main function"
if len(sys.argv) < 2:
print "USAGE: config.py configuration_file.yaml\nconfig.py configuration_file.yaml"
exit()
settings = ruamel.yaml.load(
read_from_disk(sys.argv[1]),
ruamel.yaml.RoundTripLoader
)
settings['ROSLIN_CORE_ROOT'] = os.environ['ROSLIN_ROOT']
configure_setup_settings(settings)
if __name__ == "__main__":
main()