# Path: cloudbio/custom/shared.py
# def _set_default_config(env, install_dir, sym_dir_name="default"):
#     """
#     Sets up default galaxy config directory symbolic link (if needed). Needed
#     when it doesn't exists or when installing a new version of software.
#     """
#     version = env["tool_version"]
#     if env.safe_exists(install_dir):
#         install_dir_root = "%s/.." % install_dir
#         sym_dir = "%s/%s" % (install_dir_root, sym_dir_name)
#         replace_default = False
#         if not env.safe_exists(sym_dir):
#             replace_default = True
#         if not replace_default:
#             default_version = env.safe_sudo("basename `readlink -f %s`" % sym_dir)
#             if version > default_version:  # Bug: Wouldn't work for 1.9 < 1.10
#                 print("default version %s is older than version %s just installed, replacing..." % (default_version, version))
#                 replace_default = True
#         if replace_default:
#             env.safe_sudo("rm -rf %s; ln -f -s %s %s" % (sym_dir, install_dir, sym_dir))
# 
# def _add_to_profiles(line, profiles=[], use_sudo=True):
#     """
#     If it's not already there, append ``line`` to shell profiles files.
#     By default, these are ``/etc/profile`` and ``/etc/bash.bashrc`` but can be
#     overridden by providing a list of file paths to the ``profiles`` argument.
#     """
#     if not profiles:
#         profiles = ['/etc/bash.bashrc', '/etc/profile']
#     for profile in profiles:
#         if not env.safe_contains(profile, line):
#             env.safe_append(profile, line, use_sudo=use_sudo)


import os
import six
import yaml
from string import Template
from cloudbio.custom.bio_general import *
from cloudbio.custom.bio_nextgen import *
from cloudbio.custom.bio_proteomics import *
from cloudbio.custom.shared import _set_default_config, _add_to_profiles
from cloudbio.galaxy.applications import *
from cloudbio.galaxy.r import _install_r_packages
from cloudbio.galaxy.utils import _chown_galaxy, _read_boolean

    TODO: Rename versions and document options.
    """
    if type(versions) is str:
        versions = [versions]
    for version_info in versions:
        if type(version_info) is str:
            _install_tool(env, name, version=version_info, requirement_name=name, tool_install_dir=tool_install_dir)
        else:
            version = version_info["version"]
            bin_dirs = version_info.get("bin_dirs", ["bin"])
            env_vars = version_info.get("env_vars", {})
            provides = version_info.get("provides", [])
            if isinstance(provides, (str, unicode, six.string_types)):
                provides = [provides]
            for provide_conf in provides[:]:
                if isinstance(provide_conf, dict):
                    provides.remove(provide_conf)
                    if __check_conditional(provide_conf):
                        provies.append(provide_conf["name"])

            # Some requirements (e.g. blast+) maybe not have valid python
            # identifiers as name. Use install_blast to setup but override
            # requirement directory name with requirement_name field.
            requirement_name = version_info.get("requirement_name", name)
            tool_env = _install_tool(env, name, version, bin_dirs=bin_dirs, env_vars=env_vars, requirement_name=requirement_name, tool_install_dir=tool_install_dir)
            symlink_versions = version_info.get("symlink_versions", [])
            if type(symlink_versions) is str:
                symlink_versions = [symlink_versions]
            for symlink_version in symlink_versions:

# Path: cloudbio/custom/shared.py
# def _set_default_config(env, install_dir, sym_dir_name="default"):
#     """
#     Sets up default galaxy config directory symbolic link (if needed). Needed
#     when it doesn't exists or when installing a new version of software.
#     """
#     version = env["tool_version"]
#     if env.safe_exists(install_dir):
#         install_dir_root = "%s/.." % install_dir
#         sym_dir = "%s/%s" % (install_dir_root, sym_dir_name)
#         replace_default = False
#         if not env.safe_exists(sym_dir):
#             replace_default = True
#         if not replace_default:
#             default_version = env.safe_sudo("basename `readlink -f %s`" % sym_dir)
#             if version > default_version:  # Bug: Wouldn't work for 1.9 < 1.10
#                 print("default version %s is older than version %s just installed, replacing..." % (default_version, version))
#                 replace_default = True
#         if replace_default:
#             env.safe_sudo("rm -rf %s; ln -f -s %s %s" % (sym_dir, install_dir, sym_dir))
# 
# def _add_to_profiles(line, profiles=[], use_sudo=True):
#     """
#     If it's not already there, append ``line`` to shell profiles files.
#     By default, these are ``/etc/profile`` and ``/etc/bash.bashrc`` but can be
#     overridden by providing a list of file paths to the ``profiles`` argument.
#     """
#     if not profiles:
#         profiles = ['/etc/bash.bashrc', '/etc/profile']
#     for profile in profiles:
#         if not env.safe_contains(profile, line):
#             env.safe_append(profile, line, use_sudo=use_sudo)


# Path: cloudbio/galaxy/tools.py
import os
import six
import yaml
from string import Template
from cloudbio.custom.bio_general import *
from cloudbio.custom.bio_nextgen import *
from cloudbio.custom.bio_proteomics import *
from cloudbio.custom.shared import _set_default_config, _add_to_profiles
from cloudbio.galaxy.applications import *
from cloudbio.galaxy.r import _install_r_packages
from cloudbio.galaxy.utils import _chown_galaxy, _read_boolean


    TODO: Rename versions and document options.
    """
    if type(versions) is str:
        versions = [versions]
    for version_info in versions:
        if type(version_info) is str:
            _install_tool(env, name, version=version_info, requirement_name=name, tool_install_dir=tool_install_dir)
        else:
            version = version_info["version"]
            bin_dirs = version_info.get("bin_dirs", ["bin"])
            env_vars = version_info.get("env_vars", {})
            provides = version_info.get("provides", [])
            if isinstance(provides, (str, unicode, six.string_types)):
                provides = [provides]
            for provide_conf in provides[:]:
                if isinstance(provide_conf, dict):
                    provides.remove(provide_conf)
                    if __check_conditional(provide_conf):
                        provies.append(provide_conf["name"])

            # Some requirements (e.g. blast+) maybe not have valid python
            # identifiers as name. Use install_blast to setup but override
            # requirement directory name with requirement_name field.
            requirement_name = version_info.get("requirement_name", name)
            tool_env = _install_tool(env, name, version, bin_dirs=bin_dirs, env_vars=env_vars, requirement_name=requirement_name, tool_install_dir=tool_install_dir)
            symlink_versions = version_info.get("symlink_versions", [])
            if type(symlink_versions) is str:
                symlink_versions = [symlink_versions]
            for symlink_version in symlink_versions:

                _set_default_config(tool_env, tool_env["system_install"], symlink_version)