labpack/storage/aws/s3.py
def list_records(self, bucket_name, prefix='', delimiter='', max_results=1000, starting_key=''):

        '''
            a method for retrieving a list of the versions of records in a bucket

        :param bucket_name: string with name of bucket
        :param prefix: [optional] string with value limiting results to key prefix
        :param delimiter: string with value which results must not contain (after prefix)
        :param max_results: [optional] integer with max results to return
        :param starting_key: [optional] string with key value to continue search with
        :return: list of results with key, size and date, string with ending key value
        '''
        
        title = '%s.list_records' % self.__class__.__name__
        
        from datetime import datetime
        from dateutil.tz import tzutc
        
    # validate inputs
        input_fields = {
            'bucket_name': bucket_name,
            'prefix': prefix,
            'delimiter': delimiter,
            'max_results': max_results,
            'starting_key': starting_key
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)

    # verify existence of bucket
        if not bucket_name in self.bucket_list:
            if not bucket_name in self.list_buckets():
                raise ValueError('S3 Bucket "%s" does not exist in aws region %s.' % (bucket_name, self.iam.region_name))

    # create key word argument dictionary
        kw_args = {
            'Bucket': bucket_name
        }
        if starting_key:
            kw_args['Marker'] = starting_key
        if prefix:
            kw_args['Prefix'] = prefix
        if delimiter:
            kw_args['Delimiter'] = delimiter
        if max_results:
            kw_args['MaxKeys'] = max_results

    # send request for objects
        record_list = []
        next_key = ''
        try:
            response = self.connection.list_objects(**kw_args)
        except:
            raise AWSConnectionError(title)

    # add retrieved contents to object list
        if 'Contents' in response:
            for record in response['Contents']:
                details = {
                    'key': ''
                }
                details = self.iam.ingest(record, details)
                epoch_zero = datetime.fromtimestamp(0).replace(tzinfo=tzutc())
                details['last_modified'] = (details['last_modified'] - epoch_zero).total_seconds()
                record_list.append(details)

    # define ending key value
        if response['IsTruncated']:
            next_key = response['NextMarker']

        return record_list, next_key

            a method for retrieving a list of the versions of records in a bucket

        :param bucket_name: string with name of bucket
        :param prefix: [optional] string with value limiting results to key prefix
        :param delimiter: string with value which results must not contain (after prefix)
        :param max_results: [optional] integer with max results to return
        :param starting_key: [optional] string with key value to continue search with
        :return: list of results with key, size and date, string with ending key value
        
a method for retrieving a list of the versions of records in a bucket
a method for retrieving a list of the versions of records in a bucket
def list_records(self, bucket_name, prefix='', delimiter='', max_results=1000, starting_key=''):
        title = '%s.list_records' % self.__class__.__name__
        from datetime import datetime
        from dateutil.tz import tzutc
        input_fields = {
            'bucket_name': bucket_name,
            'prefix': prefix,
            'delimiter': delimiter,
            'max_results': max_results,
            'starting_key': starting_key
        }
        for key, value in input_fields.items():
            if value:
                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():
                raise ValueError('S3 Bucket "%s" does not exist in aws region %s.' % (bucket_name, self.iam.region_name))
        kw_args = {
            'Bucket': bucket_name
        }
        if starting_key:
            kw_args['Marker'] = starting_key
        if prefix:
            kw_args['Prefix'] = prefix
        if delimiter:
            kw_args['Delimiter'] = delimiter
        if max_results:
            kw_args['MaxKeys'] = max_results
        record_list = []
        next_key = ''
        try:
            response = self.connection.list_objects(**kw_args)
        except:
            raise AWSConnectionError(title)
        if 'Contents' in response:
            for record in response['Contents']:
                details = {
                    'key': ''
                }
                details = self.iam.ingest(record, details)
                epoch_zero = datetime.fromtimestamp(0).replace(tzinfo=tzutc())
                details['last_modified'] = (details['last_modified'] - epoch_zero).total_seconds()
                record_list.append(details)
        if response['IsTruncated']:
            next_key = response['NextMarker']
        return record_list, next_key
def list_records ( self , bucket_name , prefix = '' , delimiter = '' , max_results = 1000 , starting_key = '' ) : title = '%s.list_records' % self . __class__ . __name__ from datetime import datetime from dateutil . tz import tzutc input_fields = { 'bucket_name' : bucket_name , 'prefix' : prefix , 'delimiter' : delimiter , 'max_results' : max_results , 'starting_key' : starting_key } for key , value in input_fields . items ( ) : if value : 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 ( ) : raise ValueError ( 'S3 Bucket "%s" does not exist in aws region %s.' % ( bucket_name , self . iam . region_name ) ) kw_args = { 'Bucket' : bucket_name } if starting_key : kw_args [ 'Marker' ] = starting_key if prefix : kw_args [ 'Prefix' ] = prefix if delimiter : kw_args [ 'Delimiter' ] = delimiter if max_results : kw_args [ 'MaxKeys' ] = max_results record_list = [ ] next_key = '' try : response = self . connection . list_objects ( ** kw_args ) except : raise AWSConnectionError ( title ) if 'Contents' in response : for record in response [ 'Contents' ] : details = { 'key' : '' } details = self . iam . ingest ( record , details ) epoch_zero = datetime . fromtimestamp ( 0 ) . replace ( tzinfo = tzutc ( ) ) details [ 'last_modified' ] = ( details [ 'last_modified' ] - epoch_zero ) . total_seconds ( ) record_list . append ( details ) if response [ 'IsTruncated' ] : next_key = response [ 'NextMarker' ] return record_list , next_key
a method for retrieving a list of the versions of records in a bucket
a method for retrieving a list of the versions of records in a bucket
'''
            a method for retrieving a list of the versions of records in a bucket

        :param bucket_name: string with name of bucket
        :param prefix: [optional] string with value limiting results to key prefix
        :param delimiter: string with value which results must not contain (after prefix)
        :param max_results: [optional] integer with max results to return
        :param starting_key: [optional] string with key value to continue search with
        :return: list of results with key, size and date, string with ending key value
        ''' # validate inputs # verify existence of bucket # create key word argument dictionary # send request for objects # add retrieved contents to object list # define ending key value
list of results with key, size and date, string with ending key value
list of results with key size and date string with ending key value
self
bucket_name
string with name of bucket
string with name of bucket
prefix
[optional] string with value limiting results to key prefix
[ optional ] string with value limiting results to key prefix
delimiter
string with value which results must not contain (after prefix)
string with value which results must not contain ( after prefix )
max_results
[optional] integer with max results to return
[ optional ] integer with max results to return
starting_key
[optional] string with key value to continue search with
[ optional ] string with key value to continue search with