2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-11 15:51:03 +00:00

Merge pull request #606 from frappe/clear-redis-cache

clear-redis-cache
This commit is contained in:
Achilles Rasquinha 2018-03-23 20:39:17 +05:30 committed by GitHub
commit 84c5719bc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,7 +9,7 @@ from datetime import datetime
from bench.utils import which, exec_cmd from bench.utils import which, exec_cmd
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
log.setLevel(logging.ERROR) log.setLevel(logging.DEBUG)
def print_bench_version(ctx, param, value): def print_bench_version(ctx, param, value):
"""Prints current bench version""" """Prints current bench version"""
@ -82,6 +82,12 @@ bench_command.add_command(remote_urls)
from bench.commands.install import install from bench.commands.install import install
bench_command.add_command(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.command('migrate-env')
@click.argument('python', type = str) @click.argument('python', type = str)
@click.option('--no-backup', default = False, help = 'Do not backup the existing Virtual Environment') @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. 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: try:
# This is with the assumption that a bench is set-up within path. # This is with the assumption that a bench is set-up within path.
path = os.getcwd() 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 # WARNING: This is an archive, you might have to use virtualenv --relocate
# That's because virtualenv creates symlinks with shebangs pointing to executables. # That's because virtualenv creates symlinks with shebangs pointing to executables.
# shebangs, shebangs - ricky martin.
# ...and shutil.copytree is a f*cking mess. # ...and shutil.copytree is a f*cking mess.
os.rename(source, dest) os.rename(source, dest)