From 9cc3c4492b32a3bd58c6d6e51b1dee32767f13b4 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Fri, 7 Nov 2014 20:19:13 +0530 Subject: [PATCH] add set-mariadb-host --- bench/cli.py | 10 +++++++++- bench/utils.py | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/bench/cli.py b/bench/cli.py index 61fd246b..5d894d2c 100644 --- a/bench/cli.py +++ b/bench/cli.py @@ -8,10 +8,11 @@ from .utils import setup_sudoers as _setup_sudoers from .utils import start as _start from .utils import setup_procfile as _setup_procfile from .utils import set_nginx_port as _set_nginx_port +from .utils import set_nginx_port as _set_nginx_port from .utils import set_default_site as _set_default_site from .utils import (build_assets, patch_sites, exec_cmd, update_bench, get_frappe, setup_logging, get_config, update_config, restart_supervisor_processes, put_config, default_config, update_requirements, - backup_all_sites, backup_site, get_sites, prime_wheel_cache, is_root) + backup_all_sites, backup_site, get_sites, prime_wheel_cache, is_root, set_mariadb_host) from .app import get_app as _get_app from .app import new_app as _new_app from .app import pull_all_apps @@ -196,6 +197,12 @@ def set_nginx_port(site, port): "Set nginx port for site" _set_nginx_port(site, port) +@click.command('set-mariadb-host') +@click.argument('host') +def _set_mariadb_host(host): + "Set MariaDB host for bench" + set_mariadb_host(host) + @click.command('set-default-site') @click.argument('site') def set_default_site(site): @@ -384,6 +391,7 @@ bench.add_command(restart) bench.add_command(config) bench.add_command(start) bench.add_command(set_nginx_port) +bench.add_command(_set_mariadb_host) bench.add_command(set_default_site) bench.add_command(migrate_3to4) bench.add_command(shell) diff --git a/bench/utils.py b/bench/utils.py index 7cd121a2..6c68ebf5 100644 --- a/bench/utils.py +++ b/bench/utils.py @@ -279,3 +279,17 @@ def is_root(): if os.getuid() == 0: return True return False + +def set_mariadb_host(host, bench='.'): + update_common_site_config({'db_host': host}, bench=bench) + +def update_common_site_config(ddict, bench='.'): + update_json_file(os.path.join(bench, 'sites', 'common_site_config.json'), ddict) + +def update_json_file(filename, ddict): + with open(filename, 'r') as f: + content = json.load(f) + content.update(ddict) + with open(filename, 'w') as f: + content = json.dump(content, f, indent=1) +