#!/usr/bin/env python

"""
Utilities used by multiple commands.
"""

import boto

from boto.s3.connection import OrdinaryCallingFormat
from fabric.api import prompt


def confirm(message):
    """
    Verify a users intentions.
    """
    answer = prompt(message, default="Not at all")

    if answer.lower() not in ('y', 'yes', 'buzz off', 'screw you'):
        exit()


def confirm_bool(message):
    """
    Verify a users intentions.
    """
    answer = prompt(message, default="Not at all")
    return answer.lower() in ('y', 'yes', 'buzz off', 'screw you')


def get_bucket(bucket_name):
    """
    Established a connection and gets s3 bucket
    """

    if '.' in bucket_name:
        s3 = boto.connect_s3(calling_format=OrdinaryCallingFormat())
    else:
        s3 = boto.connect_s3()

    return s3.get_bucket(bucket_name)

