# Path: cloudbio/fabutils.py
# SUDO_ENV_KEEPS = []  # Environment variables passed through to sudo environment when using local sudo.
# def local_exists(path, use_sudo=False):
# def run_local(use_sudo=False, capture=False):
#     def _run(command, *args, **kwags):
# def local_put(orig_file, new_file):
# def local_sed(filename, before, after, limit='', use_sudo=False, backup='.bak',
#               flags='', shell=False):
# def local_comment(filename, regex, use_sudo=False, char='#', backup='.bak', shell=False):
# def _escape_for_regex(text):
# def _expand_path(path):
# def local_contains(filename, text, exact=False, use_sudo=False, escape=True,
#     shell=False):
# def local_append(filename, text, use_sudo=False, partial=False, escape=True, shell=False):
# def run_output(*args, **kwargs):
# def configure_runsudo(env):
# def find_cmd(env, cmd, args):
#     def quiet():
#     def warn_only():
# 
# Path: cloudbio/custom/shared.py
# CBL_REPO_ROOT_URL = "https://raw.github.com/chapmanb/cloudbiolinux/master/"
# def chdir(new_dir):
# def safe_makedir(dname):
# def which(program, env=None):
#     def is_exe(fpath):
# def _if_not_installed(pname):
#     def argcatcher(func):
#         def decorator(*args, **kwargs):
# def _all_cbl_paths(env, ext):
# def _executable_not_on_path(pname):
# def _galaxy_tool_install(args):
# def _galaxy_tool_present(args):
# def _if_not_python_lib(library):
#     def argcatcher(func):
#         def decorator(*args, **kwargs):
# def make_tmp_dir_local(ext, work_dir):
# def _make_tmp_dir(ext=None, work_dir=None):
# def __work_dir():
# def _get_expected_file(url, dir_name=None, safe_tar=False, tar_file_name=None):
# def _safe_dir_name(dir_name, need_dir=True):
# def _remote_fetch(env, url, out_file=None, allow_fail=False, fix_fn=None, samedir=False):
# def _fetch_and_unpack(url, need_dir=True, dir_name=None, revision=None,
#                       safe_tar=False, tar_file_name=None):
# def _configure_make(env):
# def _ac_configure_make(env):
# def _make_copy(find_cmd=None, premake_cmd=None, do_make=True):
#     def _do_work(env):
# def _get_install(url, env, make_command, post_unpack_fn=None, revision=None, dir_name=None,
#                  safe_tar=False, tar_file_name=None):
# def _apply_patch(env, url):
# def _get_install_local(url, env, make_command, dir_name=None,
#                        post_unpack_fn=None, safe_tar=False, tar_file_name=None):
# def _symlinked_install_dir(pname, version, env, extra_dir=None):
# def _symlinked_dir_exists(pname, version, env, extra_dir=None):
# def _symlinked_shared_dir(pname, version, env, extra_dir=None):
# def _symlinked_java_version_dir(pname, version, env):
# def _java_install(pname, version, url, env, install_fn=None,
#                   pre_fetch_fn=None):
# def _python_cmd(env):
# def _pip_cmd(env):
# def _conda_cmd(env):
# def _is_anaconda(env):
# def _python_make(env):
# def _get_installed_file(env, local_file):
# def _get_installed_file_contents(env, local_file):
# def _write_to_file(contents, path, mode):
# def _get_bin_dir(env):
# def _get_include_dir(env):
# def _get_lib_dir(env):
# def _get_install_subdir(env, subdir):
# def _set_default_config(env, install_dir, sym_dir_name="default"):
# def _setup_simple_service(service_name):
# def _render_config_file_template(env, name, defaults={}, overrides={}, default_source=None):
# def _extend_env(env, defaults={}, overrides={}):
# def _setup_conf_file(env, dest, name, defaults={}, overrides={}, default_source=None, mode="0755"):
# def _add_to_profiles(line, profiles=[], use_sudo=True):
# def install_venvburrito():
# def _create_python_virtualenv(env, venv_name, reqs_file=None, reqs_url=None):
#     def create():
# def _create_local_python_virtualenv(env, venv_name, reqs_file, reqs_url):
# def _create_global_python_virtualenv(env, venv_name, reqs_file, reqs_url):
# def _get_bitbucket_download_url(revision, default_repo):
# def _read_boolean(env, name, default):


import os
from fabric.api import env, cd, settings
from cloudbio import fabutils
from cloudbio.custom import shared
"""Installers for programming language specific libraries.
"""


def r_library_installer(config):
    """Install R libraries using CRAN and Bioconductor.
    """
    if config.get("cran") or config.get("bioc") or config.get("github"):
        with shared._make_tmp_dir() as tmp_dir:
            with cd(tmp_dir):
                # Create an Rscript file with install details.
                out_file = os.path.join(tmp_dir, "install_packages.R")
                _make_install_script(out_file, config)
                # run the script and then get rid of it
                # try using either
                rlib_installed = False
                rscripts = []
                conda_bin = shared._conda_cmd(env)
                if conda_bin:
                    rscripts.append(fabutils.find_cmd(env, os.path.join(os.path.dirname(conda_bin), "Rscript"),
                                                    "--version"))

