# Path: cloudbio/fabutils.py
# def quiet():
#     return settings(hide('warnings', 'running', 'stdout', 'stderr'), warn_only=True)
# 
# Path: cloudbio/fabutils.py
# def configure_runsudo(env):
#     """Setup env variable with safe_sudo and safe_run,
#     supporting non-privileged users and local execution.
#     """
#     env.is_local = env.hosts == ["localhost"]
#     if env.is_local:
#         env.safe_put = local_put
#         env.safe_sed = local_sed
#         env.safe_comment = local_comment
#         env.safe_contains = local_contains
#         env.safe_append = local_append
#         env.safe_exists = local_exists
#         env.safe_run = run_local()
#         env.safe_run_output = run_local(capture=True)
#     else:
#         env.safe_put = put
#         env.safe_sed = sed
#         env.safe_comment = comment
#         env.safe_contains = contains
#         env.safe_append = append
#         env.safe_exists = exists
#         env.safe_run = run
#         env.safe_run_output = run_output
#     if isinstance(getattr(env, "use_sudo", "true"), six.string_types):
#         if getattr(env, "use_sudo", "true").lower() in ["true", "yes"]:
#             env.use_sudo = True
#             if env.is_local:
#                 env.safe_sudo = run_local(True)
#             else:
#                 env.safe_sudo = sudo
#         else:
#             env.use_sudo = False
#             if env.is_local:
#                 env.safe_sudo = run_local()
#             else:
#                 env.safe_sudo = run


import os
import subprocess
from fabric.api import env
from cloudbio.fabutils import quiet
from cloudbio.fabutils import configure_runsudo
from cloudbio.custom import system
    env.std_sources = _add_source_versions(env.dist_name, sources)


def _setup_debian():
    env.logger.info("Debian setup")
    unstable_remap = {"sid": "squeeze"}
    shared_sources = _setup_deb_general()
    sources = [
        "deb http://cran.fhcrc.org/bin/linux/debian %s-cran/",  # lastest R versions
        "deb http://nebc.nerc.ac.uk/bio-linux/ unstable bio-linux",  # Bio-Linux
        ] + shared_sources
    # fill in %s
    dist_name = unstable_remap.get(env.dist_name, env.dist_name)
    env.std_sources = _add_source_versions(dist_name, sources)


def _setup_deb_general():
    """Shared settings for different debian based/derived distributions.
    """
    env.logger.debug("Debian-shared setup")
    env.sources_file = "/etc/apt/sources.list.d/cloudbiolinux.list"
    env.global_sources_file = "/etc/apt/sources.list"
    env.apt_preferences_file = "/etc/apt/preferences"
    if not hasattr(env, "python_version_ext"):
        env.python_version_ext = ""
    if not hasattr(env, "ruby_version_ext"):
        env.ruby_version_ext = "1.9.1"
    if not env.has_key("java_home"):
        # Try to determine java location from update-alternatives
        java_home = "/usr/lib/jvm/java-7-openjdk-amd64"

# Path: cloudbio/fabutils.py
# def quiet():
#     return settings(hide('warnings', 'running', 'stdout', 'stderr'), warn_only=True)
# 
# Path: cloudbio/fabutils.py
# def configure_runsudo(env):
#     """Setup env variable with safe_sudo and safe_run,
#     supporting non-privileged users and local execution.
#     """
#     env.is_local = env.hosts == ["localhost"]
#     if env.is_local:
#         env.safe_put = local_put
#         env.safe_sed = local_sed
#         env.safe_comment = local_comment
#         env.safe_contains = local_contains
#         env.safe_append = local_append
#         env.safe_exists = local_exists
#         env.safe_run = run_local()
#         env.safe_run_output = run_local(capture=True)
#     else:
#         env.safe_put = put
#         env.safe_sed = sed
#         env.safe_comment = comment
#         env.safe_contains = contains
#         env.safe_append = append
#         env.safe_exists = exists
#         env.safe_run = run
#         env.safe_run_output = run_output
#     if isinstance(getattr(env, "use_sudo", "true"), six.string_types):
#         if getattr(env, "use_sudo", "true").lower() in ["true", "yes"]:
#             env.use_sudo = True
#             if env.is_local:
#                 env.safe_sudo = run_local(True)
#             else:
#                 env.safe_sudo = sudo
#         else:
#             env.use_sudo = False
#             if env.is_local:
#                 env.safe_sudo = run_local()
#             else:
#                 env.safe_sudo = run


# Path: cloudbio/distribution.py
import os
import subprocess
from fabric.api import env
from cloudbio.fabutils import quiet
from cloudbio.fabutils import configure_runsudo
from cloudbio.custom import system

    env.std_sources = _add_source_versions(env.dist_name, sources)


def _setup_debian():
    env.logger.info("Debian setup")
    unstable_remap = {"sid": "squeeze"}
    shared_sources = _setup_deb_general()
    sources = [
        "deb http://cran.fhcrc.org/bin/linux/debian %s-cran/",  # lastest R versions
        "deb http://nebc.nerc.ac.uk/bio-linux/ unstable bio-linux",  # Bio-Linux
        ] + shared_sources
    # fill in %s
    dist_name = unstable_remap.get(env.dist_name, env.dist_name)
    env.std_sources = _add_source_versions(dist_name, sources)


def _setup_deb_general():
    """Shared settings for different debian based/derived distributions.
    """
    env.logger.debug("Debian-shared setup")
    env.sources_file = "/etc/apt/sources.list.d/cloudbiolinux.list"
    env.global_sources_file = "/etc/apt/sources.list"
    env.apt_preferences_file = "/etc/apt/preferences"
    if not hasattr(env, "python_version_ext"):
        env.python_version_ext = ""
    if not hasattr(env, "ruby_version_ext"):
        env.ruby_version_ext = "1.9.1"
    if not env.has_key("java_home"):
        # Try to determine java location from update-alternatives
        java_home = "/usr/lib/jvm/java-7-openjdk-amd64"

        with quiet():