def to_bool(string):
    """Returns a boolean from a string.

    string -- string in format yes|no|true|false
    """
    if string.lower() in ('yes', 'y', 'true', '1'):
        return True
    elif string.lower() in ('no', 'n', 'false', '0'):
        return False
    raise ValueError(str(string) +
        ' not in ["yes", "y", "true", "1", "no", "n", "false", "0"].')
