labpack/storage/aws/s3.py
def delete_bucket(self, bucket_name):

        '''
            a method to delete a bucket in s3 and all its contents

        :param bucket_name: string with name of bucket
        :return: string with status of method
        '''

        title = '%s.delete_bucket' % self.__class__.__name__
        
    # validate inputs
        input_fields = {
            'bucket_name': bucket_name
        }
        for key, value in input_fields.items():
            object_title = '%s(%s=%s)' % (title, key, str(value))
            self.fields.validate(value, '.%s' % key, object_title)

    # check for existence of bucket
        if not bucket_name in self.bucket_list:
            if not bucket_name in self.list_buckets():
                status_msg = 'S3 bucket "%s" does not exist.' % bucket_name
                self.iam.printer(status_msg)
                return status_msg

    # retrieve list of records in bucket
        record_keys = []
        record_list, next_key = self.list_versions(bucket_name)
        for record in record_list:
            details = {
                'Key': record['key'],
                'VersionId': record['version_id']
            }
            record_keys.append(details)

    # delete records in bucket
        kw_args = {
            'Bucket': bucket_name,
            'Delete': { 'Objects': record_keys }
        }
        if record_keys:
            try:
                response = self.connection.delete_objects(**kw_args)
            except:
                raise AWSConnectionError(title)

    # continue deleting objects in bucket until empty
        if next_key:
            while next_key:
                record_keys = []
                record_list, next_key = self.list_versions(bucket_name, starting_key=next_key['key'], starting_version=next_key['version_id'])
                for record in record_list:
                    details = {
                        'Key': record['key'],
                        'VersionId': record['version_id']
                    }
                    record_keys.append(details)
                kw_args = {
                    'Bucket': bucket_name,
                    'Delete': { 'Objects': record_keys }
                }
                try:
                    response = self.connection.delete_objects(**kw_args)
                except:
                    raise AWSConnectionError(title)

    # send delete bucket request
        try:
            self.connection.delete_bucket( Bucket=bucket_name )
        except:
            raise AWSConnectionError(title)

    # report result and return true
        status_msg = 'S3 bucket "%s" deleted.' % bucket_name
        self.iam.printer(status_msg)
        
        return status_msg

            a method to delete a bucket in s3 and all its contents

        :param bucket_name: string with name of bucket
        :return: string with status of method
        
a method to delete a bucket in s3 and all its contents
a method to delete a bucket in s3 and all its contents
def delete_bucket(self, bucket_name):
        title = '%s.delete_bucket' % self.__class__.__name__
        input_fields = {
            'bucket_name': bucket_name
        }
        for key, value in input_fields.items():
            object_title = '%s(%s=%s)' % (title, key, str(value))
            self.fields.validate(value, '.%s' % key, object_title)
        if not bucket_name in self.bucket_list:
            if not bucket_name in self.list_buckets():
                status_msg = 'S3 bucket "%s" does not exist.' % bucket_name
                self.iam.printer(status_msg)
                return status_msg
        record_keys = []
        record_list, next_key = self.list_versions(bucket_name)
        for record in record_list:
            details = {
                'Key': record['key'],
                'VersionId': record['version_id']
            }
            record_keys.append(details)
        kw_args = {
            'Bucket': bucket_name,
            'Delete': { 'Objects': record_keys }
        }
        if record_keys:
            try:
                response = self.connection.delete_objects(**kw_args)
            except:
                raise AWSConnectionError(title)
        if next_key:
            while next_key:
                record_keys = []
                record_list, next_key = self.list_versions(bucket_name, starting_key=next_key['key'], starting_version=next_key['version_id'])
                for record in record_list:
                    details = {
                        'Key': record['key'],
                        'VersionId': record['version_id']
                    }
                    record_keys.append(details)
                kw_args = {
                    'Bucket': bucket_name,
                    'Delete': { 'Objects': record_keys }
                }
                try:
                    response = self.connection.delete_objects(**kw_args)
                except:
                    raise AWSConnectionError(title)
        try:
            self.connection.delete_bucket( Bucket=bucket_name )
        except:
            raise AWSConnectionError(title)
        status_msg = 'S3 bucket "%s" deleted.' % bucket_name
        self.iam.printer(status_msg)
        return status_msg
def delete_bucket ( self , bucket_name ) : title = '%s.delete_bucket' % self . __class__ . __name__ input_fields = { 'bucket_name' : bucket_name } for key , value in input_fields . items ( ) : object_title = '%s(%s=%s)' % ( title , key , str ( value ) ) self . fields . validate ( value , '.%s' % key , object_title ) if not bucket_name in self . bucket_list : if not bucket_name in self . list_buckets ( ) : status_msg = 'S3 bucket "%s" does not exist.' % bucket_name self . iam . printer ( status_msg ) return status_msg record_keys = [ ] record_list , next_key = self . list_versions ( bucket_name ) for record in record_list : details = { 'Key' : record [ 'key' ] , 'VersionId' : record [ 'version_id' ] } record_keys . append ( details ) kw_args = { 'Bucket' : bucket_name , 'Delete' : { 'Objects' : record_keys } } if record_keys : try : response = self . connection . delete_objects ( ** kw_args ) except : raise AWSConnectionError ( title ) if next_key : while next_key : record_keys = [ ] record_list , next_key = self . list_versions ( bucket_name , starting_key = next_key [ 'key' ] , starting_version = next_key [ 'version_id' ] ) for record in record_list : details = { 'Key' : record [ 'key' ] , 'VersionId' : record [ 'version_id' ] } record_keys . append ( details ) kw_args = { 'Bucket' : bucket_name , 'Delete' : { 'Objects' : record_keys } } try : response = self . connection . delete_objects ( ** kw_args ) except : raise AWSConnectionError ( title ) try : self . connection . delete_bucket ( Bucket = bucket_name ) except : raise AWSConnectionError ( title ) status_msg = 'S3 bucket "%s" deleted.' % bucket_name self . iam . printer ( status_msg ) return status_msg
a method to delete a bucket in s3 and all its contents
a method to delete a bucket in s3 and all its contents
'''
            a method to delete a bucket in s3 and all its contents

        :param bucket_name: string with name of bucket
        :return: string with status of method
        ''' # validate inputs # check for existence of bucket # retrieve list of records in bucket # delete records in bucket # continue deleting objects in bucket until empty # send delete bucket request # report result and return true
string with status of method
string with status of method
self
bucket_name
string with name of bucket
string with name of bucket