# Path: cloudbio/fabutils.py
# SUDO_ENV_KEEPS = []  # Environment variables passed through to sudo environment when using local sudo.
# def local_exists(path, use_sudo=False):
# def run_local(use_sudo=False, capture=False):
#     def _run(command, *args, **kwags):
# def local_put(orig_file, new_file):
# def local_sed(filename, before, after, limit='', use_sudo=False, backup='.bak',
#               flags='', shell=False):
# def local_comment(filename, regex, use_sudo=False, char='#', backup='.bak', shell=False):
# def _escape_for_regex(text):
# def _expand_path(path):
# def local_contains(filename, text, exact=False, use_sudo=False, escape=True,
#     shell=False):
# def local_append(filename, text, use_sudo=False, partial=False, escape=True, shell=False):
# def run_output(*args, **kwargs):
# def configure_runsudo(env):
# def find_cmd(env, cmd, args):
#     def quiet():
#     def warn_only():
# 
# Path: cloudbio/custom/shared.py
# CBL_REPO_ROOT_URL = "https://raw.github.com/chapmanb/cloudbiolinux/master/"
# def chdir(new_dir):
# def safe_makedir(dname):
# def which(program, env=None):
#     def is_exe(fpath):
# def _if_not_installed(pname):
#     def argcatcher(func):
#         def decorator(*args, **kwargs):
# def _all_cbl_paths(env, ext):
# def _executable_not_on_path(pname):
# def _galaxy_tool_install(args):
# def _galaxy_tool_present(args):
# def _if_not_python_lib(library):
#     def argcatcher(func):
#         def decorator(*args, **kwargs):
# def make_tmp_dir_local(ext, work_dir):
# def _make_tmp_dir(ext=None, work_dir=None):
# def __work_dir():
# def _get_expected_file(url, dir_name=None, safe_tar=False, tar_file_name=None):
# def _safe_dir_name(dir_name, need_dir=True):
# def _remote_fetch(env, url, out_file=None, allow_fail=False, fix_fn=None, samedir=False):
# def _fetch_and_unpack(url, need_dir=True, dir_name=None, revision=None,
#                       safe_tar=False, tar_file_name=None):
# def _configure_make(env):
# def _ac_configure_make(env):
# def _make_copy(find_cmd=None, premake_cmd=None, do_make=True):
#     def _do_work(env):
# def _get_install(url, env, make_command, post_unpack_fn=None, revision=None, dir_name=None,
#                  safe_tar=False, tar_file_name=None):
# def _apply_patch(env, url):
# def _get_install_local(url, env, make_command, dir_name=None,
#                        post_unpack_fn=None, safe_tar=False, tar_file_name=None):
# def _symlinked_install_dir(pname, version, env, extra_dir=None):
# def _symlinked_dir_exists(pname, version, env, extra_dir=None):
# def _symlinked_shared_dir(pname, version, env, extra_dir=None):
# def _symlinked_java_version_dir(pname, version, env):
# def _java_install(pname, version, url, env, install_fn=None,
#                   pre_fetch_fn=None):
# def _python_cmd(env):
# def _pip_cmd(env):
# def _conda_cmd(env):
# def _is_anaconda(env):
# def _python_make(env):
# def _get_installed_file(env, local_file):
# def _get_installed_file_contents(env, local_file):
# def _write_to_file(contents, path, mode):
# def _get_bin_dir(env):
# def _get_include_dir(env):
# def _get_lib_dir(env):
# def _get_install_subdir(env, subdir):
# def _set_default_config(env, install_dir, sym_dir_name="default"):
# def _setup_simple_service(service_name):
# def _render_config_file_template(env, name, defaults={}, overrides={}, default_source=None):
# def _extend_env(env, defaults={}, overrides={}):
# def _setup_conf_file(env, dest, name, defaults={}, overrides={}, default_source=None, mode="0755"):
# def _add_to_profiles(line, profiles=[], use_sudo=True):
# def install_venvburrito():
# def _create_python_virtualenv(env, venv_name, reqs_file=None, reqs_url=None):
#     def create():
# def _create_local_python_virtualenv(env, venv_name, reqs_file, reqs_url):
# def _create_global_python_virtualenv(env, venv_name, reqs_file, reqs_url):
# def _get_bitbucket_download_url(revision, default_repo):
# def _read_boolean(env, name, default):


# Path: cloudbio/libraries.py
import os
from fabric.api import env, cd, settings
from cloudbio import fabutils
from cloudbio.custom import shared

"""Installers for programming language specific libraries.
"""


def r_library_installer(config):
    """Install R libraries using CRAN and Bioconductor.
    """
    if config.get("cran") or config.get("bioc") or config.get("github"):
        with shared._make_tmp_dir() as tmp_dir:
            with cd(tmp_dir):
                # Create an Rscript file with install details.
                out_file = os.path.join(tmp_dir, "install_packages.R")
                _make_install_script(out_file, config)
                # run the script and then get rid of it
                # try using either
                rlib_installed = False
                rscripts = []
                conda_bin = shared._conda_cmd(env)
                if conda_bin:
                    rscripts.append(fabutils.find_cmd(env, os.path.join(os.path.dirname(conda_bin), "Rscript"),
                                                    "--version"))

                rscripts.append(fabutils.find_cmd(env, "Rscript", "--version"))