Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
103 lines (80 sloc) 2.96 KB
#!/usr/bin/env python
import os
import sys
PAYPAL_BIN = '/x/opt/pp/bin/'
# /usr/bin/env python in some environments is 2.4 and we support only
# python version >= 2.6. so if we're in paypal, go ahead and re-exec
# as the right version
if sys.version_info < (2, 6, 0):
path = os.path.join(PAYPAL_BIN, 'python')
os.execl(path, path, *sys.argv)
import glob
import errno
import shutil
import subprocess
from os.path import abspath, dirname, join as pjoin
TARGET_BASE_DIR = '/x/web/LIVE/'
TARGET_DIR = pjoin(TARGET_BASE_DIR, 'anaconda2/')
TARGET_OLD_DIR = pjoin(TARGET_BASE_DIR, 'anaconda2_old/')
CUR_DIR = dirname(abspath(__file__))
BASE_PKG_DIR = dirname(dirname(CUR_DIR))
CONDA_ARCHIVES_DIR = pjoin(BASE_PKG_DIR, 'archives')
PATCHELF_PKG_PATH = glob.glob(pjoin(CONDA_ARCHIVES_DIR, 'patchelf*.bz2'))[0]
ALL_PKG_PATHS = glob.glob(pjoin(CONDA_ARCHIVES_DIR, '*.bz2'))
MINICONDA_SH_FN = 'Miniconda-latest-Linux-x86_64.sh'
MINICONDA_SH_PATH = pjoin(BASE_PKG_DIR, MINICONDA_SH_FN)
CONDA_PATH = pjoin(TARGET_DIR, 'bin', 'conda')
def shexec(args):
print '+executing %r' % (args,)
return subprocess.check_output(args)
def install_conda_and_packages():
shexec(['bash', MINICONDA_SH_PATH, '-b', '-f', '-p', TARGET_DIR])
shexec([CONDA_PATH, 'install', '-f', '-y', '--offline', PATCHELF_PKG_PATH])
# TODO: readline
cmd = [CONDA_PATH, 'install', '-f', '-y', '--offline'] + ALL_PKG_PATHS
shexec(cmd)
return
def main():
restore_old_on_exc = False
if os.path.exists(TARGET_DIR):
if not os.path.isdir(TARGET_DIR):
raise RuntimeError('target path exists and is not directory: %r'
% TARGET_DIR)
print ('existing anaconda installation found, moving from %r to %r'
% (TARGET_DIR, TARGET_OLD_DIR))
if os.path.exists(TARGET_OLD_DIR):
shutil.rmtree(TARGET_OLD_DIR)
os.rename(TARGET_DIR, TARGET_OLD_DIR)
restore_old_on_exc = True
mkdir_p(TARGET_DIR)
try:
install_conda_and_packages()
finally:
if restore_old_on_exc:
try:
try:
shutil.rmtree(TARGET_DIR)
except Exception:
pass # might not exist somehow
os.rename(TARGET_OLD_DIR, TARGET_DIR)
except Exception:
import traceback
print '!! -- unable to restore old anaconda to %r' % TARGET_DIR
traceback.print_exc()
return
def mkdir_p(path):
"""Creates a directory and any parent directories that may need to
be created along the way, without raising errors for any existing
directories. This function mimics the behavior of the ``mkdir -p``
command available in Linux/BSD environments, but also works on
Windows.
"""
try:
os.makedirs(path)
except OSError, exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
return
raise
return
if __name__ == '__main__':
main()