labpack/storage/aws/s3.py
def export(self, storage_client, overwrite=True):
    
        '''
            a method to export all the records in collection to another platform
            
        :param storage_client: class object with storage client methods
        :return: string with exit message
        '''
        
        title = '%s.export' % self.__class__.__name__
        
    # validate storage client
        method_list = [ 'save', 'load', 'list', 'export', 'delete', 'remove', '_import', 'collection_name' ]
        for method in method_list:
            if not getattr(storage_client, method, None):
                from labpack.parsing.grammar import join_words
                raise ValueError('%s(storage_client=...) must be a client object with %s methods.' % (title, join_words(method_list)))
    
    # define copy record function
        def _copy_record(_record, _storage_client):
            record_key = _record['key']
            record_data, record_metadata = self.s3.read_record(self.bucket_name, record_key)
            encryption = ''
            if 'encryption' in record_metadata['metadata'].keys():
                encryption = record_metadata['metadata']['encryption']
            last_modified = 0.0
            if 'last_modified' in record_metadata['metadata'].keys():
                try:
                    last_modified = float(record_metadata['metadata']['last_modified'])
                except:
                    pass
            outcome = _storage_client._import(record_key, record_data, overwrite=overwrite, encryption=encryption, last_modified=last_modified)
            return outcome
            
    # retrieve list of records in bucket
        count = 0
        skipped = 0
        record_list, next_key = self.s3.list_records(self.bucket_name)
        for record in record_list:
            outcome = _copy_record(record, storage_client)
            if outcome:
                count += 1
            else:
                skipped += 1
        
    # continue through bucket
        if next_key:
            while next_key:
                record_list, next_key = self.s3.list_records(self.bucket_name, starting_key=next_key)
                for record in record_list:
                    outcome = _copy_record(record, storage_client)
                    if outcome:
                        count += 1
                    else:
                        skipped += 1
    
    # report outcome
        from os import path
        plural = ''
        skip_insert = ''
        new_root, new_folder = path.split(storage_client.collection_folder)
        if count != 1:
            plural = 's'
        if skipped > 0:
            skip_plural = ''
            if skipped > 1:
                skip_plural = 's'
            skip_insert = ' %s record%s skipped to avoid overwrite.' % (str(skipped), skip_plural)
        exit_msg = '%s record%s exported to %s.%s' % (str(count), plural, new_folder, skip_insert)
        return exit_msg

            a method to export all the records in collection to another platform
            
        :param storage_client: class object with storage client methods
        :return: string with exit message
        
a method to export all the records in collection to another platform
a method to export all the records in collection to another platform
def export(self, storage_client, overwrite=True):
        title = '%s.export' % self.__class__.__name__
        method_list = [ 'save', 'load', 'list', 'export', 'delete', 'remove', '_import', 'collection_name' ]
        for method in method_list:
            if not getattr(storage_client, method, None):
                from labpack.parsing.grammar import join_words
                raise ValueError('%s(storage_client=...) must be a client object with %s methods.' % (title, join_words(method_list)))
        def _copy_record(_record, _storage_client):
            record_key = _record['key']
            record_data, record_metadata = self.s3.read_record(self.bucket_name, record_key)
            encryption = ''
            if 'encryption' in record_metadata['metadata'].keys():
                encryption = record_metadata['metadata']['encryption']
            last_modified = 0.0
            if 'last_modified' in record_metadata['metadata'].keys():
                try:
                    last_modified = float(record_metadata['metadata']['last_modified'])
                except:
                    pass
            outcome = _storage_client._import(record_key, record_data, overwrite=overwrite, encryption=encryption, last_modified=last_modified)
            return outcome
        count = 0
        skipped = 0
        record_list, next_key = self.s3.list_records(self.bucket_name)
        for record in record_list:
            outcome = _copy_record(record, storage_client)
            if outcome:
                count += 1
            else:
                skipped += 1
        if next_key:
            while next_key:
                record_list, next_key = self.s3.list_records(self.bucket_name, starting_key=next_key)
                for record in record_list:
                    outcome = _copy_record(record, storage_client)
                    if outcome:
                        count += 1
                    else:
                        skipped += 1
        from os import path
        plural = ''
        skip_insert = ''
        new_root, new_folder = path.split(storage_client.collection_folder)
        if count != 1:
            plural = 's'
        if skipped > 0:
            skip_plural = ''
            if skipped > 1:
                skip_plural = 's'
            skip_insert = ' %s record%s skipped to avoid overwrite.' % (str(skipped), skip_plural)
        exit_msg = '%s record%s exported to %s.%s' % (str(count), plural, new_folder, skip_insert)
        return exit_msg
def export ( self , storage_client , overwrite = True ) : title = '%s.export' % self . __class__ . __name__ method_list = [ 'save' , 'load' , 'list' , 'export' , 'delete' , 'remove' , '_import' , 'collection_name' ] for method in method_list : if not getattr ( storage_client , method , None ) : from labpack . parsing . grammar import join_words raise ValueError ( '%s(storage_client=...) must be a client object with %s methods.' % ( title , join_words ( method_list ) ) ) def _copy_record ( _record , _storage_client ) : record_key = _record [ 'key' ] record_data , record_metadata = self . s3 . read_record ( self . bucket_name , record_key ) encryption = '' if 'encryption' in record_metadata [ 'metadata' ] . keys ( ) : encryption = record_metadata [ 'metadata' ] [ 'encryption' ] last_modified = 0.0 if 'last_modified' in record_metadata [ 'metadata' ] . keys ( ) : try : last_modified = float ( record_metadata [ 'metadata' ] [ 'last_modified' ] ) except : pass outcome = _storage_client . _import ( record_key , record_data , overwrite = overwrite , encryption = encryption , last_modified = last_modified ) return outcome count = 0 skipped = 0 record_list , next_key = self . s3 . list_records ( self . bucket_name ) for record in record_list : outcome = _copy_record ( record , storage_client ) if outcome : count += 1 else : skipped += 1 if next_key : while next_key : record_list , next_key = self . s3 . list_records ( self . bucket_name , starting_key = next_key ) for record in record_list : outcome = _copy_record ( record , storage_client ) if outcome : count += 1 else : skipped += 1 from os import path plural = '' skip_insert = '' new_root , new_folder = path . split ( storage_client . collection_folder ) if count != 1 : plural = 's' if skipped > 0 : skip_plural = '' if skipped > 1 : skip_plural = 's' skip_insert = ' %s record%s skipped to avoid overwrite.' % ( str ( skipped ) , skip_plural ) exit_msg = '%s record%s exported to %s.%s' % ( str ( count ) , plural , new_folder , skip_insert ) return exit_msg
a method to export all the records in collection to another platform
a method to export all the records in collection to another platform
'''
            a method to export all the records in collection to another platform
            
        :param storage_client: class object with storage client methods
        :return: string with exit message
        ''' # validate storage client # define copy record function # retrieve list of records in bucket # continue through bucket # report outcome
string with exit message
string with exit message
self
storage_client
class object with storage client methods
class object with storage client methods
overwrite