From 2ccf88a731190a92fdf4215540e567462484b13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 31 Oct 2013 14:27:34 +0100 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(-) diff --git a/wcsinst/wcsinstd/deploy.py b/wcsinst/wcsinstd/deploy.py index b4a7244..2146ddc 100644 --- a/wcsinst/wcsinstd/deploy.py +++ b/wcsinst/wcsinstd/deploy.py @@ -18,6 +18,15 @@ from . import app_settings def get_provider_key(provider_id): return provider_id.replace('://', '-').replace('/', '-').replace('?', '-').replace(':', '-') +def flatten_dict(d): + for k, v in d.items(): + if type(v) is dict: + flatten_dict(v) + for k2, v2 in v.items(): + d['%s_%s' % (k, k2)] = v2 + del d[k] + return d + class DeployInstance(object): skeleton = 'default' @@ -206,12 +215,11 @@ class DeployInstance(object): if not os.path.exists(options_template_path): return options_template = file(options_template_path).read() + vars = {'domain': self.domain} + if self.site_options_cfg: + vars.update(flatten_dict(self.site_options_cfg)) file(os.path.join(self.collectivity_install_dir, 'site-options.cfg'), 'w').write( - string.Template(options_template).substitute({ - 'domain': self.domain, - 'options': self.site_options_cfg - }) - ) + string.Template(options_template).substitute(vars)) def make_apache_vhost(self): -- 1.8.4.2