def _prev_rosdistro(index, rosdistro_name):
    """Given current rosdistro name, return the previous."""
    valid_rosdistro_names = list(index.distributions.keys())
    valid_rosdistro_names.sort()

    # skip distributions with a different type if the information is available
    distro_type = index.distributions[rosdistro_name].get('distribution_type')
    if distro_type is not None:
        valid_rosdistro_names = [
            n for n in valid_rosdistro_names
            if distro_type == index.distributions[n].get('distribution_type')]

    try:
        i = valid_rosdistro_names.index(rosdistro_name)
    except ValueError:
        raise ValueError('Distribution key not found in list of valid distributions.')

    if i == 0:
        raise ValueError('No previous distribution found.')

    return valid_rosdistro_names[i - 1]