From 012be92f0963c1cea60948fada3a30a2b069ea8e Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 5 Jul 2016 19:08:19 +0530 Subject: [PATCH] [command] bench config set-common-config / remove-common-config bench config set-common-config --config KEY1 VAL1 --config KEY2 VAL2 ... bench config remove-common-config KEY1 KEY2 ... --- bench/commands/config.py | 51 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/bench/commands/config.py b/bench/commands/config.py index b50a1f71..7804d7b5 100644 --- a/bench/commands/config.py +++ b/bench/commands/config.py @@ -1,4 +1,4 @@ -import click +import click, json from bench.config.common_site_config import update_config ## Config @@ -8,7 +8,6 @@ def config(): "change bench configuration" pass - @click.command('auto_update') @click.argument('state', type=click.Choice(['on', 'off'])) def config_auto_update(state): @@ -64,9 +63,57 @@ def config_http_timeout(seconds): update_config({'http_timeout': seconds}) +@click.command('set-common-config') +@click.option('configs', '-c', '--config', multiple=True, type=(unicode, unicode)) +def set_common_config(configs): + import ast + from bench.config.common_site_config import update_config + + common_site_config = {} + for key, value in configs: + if value in ("False", "True"): + value = ast.literal_eval(value) + + elif "." in value: + try: + value = float(value) + except ValueError: + pass + + elif "{" in value or "[" in value: + try: + value = json.loads(value) + except ValueError: + pass + + else: + try: + value = int(value) + except ValueError: + pass + + common_site_config[key] = value + + update_config(common_site_config, bench_path='.') + + +@click.command('remove-common-config') +@click.argument('keys', nargs=-1) +def remove_common_config(keys): + from bench.config.common_site_config import get_config, put_config + common_site_config = get_config('.') + for key in keys: + if key in common_site_config: + del common_site_config[key] + + put_config(common_site_config) + + config.add_command(config_auto_update) config.add_command(config_update_bench_on_update) config.add_command(config_restart_supervisor_on_update) config.add_command(config_dns_multitenant) config.add_command(config_serve_default_site) config.add_command(config_http_timeout) +config.add_command(set_common_config) +config.add_command(remove_common_config)