Completed
Push — master ( f9bce8...3a72b7 )
by Egor
01:36
created

main()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
1
#!/usr/bin/env python
2
# coding: utf8
3
4
"""
5
This software is licensed under the Apache 2 license, quoted below.
6
7
Copyright 2014 Crystalnix Limited
8
9
Licensed under the Apache License, Version 2.0 (the "License"); you may not
10
use this file except in compliance with the License. You may obtain a copy of
11
the License at
12
13
    http://www.apache.org/licenses/LICENSE-2.0
14
15
Unless required by applicable law or agreed to in writing, software
16
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18
License for the specific language governing permissions and limitations under
19
the License.
20
"""
21
22
import os
23
24
import yaml
25
from jinja2 import Template
26
27
BASE_DIR = os.path.dirname(__file__)
28
TEMPLATE_PATH = os.path.join(BASE_DIR, 'ebs.config.template')
29
CONFIG_SAVE_PATH = os.path.join(BASE_DIR, 'ebs.config')
30
SETTINGS_PATH = os.path.join(BASE_DIR, 'settings.yml')
31
DEFAULT_SETTINGS = dict(
32
    app=dict(
33
        versions_to_keep=10,
34
        solution_stack_name='64bit Amazon Linux 2015.03 v1.4.3 running Docker 1.6.2',
35
        InstanceType='t2.small',
36
        autoscaling=dict(min=1, max=10),
37
        healthcheck_url='/healthcheck/status/',
38
    ),
39
    environment=dict(
40
        DJANGO_SETTINGS_MODULE='omaha_server.settings_dev',
41
        UWSGI_PROCESSES=10,
42
        UWSGI_THREADS=8,
43
    ),
44
)
45
46
47
def get_settings():
48
    with open(SETTINGS_PATH, 'r') as f:
49
        settings = yaml.load(f)
50
51
    app_settings = DEFAULT_SETTINGS['app'].copy()
52
    app_settings.update(settings['app'])
53
    settings['app'] = app_settings
54
55
    environments = settings['app']['environments']
56
    for env in environments.keys():
57
        environment = DEFAULT_SETTINGS['environment'].copy()
58
        environment.update(environments[env]['environment'])
59
        environments[env]['environment'] = environment
60
61
    return settings
62
63
64
def get_template():
65
    with open(TEMPLATE_PATH, 'r') as f:
66
        text = f.read()
67
    return Template(text)
68
69
70
def save_config(data):
71
    with open(CONFIG_SAVE_PATH, 'w') as f:
72
        f.write(data)
73
74
75
def main():
76
    template = get_template()
77
    ebs_config = template.render(**get_settings())
78
    save_config(ebs_config)
79
80
81
if __name__ == '__main__':
82
    main()
83