def install_conda(conda_context, force_conda_build=False): f, script_path = tempfile.mkstemp(suffix=".sh", prefix="conda_install") os.close(f) download_cmd = commands.download_command(conda_link(), to=script_path) install_cmd = ['bash', script_path, '-b', '-p', conda_context.conda_prefix] package_targets = [ "conda=%s" % CONDA_VERSION, ] if force_conda_build or conda_context.use_local: package_targets.append("conda-build=%s" % CONDA_BUILD_VERSION) log.info("Installing conda, this may take several minutes.") try: exit_code = conda_context.shell_exec(download_cmd) if exit_code: return exit_code exit_code = conda_context.shell_exec(install_cmd) except Exception: log.exception('Failed to install conda') return 1 finally: if os.path.exists(script_path): os.remove(script_path) if exit_code: return exit_code return conda_context.exec_install(package_targets, allow_local=False)
def install_involucro(involucro_context): install_path = os.path.abspath(involucro_context.involucro_bin) involucro_context.involucro_bin = install_path download_cmd = commands.download_command(involucro_link(), to=install_path) exit_code = involucro_context.shell_exec(download_cmd) if exit_code: return exit_code try: os.chmod(install_path, os.stat(install_path).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) return 0 except Exception: log.exception("Failed to make file '%s' executable", install_path) return 1
def untar_to(url, tar_args=None, path=None, dest_dir=None): if tar_args: assert not (path and dest_dir) if dest_dir: if not os.path.exists(dest_dir): os.makedirs(dest_dir) tar_args[0:0] = ['-C', dest_dir] if path: tar_args.insert(0, '-O') download_cmd = download_command(url) download_p = commands.shell_process(download_cmd, stdout=subprocess.PIPE) untar_cmd = ['tar'] + tar_args if path: with open(path, 'wb') as fh: shell(untar_cmd, stdin=download_p.stdout, stdout=fh) else: shell(untar_cmd, stdin=download_p.stdout) download_p.wait() else: cmd = download_command(url, to=path) shell(cmd)