labpack/storage/dropbox.py
def _import(self, record_key, record_data, overwrite=True, last_modified=0.0, **kwargs):
        
        '''
            a helper method for other storage clients to import into appdata
            
        :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 last_modified: [optional] float to record last modified date
        :param kwargs: [optional] keyword arguments from other import methods 
        :return: boolean indicating whether record was imported
        '''
        
        title = '%s._import' % self.__class__.__name__
    
    # check overwrite
        if not overwrite:
            if self.exists(record_key):
                return False
    
    # check max size
        import sys
        record_max = self.fields.metadata['record_max_bytes']
        record_size = sys.getsizeof(record_data)
        error_prefix = '%s(record_key="%s", record_data=b"...")' % (title, record_key)
        if record_size > record_max:
            raise ValueError('%s exceeds maximum record data size of %s bytes.' % (error_prefix, record_max))
    
    # TODO: apply session upload for files greater than record_max
            
    # construct upload kwargs
        upload_kwargs = {
            'f': record_data,
            'path': '/%s' % record_key,
            'mute': True,
            'mode': self.objects.WriteMode.overwrite
        }
    
    # modify file time
        import re
        if re.search('\\.drep$', record_key):
            from labpack.records.time import labDT
            drep_time = labDT.fromEpoch(1)
            upload_kwargs['client_modified'] = drep_time
        elif last_modified:
            from labpack.records.time import labDT
            mod_time = labDT.fromEpoch(last_modified)
            upload_kwargs['client_modified'] = mod_time
    
    # send upload request
        try:
            self.dropbox.files_upload(**upload_kwargs)
        except:
            raise DropboxConnectionError(title)
        
        return True

            a helper method for other storage clients to import into appdata
            
        :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 last_modified: [optional] float to record last modified date
        :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 appdata
a helper method for other storage clients to import into appdata
def _import(self, record_key, record_data, overwrite=True, last_modified=0.0, **kwargs):
        title = '%s._import' % self.__class__.__name__
        if not overwrite:
            if self.exists(record_key):
                return False
        import sys
        record_max = self.fields.metadata['record_max_bytes']
        record_size = sys.getsizeof(record_data)
        error_prefix = '%s(record_key="%s", record_data=b"...")' % (title, record_key)
        if record_size > record_max:
            raise ValueError('%s exceeds maximum record data size of %s bytes.' % (error_prefix, record_max))
        upload_kwargs = {
            'f': record_data,
            'path': '/%s' % record_key,
            'mute': True,
            'mode': self.objects.WriteMode.overwrite
        }
        import re
        if re.search('\\.drep$', record_key):
            from labpack.records.time import labDT
            drep_time = labDT.fromEpoch(1)
            upload_kwargs['client_modified'] = drep_time
        elif last_modified:
            from labpack.records.time import labDT
            mod_time = labDT.fromEpoch(last_modified)
            upload_kwargs['client_modified'] = mod_time
        try:
            self.dropbox.files_upload(**upload_kwargs)
        except:
            raise DropboxConnectionError(title)
        return True
def _import ( self , record_key , record_data , overwrite = True , last_modified = 0.0 , ** kwargs ) : title = '%s._import' % self . __class__ . __name__ if not overwrite : if self . exists ( record_key ) : return False import sys record_max = self . fields . metadata [ 'record_max_bytes' ] record_size = sys . getsizeof ( record_data ) error_prefix = '%s(record_key="%s", record_data=b"...")' % ( title , record_key ) if record_size > record_max : raise ValueError ( '%s exceeds maximum record data size of %s bytes.' % ( error_prefix , record_max ) ) upload_kwargs = { 'f' : record_data , 'path' : '/%s' % record_key , 'mute' : True , 'mode' : self . objects . WriteMode . overwrite } import re if re . search ( '\\.drep$' , record_key ) : from labpack . records . time import labDT drep_time = labDT . fromEpoch ( 1 ) upload_kwargs [ 'client_modified' ] = drep_time elif last_modified : from labpack . records . time import labDT mod_time = labDT . fromEpoch ( last_modified ) upload_kwargs [ 'client_modified' ] = mod_time try : self . dropbox . files_upload ( ** upload_kwargs ) except : raise DropboxConnectionError ( title ) return True
a helper method for other storage clients to import into appdata
a helper method for other storage clients to import into appdata
'''
            a helper method for other storage clients to import into appdata
            
        :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 last_modified: [optional] float to record last modified date
        :param kwargs: [optional] keyword arguments from other import methods 
        :return: boolean indicating whether record was imported
        ''' # check overwrite
 # check max size
 # TODO: apply session upload for files greater than record_max
 # construct upload kwargs
 # modify file time
 # send upload request

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
last_modified
[optional] float to record last modified date
[ optional ] float to record last modified date
kwargs
[optional] keyword arguments from other import methods
[ optional ] keyword arguments from other import methods