Project

General

Profile

0001-flatten-site-options-so-they-can-be-used-in-string-t.patch

Frédéric Péters (de retour le 27 mai), 31 October 2013 02:31 PM

Download (1.7 KB)

View differences:

Subject: [PATCH] flatten site options so they can be used in string template
 (#3928)

 wcsinst/wcsinstd/deploy.py | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
wcsinst/wcsinstd/deploy.py
18 18
def get_provider_key(provider_id):
19 19
    return provider_id.replace('://', '-').replace('/', '-').replace('?', '-').replace(':', '-')
20 20

  
21
def flatten_dict(d):
22
    for k, v in d.items():
23
        if type(v) is dict:
24
            flatten_dict(v)
25
            for k2, v2 in v.items():
26
                d['%s_%s' % (k, k2)] = v2
27
            del d[k]
28
    return d
29

  
21 30

  
22 31
class DeployInstance(object):
23 32
    skeleton = 'default'
......
206 215
        if not os.path.exists(options_template_path):
207 216
            return
208 217
        options_template = file(options_template_path).read()
218
        vars = {'domain': self.domain}
219
        if self.site_options_cfg:
220
            vars.update(flatten_dict(self.site_options_cfg))
209 221
        file(os.path.join(self.collectivity_install_dir, 'site-options.cfg'), 'w').write(
210
                string.Template(options_template).substitute({
211
                    'domain': self.domain, 
212
                    'options': self.site_options_cfg
213
                })
214
        )
222
                string.Template(options_template).substitute(vars))
215 223

  
216 224

  
217 225
    def make_apache_vhost(self):
218
-