From be9327ba3e56502a0830b629c87d2724c7118d84 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Fri, 23 Mar 2018 20:38:27 +0530 Subject: [PATCH] clear-redis-cache --- bench/commands/__init__.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index e4ecb8c3..bcc76d6b 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -9,7 +9,7 @@ from datetime import datetime from bench.utils import which, exec_cmd log = logging.getLogger(__name__) -log.setLevel(logging.ERROR) +log.setLevel(logging.DEBUG) def print_bench_version(ctx, param, value): """Prints current bench version""" @@ -82,6 +82,12 @@ bench_command.add_command(remote_urls) from bench.commands.install import install bench_command.add_command(install) +from bench.config.common_site_config import get_config +try: + from urlparse import urlparse +except ImportError: + from urllib.parse import urlparse + @click.command('migrate-env') @click.argument('python', type = str) @click.option('--no-backup', default = False, help = 'Do not backup the existing Virtual Environment') @@ -89,6 +95,20 @@ def migrate_env(python, no_backup = False): """ Migrate Virtual Environment to desired Python Version. """ + # Clear Cache before Bench Dies. + config = get_config(bench_path = os.getcwd()) + rredis = urlparse(config['redis_cache']) + + redis = '{redis} -p {port}'.format( + redis = which('redis-cli'), + port = rredis.port + ) + + log.debug('Clearing Redis Cache...') + exec_cmd('{redis} FLUSHALL'.format(redis = redis)) + log.debug('Clearing Redis DataBase...') + exec_cmd('{redis} FLUSHDB'.format(redis = redis)) + try: # This is with the assumption that a bench is set-up within path. path = os.getcwd() @@ -111,6 +131,7 @@ def migrate_env(python, no_backup = False): # WARNING: This is an archive, you might have to use virtualenv --relocate # That's because virtualenv creates symlinks with shebangs pointing to executables. + # shebangs, shebangs - ricky martin. # ...and shutil.copytree is a f*cking mess. os.rename(source, dest)