labpack/storage/aws/s3.py
def _import(self, record_key, record_data, overwrite=True, encryption='', last_modified=0.0, **kwargs):
        
        '''
            a helper method for other storage clients to import into s3
            
        :param record_key: string with key for record
        :param record_data: byte data for body of record
        :param overwrite: [optional] boolean to overwrite existing records
        :param encryption: [optional] string with encryption type add to metadata
        :param kwargs: [optional] keyword arguments from other import methods 
        :return: boolean indicating whether record was imported
        '''

    # define keyword arguments
        from time import time
        create_kwargs = {
            'bucket_name': self.bucket_name,
            'record_key': record_key,
            'record_data': record_data,
            'overwrite': overwrite,
            'record_metadata': { 'last_modified': str(time()) }
        }
    
    # add encryption and last_modified
        if encryption:
            create_kwargs['record_metadata']['encryption'] = encryption
        if last_modified:
            create_kwargs['record_metadata']['last_modified'] = str(last_modified)
            
    # add record mimetype and encoding
        import mimetypes
        guess_mimetype, guess_encoding = mimetypes.guess_type(record_key)
        if not guess_mimetype:
            if record_key.find('.yaml') or record_key.find('.yml'):
                guess_mimetype = 'application/x-yaml'
            if record_key.find('.drep'):
                guess_mimetype = 'application/x-drep'
        if guess_mimetype:
            create_kwargs['record_mimetype'] = guess_mimetype
        if guess_encoding:
            create_kwargs['record_encoding'] = guess_encoding
            
    # create record
        try:
            self.s3.create_record(**create_kwargs)
        except ValueError as err:
            if str(err).find('already contains') > -1:
                self.s3.iam.printer('%s already exists in %s collection. Skipping.' % (record_key, self.bucket_name))
                return False
            # elif str(err).find('exceeds maximum record') > -1:
            #     self.s3.iam.printer('%s exceeds the maximum size for files on S3. Skipping.' % record_key)
            else:
                raise
        except:
            raise

        return True

            a helper method for other storage clients to import into s3
            
        :param record_key: string with key for record
        :param record_data: byte data for body of record
        :param overwrite: [optional] boolean to overwrite existing records
        :param encryption: [optional] string with encryption type add to metadata
        :param kwargs: [optional] keyword arguments from other import methods 
        :return: boolean indicating whether record was imported
        
a helper method for other storage clients to import into s3
a helper method for other storage clients to import into s3
def _import(self, record_key, record_data, overwrite=True, encryption='', last_modified=0.0, **kwargs):
        from time import time
        create_kwargs = {
            'bucket_name': self.bucket_name,
            'record_key': record_key,
            'record_data': record_data,
            'overwrite': overwrite,
            'record_metadata': { 'last_modified': str(time()) }
        }
        if encryption:
            create_kwargs['record_metadata']['encryption'] = encryption
        if last_modified:
            create_kwargs['record_metadata']['last_modified'] = str(last_modified)
        import mimetypes
        guess_mimetype, guess_encoding = mimetypes.guess_type(record_key)
        if not guess_mimetype:
            if record_key.find('.yaml') or record_key.find('.yml'):
                guess_mimetype = 'application/x-yaml'
            if record_key.find('.drep'):
                guess_mimetype = 'application/x-drep'
        if guess_mimetype:
            create_kwargs['record_mimetype'] = guess_mimetype
        if guess_encoding:
            create_kwargs['record_encoding'] = guess_encoding
        try:
            self.s3.create_record(**create_kwargs)
        except ValueError as err:
            if str(err).find('already contains') > -1:
                self.s3.iam.printer('%s already exists in %s collection. Skipping.' % (record_key, self.bucket_name))
                return False
            else:
                raise
        except:
            raise
        return True
def _import ( self , record_key , record_data , overwrite = True , encryption = '' , last_modified = 0.0 , ** kwargs ) : from time import time create_kwargs = { 'bucket_name' : self . bucket_name , 'record_key' : record_key , 'record_data' : record_data , 'overwrite' : overwrite , 'record_metadata' : { 'last_modified' : str ( time ( ) ) } } if encryption : create_kwargs [ 'record_metadata' ] [ 'encryption' ] = encryption if last_modified : create_kwargs [ 'record_metadata' ] [ 'last_modified' ] = str ( last_modified ) import mimetypes guess_mimetype , guess_encoding = mimetypes . guess_type ( record_key ) if not guess_mimetype : if record_key . find ( '.yaml' ) or record_key . find ( '.yml' ) : guess_mimetype = 'application/x-yaml' if record_key . find ( '.drep' ) : guess_mimetype = 'application/x-drep' if guess_mimetype : create_kwargs [ 'record_mimetype' ] = guess_mimetype if guess_encoding : create_kwargs [ 'record_encoding' ] = guess_encoding try : self . s3 . create_record ( ** create_kwargs ) except ValueError as err : if str ( err ) . find ( 'already contains' ) > - 1 : self . s3 . iam . printer ( '%s already exists in %s collection. Skipping.' % ( record_key , self . bucket_name ) ) return False else : raise except : raise return True
a helper method for other storage clients to import into s3
a helper method for other storage clients to import into s3
'''
            a helper method for other storage clients to import into s3
            
        :param record_key: string with key for record
        :param record_data: byte data for body of record
        :param overwrite: [optional] boolean to overwrite existing records
        :param encryption: [optional] string with encryption type add to metadata
        :param kwargs: [optional] keyword arguments from other import methods 
        :return: boolean indicating whether record was imported
        ''' # define keyword arguments # add encryption and last_modified # add record mimetype and encoding # create record # elif str(err).find('exceeds maximum record') > -1: #     self.s3.iam.printer('%s exceeds the maximum size for files on S3. Skipping.' % record_key)
boolean indicating whether record was imported
boolean indicating whether record was imported
self
record_key
string with key for record
string with key for record
record_data
byte data for body of record
byte data for body of record
overwrite
[optional] boolean to overwrite existing records
[ optional ] boolean to overwrite existing records
encryption
[optional] string with encryption type add to metadata
[ optional ] string with encryption type add to metadata
last_modified
kwargs
[optional] keyword arguments from other import methods
[ optional ] keyword arguments from other import methods