def migrate_env(python, no_backup=False): """ Migrate Virtual Environment to desired Python Version. """ try: # 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)) except Exception: log.warn('Please ensure Redis Connections are running or Daemonized.') try: # 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! :| - <*****@*****.**> 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)) # 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) 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) pip = osp.join(pvenv, 'bin', 'pip') exec_cmd('{pip} install --upgrade pip'.format(pip=pip)) exec_cmd('{pip} install --upgrade setuptools'.format(pip=pip)) # TODO: Options papps = osp.join(path, 'apps') apps = ['frappe', 'erpnext'] + [ app for app in os.listdir(papps) if app not in ['frappe', 'erpnext'] ] for app in apps: papp = osp.join(papps, app) if osp.isdir(papp) and osp.exists(osp.join(papp, 'setup.py')): exec_cmd('{pip} install -e {app}'.format(pip=pip, app=papp)) log.debug('Migration Successful to {python}'.format(python=python)) except: log.debug('Migration Error') raise
def migrate_env(python, no_backup=False): """ Migrate Virtual Environment to desired Python Version. """ try: # 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! :| - <*****@*****.**> 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)) # 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) pip = osp.join(pvenv, 'bin', 'pip') exec_cmd('{pip} install --upgrade pip'.format(pip=pip)) exec_cmd('{pip} install --upgrade setuptools'.format(pip=pip)) # 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')): exec_cmd('{pip} install -e {app}'.format(pip=pip, app=papp)) log.debug('Migration Successful to {python}'.format(python=python)) except: log.debug('Migration Error') raise
def migrate_env(python, no_backup = False): """ Migrate Virtual Environment to desired Python Version. """ try: # 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)) except Exception: log.warn('Please ensure Redis Connections are running or Daemonized.') try: # 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! :| - <*****@*****.**> 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)) # 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) 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) pip = osp.join(pvenv, 'bin', 'pip') # pip 10 seems to have a few problems associated with it, temporary freeze pip at 9.0.3 exec_cmd('{pip} install --upgrade pip==9.0.3'.format(pip=pip)) exec_cmd('{pip} install --upgrade setuptools'.format(pip=pip)) # TODO: Options papps = osp.join(path, 'apps') apps = ['frappe', 'erpnext'] + [app for app in os.listdir(papps) if app not in ['frappe', 'erpnext']] for app in apps: papp = osp.join(papps, app) if osp.isdir(papp) and osp.exists(osp.join(papp, 'setup.py')): exec_cmd('{pip} install -e {app}'.format( pip = pip, app = papp )) log.debug('Migration Successful to {python}'.format( python = python )) except: log.debug('Migration Error') raise
def migrate_env(python, no_backup = False): """ Migrate Virtual Environment to desired Python Version. """ try: # 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! :| - <*****@*****.**> 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)) # 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) pip = osp.join(pvenv, 'bin', 'pip') exec_cmd('{pip} install --upgrade pip'.format(pip=pip)) exec_cmd('{pip} install --upgrade setuptools'.format(pip=pip)) # 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')): exec_cmd('{pip} install -e {app}'.format( pip = pip, app = papp )) log.debug('Migration Successful to {python}'.format( python = python )) except: log.debug('Migration Error') raise