# Path: shelf/cloud/cloud_exceptions.py
# class ArtifactNotFoundError(CloudStorageException):
#     def __init__(self, artifact_name):
#         message = "Artifact {0} not found".format(artifact_name)
#         super(ArtifactNotFoundError, self).__init__(message, ErrorCode.RESOURCE_NOT_FOUND)
# 
# class BucketNotFoundError(CloudStorageException):
#     def __init__(self, bucket_name):
#         message = "Bucket {0} not found".format(bucket_name)
#         super(BucketNotFoundError, self).__init__(message, ErrorCode.RESOURCE_NOT_FOUND)
# 
# class DuplicateArtifactError(CloudStorageException):
#     def __init__(self, artifact_name):
#         message = "Artifact by name {0} already exists in current directory".format(artifact_name)
#         super(DuplicateArtifactError, self).__init__(message, ErrorCode.DUPLICATE_ARTIFACT)


from boto.s3.connection import S3Connection
from boto.s3.key import Key
from shelf.cloud.stream_iterator import StreamIterator
from shelf.cloud.cloud_exceptions import ArtifactNotFoundError, BucketNotFoundError, DuplicateArtifactError
        """
            Gets the contents of a directory.

            Args:
                path(string): The path of the directory.
                recursive(boolean):

            Returns:
                list of s3.boto.key.Key
        """
        if path == "/":
            path = ""

        if recursive:
            result_list = self._get_bucket(self.bucket_name).list(prefix=path)
        else:
            result_list = self._get_bucket(self.bucket_name).list(prefix=path, delimiter="/")

        keys = list(result_list)
        return keys

    def _get_key(self, artifact_name):
        if artifact_name in self.key_map:
            return self.key_map[artifact_name]

        bucket = self._get_bucket(self.bucket_name)
        self.logger.debug("Attempting to get artifact {0}".format(artifact_name))
        key = bucket.get_key(artifact_name)
        if key is None:
            self.logger.info("Artifact {0} does not exist in bucket {0}".format(artifact_name, self.bucket_name))

# Path: shelf/cloud/cloud_exceptions.py
# class ArtifactNotFoundError(CloudStorageException):
#     def __init__(self, artifact_name):
#         message = "Artifact {0} not found".format(artifact_name)
#         super(ArtifactNotFoundError, self).__init__(message, ErrorCode.RESOURCE_NOT_FOUND)
# 
# class BucketNotFoundError(CloudStorageException):
#     def __init__(self, bucket_name):
#         message = "Bucket {0} not found".format(bucket_name)
#         super(BucketNotFoundError, self).__init__(message, ErrorCode.RESOURCE_NOT_FOUND)
# 
# class DuplicateArtifactError(CloudStorageException):
#     def __init__(self, artifact_name):
#         message = "Artifact by name {0} already exists in current directory".format(artifact_name)
#         super(DuplicateArtifactError, self).__init__(message, ErrorCode.DUPLICATE_ARTIFACT)


# Path: shelf/cloud/storage.py
from boto.s3.connection import S3Connection
from boto.s3.key import Key
from shelf.cloud.stream_iterator import StreamIterator
from shelf.cloud.cloud_exceptions import ArtifactNotFoundError, BucketNotFoundError, DuplicateArtifactError

        """
            Gets the contents of a directory.

            Args:
                path(string): The path of the directory.
                recursive(boolean):

            Returns:
                list of s3.boto.key.Key
        """
        if path == "/":
            path = ""

        if recursive:
            result_list = self._get_bucket(self.bucket_name).list(prefix=path)
        else:
            result_list = self._get_bucket(self.bucket_name).list(prefix=path, delimiter="/")

        keys = list(result_list)
        return keys

    def _get_key(self, artifact_name):
        if artifact_name in self.key_map:
            return self.key_map[artifact_name]

        bucket = self._get_bucket(self.bucket_name)
        self.logger.debug("Attempting to get artifact {0}".format(artifact_name))
        key = bucket.get_key(artifact_name)
        if key is None:
            self.logger.info("Artifact {0} does not exist in bucket {0}".format(artifact_name, self.bucket_name))

            raise ArtifactNotFoundError(artifact_name)