예제 #1
0
 def upload(self):
     """上传操作"""
     self.blockStatus = []
     host = config.get_default('default_zone').get_up_host_by_token(
         self.up_token)
     offset = self.recovery_from_record()
     for block in _file_iter(self.input_stream, config._BLOCK_SIZE, offset):
         length = len(block)
         crc = crc32(block)
         ret, info = self.make_block(block, length, host)
         if ret is None and not info.need_retry():
             return ret, info
         if info.connect_failed():
             host = config.get_default(
                 'default_zone').get_up_host_backup_by_token(self.up_token)
         if info.need_retry() or crc != ret['crc32']:
             ret, info = self.make_block(block, length, host)
             if ret is None or crc != ret['crc32']:
                 return ret, info
         self.blockStatus.append(ret)
         offset += length
         self.record_upload_progress(offset)
         if (callable(self.progress_handler)):
             self.progress_handler(
                 ((len(self.blockStatus) - 1) * config._BLOCK_SIZE) +
                 length, self.size)
     return self.make_file(host)
예제 #2
0
    def upload(self):
        self.blockStatus = []

        for block in _file_iter(self.input_stream, config._BLOCK_SIZE):
            length = len(block)
            ret = self.make_block(block, length)
            self.blockStatus.append(ret)
            if(callable(self.notify)):
                self.notify(((len(self.blockStatus) - 1) * config._BLOCK_SIZE)+length, self.size)
        return self.make_file()
예제 #3
0
    def upload(self):
        self.blockStatus = []

        for block in _file_iter(self.input_stream, config._BLOCK_SIZE):
            length = len(block)
            ret = self.make_block(block, length)
            self.blockStatus.append(ret)
            if (callable(self.notify)):
                self.notify(
                    ((len(self.blockStatus) - 1) * config._BLOCK_SIZE) +
                    length, self.size)
        return self.make_file()
예제 #4
0
    def upload(self):
        self.blockStatus = []
        host = config.get_default('default_up_host')
        for block in _file_iter(self.input_stream, config._BLOCK_SIZE):
            length = len(block)
            crc = crc32(block)
            ret, info = self.make_block(block, length, host)
            if ret is None and not info.need_retry:
                return ret, info
            if info.connect_failed:
                host = config.UPBACKUP_HOST
            if info.need_retry or crc != ret['crc32']:
                ret, info = self.make_block(block, length, host)
                if ret is None or crc != ret['crc32']:
                    return ret, info

            self.blockStatus.append(ret)
            if(callable(self.progress_handler)):
                self.progress_handler(((len(self.blockStatus) - 1) * config._BLOCK_SIZE)+length, self.size)
        return self.make_file(host)
예제 #5
0
    def upload(self):
        self.blockStatus = []
        host = config.get_default('default_up_host')
        for block in _file_iter(self.input_stream, config._BLOCK_SIZE):
            length = len(block)
            crc = crc32(block)
            ret, info = self.make_block(block, length, host)
            if ret is None and not info.need_retry:
                return ret, info
            if info.connect_failed:
                host = config.UPBACKUP_HOST
            if info.need_retry or crc != ret['crc32']:
                ret, info = self.make_block(block, length, host)
                if ret is None or crc != ret['crc32']:
                    return ret, info

            self.blockStatus.append(ret)
            if (callable(self.progress_handler)):
                self.progress_handler(
                    ((len(self.blockStatus) - 1) * config._BLOCK_SIZE) +
                    length, self.size)
        return self.make_file(host)
예제 #6
0
 def upload(self):
     """上传操作"""
     self.blockStatus = []
     host = config.get_default('default_up_host')
     offset = self.recovery_from_record()
     for block in _file_iter(self.input_stream, config._BLOCK_SIZE, offset):
         length = len(block)
         crc = crc32(block)
         ret, info = self.make_block(block, length, host)
         if ret is None and not info.need_retry():
             return ret, info
         if info.connect_failed():
             host = config.get_default('default_up_host_backup')
         if info.need_retry() or crc != ret['crc32']:
             ret, info = self.make_block(block, length, host)
             if ret is None or crc != ret['crc32']:
                 return ret, info
         self.blockStatus.append(ret)
         offset += length
         self.record_upload_progress(offset)
         if(callable(self.progress_handler)):
             self.progress_handler(((len(self.blockStatus) - 1) * config._BLOCK_SIZE)+length, self.size)
     return self.make_file(host)
예제 #7
0
 def upload(self):
     """上传操作"""
     self.blockStatus = []
     self.recovery_index = 1
     self.expiredAt = None
     self.uploadId = None
     self.get_bucket()
     host = self.get_up_host()
     if self.version == 'v1':
         offset = self.recovery_from_record()
         self.part_size = config._BLOCK_SIZE
     elif self.version == 'v2':
         offset, self.uploadId, self.expiredAt = self.recovery_from_record()
         if offset > 0 and self.blockStatus != [] and self.uploadId is not None \
            and self.expiredAt is not None:
             self.recovery_index = self.blockStatus[-1]['partNumber'] + 1
         else:
             self.recovery_index = 1
             init_url = self.block_url_v2(host, self.bucket_name)
             self.uploadId, self.expiredAt = self.init_upload_task(init_url)
     else:
         raise ValueError("version must choose v1 or v2 !")
     for index, block in enumerate(
             _file_iter(self.input_stream, self.part_size, offset)):
         length = len(block)
         if self.version == 'v1':
             crc = crc32(block)
             ret, info = self.make_block(block, length, host)
         elif self.version == 'v2':
             index_ = index + self.recovery_index
             url = self.block_url_v2(
                 host,
                 self.bucket_name) + '/%s/%d' % (self.uploadId, index_)
             ret, info = self.make_block_v2(block, url)
         if ret is None and not info.need_retry():
             return ret, info
         if info.connect_failed():
             if config.get_default('default_zone').up_host_backup:
                 host = config.get_default('default_zone').up_host_backup
             else:
                 host = config.get_default(
                     'default_zone').get_up_host_backup_by_token(
                         self.up_token, self.hostscache_dir)
         if self.version == 'v1':
             if info.need_retry() or crc != ret['crc32']:
                 ret, info = self.make_block(block, length, host)
                 if ret is None or crc != ret['crc32']:
                     return ret, info
         elif self.version == 'v2':
             if info.need_retry():
                 url = self.block_url_v2(
                     host, self.bucket_name) + '/%s/%d' % (self.uploadId,
                                                           index + 1)
                 ret, info = self.make_block_v2(block, url)
                 if ret is None:
                     return ret, info
             del ret['md5']
             ret['partNumber'] = index_
         self.blockStatus.append(ret)
         offset += length
         self.record_upload_progress(offset)
         if (callable(self.progress_handler)):
             self.progress_handler(
                 ((len(self.blockStatus) - 1) * self.part_size) +
                 len(block), self.size)
     if self.version == 'v1':
         return self.make_file(host)
     elif self.version == 'v2':
         make_file_url = self.block_url_v2(
             host, self.bucket_name) + '/%s' % self.uploadId
         return self.make_file_v2(self.blockStatus, make_file_url,
                                  self.file_name, self.mime_type,
                                  self.params)