From 1259b089c8c58230250971e478e20ddb9adeeb2c Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Sun, 9 Feb 2020 13:14:06 +0530 Subject: [PATCH] refactor: change "no_backup" variable and cleanup comments --- bench/commands/utils.py | 6 +++--- bench/utils.py | 16 ++++------------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/bench/commands/utils.py b/bench/commands/utils.py index 7e7d5d24..f2bac0af 100644 --- a/bench/commands/utils.py +++ b/bench/commands/utils.py @@ -202,8 +202,8 @@ def find_benches(location): @click.command('migrate-env') @click.argument('python', type=str) -@click.option('--no-backup', is_flag=True) -def migrate_env(python, no_backup=False): +@click.option('--no-backup', 'backup', is_flag=True, default=True) +def migrate_env(python, backup=True): """Migrate Virtual Environment to desired Python Version""" from bench.utils import migrate_env - migrate_env(python=python, no_backup=no_backup) + migrate_env(python=python, backup=backup) diff --git a/bench/utils.py b/bench/utils.py index 143b6b0b..fc7f4a1b 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -987,7 +987,7 @@ def in_virtual_env(): return False -def migrate_env(python, no_backup=False): +def migrate_env(python, backup=False): from bench.config.common_site_config import get_config from bench.app import get_apps @@ -1015,15 +1015,12 @@ def migrate_env(python, no_backup=False): except: log.warn('Please ensure Redis Connections are running or Daemonized.') - # I know, bad name for a flag. Thanks, Ameya! :| - - if not no_backup: - # Back, the f*ck up. + # Backup venv: restore using `virtualenv --relocatable` if needed + if backup: parch = os.path.join(path, 'archived_envs') if not os.path.exists(parch): os.mkdir(parch) - # Simply moving. Thanks, Ameya. - # I'm keen to zip. source = os.path.join(path, 'env') target = parch @@ -1031,17 +1028,12 @@ def migrate_env(python, no_backup=False): stamp = datetime.now().strftime('%Y%m%d_%H%M%S') dest = os.path.join(path, str(stamp)) - # 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) shutil.move(dest, target) + # Create virtualenv using specified python try: log.debug('Setting up a New Virtual {} Environment'.format(python)) - exec_cmd('{virtualenv} --python {python} {pvenv}'.format(virtualenv=virtualenv, python=python, pvenv=pvenv)) apps = ' '.join(["-e {}".format(os.path.join("apps", app)) for app in get_apps()])