def _setup_apt_sources():
    """Add sources for retrieving library packages.
       Using add-apt-repository allows processing PPAs (on Ubuntu)

       This method modifies the apt sources file.

       Uses python-software-properties, which provides an abstraction of apt repositories
    """

    # It may be sudo is not installed - which has fab fail - therefor
    # we'll try to install it by default, assuming we have root access
    # already (e.g. on EC2). Fab will fail anyway, otherwise.
    if not env.safe_exists('/usr/bin/sudo') or not env.safe_exists('/usr/bin/curl'):
        env.safe_sudo('apt-get update')
        env.safe_sudo('apt-get -y --force-yes install sudo curl')

    env.logger.debug("_setup_apt_sources " + env.sources_file)
    env.flavor.check_packages_source()
    comment = "# This file was modified for " + env.flavor.name
    # Setup apt download policy (default is None)
    # (see also https://help.ubuntu.com/community/PinningHowto)
    preferences = env.flavor.rewrite_apt_preferences([])
    if len(preferences):
        # make sure it exists, and is empty
        env.safe_sudo("rm -f %s" % env.apt_preferences_file)
        env.safe_sudo("touch %s" % env.apt_preferences_file)
        env.safe_append(env.apt_preferences_file, comment, use_sudo=True)
        lines = "\n".join(preferences)
        env.logger.debug("Policy %s" % lines)
        # append won't duplicate, so we use echo
        env.safe_sudo("/bin/echo -e \"%s\" >> %s" % (lines, env.apt_preferences_file))
        # check there is no error parsing the file
        env.logger.debug(env.safe_sudo("apt-cache policy"))

    # Make sure a source file exists
    if not env.safe_exists(env.sources_file):
        env.safe_sudo("touch %s" % env.sources_file)
    # Add a comment
    if not env.safe_contains(env.sources_file, comment):
        env.safe_append(env.sources_file, comment, use_sudo=True)
    for source in env.flavor.rewrite_apt_sources_list(env.std_sources):
        env.logger.debug("Source %s" % source)
        if source.startswith("ppa:"):
            env.safe_sudo("apt-get install -y --force-yes python-software-properties")
            env.safe_sudo("add-apt-repository '%s'" % source)
        elif (not env.safe_contains(env.sources_file, source) and
              not env.safe_contains(env.global_sources_file, source)):
            env.safe_append(env.sources_file, source, use_sudo=True)
dataset/ETHPy150Open chapmanb/cloudbiolinux/cloudbio/package/deb.py/_setup_apt_sources/original