2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-24 23:48:24 +00:00

updated migrate-env

This commit is contained in:
Achilles Rasquinha 2018-02-05 18:42:29 +05:30
parent 300c3eea08
commit 0de8bf0ea7

View File

@ -102,6 +102,17 @@ def tempdir():
with tempchdir(dirpath, cleanup):
yield dirpath
def copytree(source, destination, symlinks = False, ignore = None):
for f in os.listdir(source):
s = os.path.join(source, f)
d = os.path.join(destination, f)
if os.path.isdir(s):
shutil.copytree(s, d, symlinks, ignore)
else:
shutil.copy2(s, d)
@click.command('migrate-env')
@click.argument('python', type = click.Choice(['python2', 'python3']))
@click.option('--no-backup', default = False, help = 'Do not backup the existing Virtual Environment')
@ -109,62 +120,65 @@ def migrate_env(python, no_backup = False):
"""
Migrate Virtual Environment to desired Python Version.
"""
python = which(python)
path = os.getcwd()
# This is with the assumption that a bench is set-up within path.
try:
with tempdir() as dirpath:
virtualenv = which('virtualenv')
# This is with the assumption that a bench is set-up within path.
path = os.getcwd()
# I know, bad name for a flag. Thanks, Ameya! :| - <achilles@frappe.io>
if not no_backup:
# Back, the f*ck up.
parch = osp.join(path, 'archived_envs')
if not osp.exists(parch):
os.mkdir(parch)
nvenv = 'env'
pvenv = osp.join(dirpath, nvenv)
# Simply moving. Thanks, Ameya.
# I'm keen to zip.
source = osp.join(path, 'env')
target = parch
exec_cmd('{virtualenv} --python {python} {pvenv}'.format(
virtualenv = virtualenv,
python = python,
pvenv = pvenv
), cwd = dirpath)
# TODO: Options
papps = osp.join(path, 'apps')
for app in os.listdir(papps):
papp = osp.join(papps, app)
if osp.isdir(papp) and osp.exists(osp.join(papp, 'setup.py')):
pip = osp.join(pvenv, 'bin', 'pip')
exec_cmd('{pip} install -e {app}'.format(
pip = pip, app = papp
))
# I know, bad name for a flag. Thanks, Ameya! :| - <achilles@frappe.io>
if not no_backup:
# Back, the f*ck up.
parch = osp.join(path, 'archived_envs')
if not osp.exists(parch):
os.mkdir(parch)
# Simply moving. Thanks, Ameya.
# I'm keen to zip.
source = osp.join(path, 'env')
target = parch
log.debug('Backing up Virtual Environment')
stamp = datetime.now().strftime('%Y%m%d_%H%M%S')
dest = osp.join(path, str(stamp))
os.rename(source, dest)
shutil.move(dest, target)
log.debug('Backing up Virtual Environment')
stamp = datetime.now().strftime('%Y%m%d_%H%M%S')
dest = osp.join(path, str(stamp))
log.debug('Setting up a New Virtual {python} Environment'.format(
python = python
))
source = pvenv
target = path
shutil.move(source, target)
# WARNING: This is an archive, you might have to use virtualenv --relocate
# That's because virtualenv creates symlinks with shebangs pointing to executables.
# ...and shutil.copytree is a f*cking mess.
os.rename(source, dest)
shutil.move(dest, target)
log.debug('Setting up a New Virtual {python} Environment'.format(
python = python
))
# Path to Python Executable (Basically $PYTHONPTH)
python = which(python)
virtualenv = which('virtualenv')
nvenv = 'env'
pvenv = osp.join(path, nvenv)
exec_cmd('{virtualenv} --python {python} {pvenv}'.format(
virtualenv = virtualenv,
python = python,
pvenv = pvenv
), cwd = path)
# TODO: Options
papps = osp.join(path, 'apps')
apps = ['frappe'] + [app for app in os.listdir(papps) if app != 'frappe']
for app in apps:
papp = osp.join(papps, app)
if osp.isdir(papp) and osp.exists(osp.join(papp, 'setup.py')):
pip = osp.join(pvenv, 'bin', 'pip')
exec_cmd('{pip} install -e {app}'.format(
pip = pip, app = papp
))
log.debug('Migration Successful to {python}'.format(
python = python
))