Esempio n. 1
0
 def slice_upload(self):
     '''分片上传'''
     self.is_slice_upload = True
     fid = self.row[FID_COL]
     slice_start = self.row[CURRSIZE_COL]
     slice_end = self.row[CURRSIZE_COL]
     file_size = os.path.getsize(self.row[SOURCEPATH_COL])
     if file_size < slice_start:
         self.emit('disk-error', fid)
         return
     elif file_size == slice_start and slice_start == self.row[SIZE_COL]:
         self.emit('uploaded', fid)
         return
     fh = open(self.row[SOURCEPATH_COL], 'rb')
     fh.seek(slice_start)
     while self.row[STATE_COL] == State.UPLOADING:
         if slice_end >= file_size:
             self.emit('merge-files', self.row[FID_COL])
             break
         slice_start = slice_end
         slice_end = min(slice_start + self.row[THRESHOLD_COL], file_size)
         data = fh.read(slice_end - slice_start)
         slice_end = slice_start + len(data)
         info = pcs.slice_upload(self.cookie, data)
         if info and 'md5' in info:
             self.emit('slice-sent', fid, slice_end, info['md5'])
         else:
             self.emit('network-error', fid)
             break
     if not fh.closed:
         fh.close()
     return
Esempio n. 2
0
 def slice_upload(self):
     '''分片上传'''
     self.is_slice_upload = True
     fid = self.row[FID_COL]
     slice_start = self.row[CURRSIZE_COL]
     slice_end = self.row[CURRSIZE_COL]
     file_size = os.path.getsize(self.row[SOURCEPATH_COL])
     if file_size < slice_start:
         self.emit('disk-error', fid)
         return
     elif file_size == slice_start and slice_start == self.row[SIZE_COL]:
         self.emit('uploaded', fid)
         return
     fh = open(self.row[SOURCEPATH_COL], 'rb')
     fh.seek(slice_start)
     while self.row[STATE_COL] == State.UPLOADING:
         if slice_end >= file_size:
             self.emit('merge-files', self.row[FID_COL])
             break
         slice_start = slice_end
         slice_end = min(slice_start + self.row[THRESHOLD_COL], file_size)
         data = fh.read(slice_end - slice_start)
         slice_end = slice_start + len(data)
         info = pcs.slice_upload(self.cookie, data)
         if info and 'md5' in info:
             self.emit('slice-sent', fid, slice_end, info['md5'])
         else:
             self.emit('network-error', fid)
             break
     if not fh.closed:
         fh.close()
     return
Esempio n. 3
0
 def slice_upload(self):
     print('Uploader.slice_upload()')
     fid = self.row[FID_COL]
     slice_start = self.row[CURRSIZE_COL]
     slice_end = self.row[CURRSIZE_COL]
     file_size = os.path.getsize(self.row[SOURCEPATH_COL])
     if file_size < slice_start:
         self.emit('disk-error', fid)
         return
     elif file_size == slice_start and slice_start == self.row[SIZE_COL]:
         self.emit('uploaded', fid)
         return
     fh = open(self.row[SOURCEPATH_COL], 'rb')
     fh.seek(slice_start)
     while self.row[STATE_COL] == State.UPLOADING:
         if slice_end >= file_size:
             print('will emit merge-files signal:', fid)
             self.emit('merge-files', self.row[FID_COL])
             break
         slice_start = slice_end
         slice_end = min(slice_start + self.threshold, file_size)
         data = fh.read(slice_end - slice_start)
         slice_end = slice_start + len(data)
         info = pcs.slice_upload(self.cookie, data)
         if info and 'md5' in info:
             print('will emit slice-sent signal:', fid, slice_end, info['md5'])
             self.emit('slice-sent', fid, slice_end, info['md5'])
         else:
             print('Failed to upload this slice:', slice_start, slice_end)
             self.emit('network-error', fid)
             break
     if not fh.closed:
         fh.close()
     return
Esempio n. 4
0
 def slice_upload(self):
     """分片上传"""
     self.is_slice_upload = True
     fid = self.row[FID_COL]
     slice_start = self.row[CURRSIZE_COL]
     slice_end = self.row[CURRSIZE_COL]
     file_size = os.path.getsize(self.row[SOURCEPATH_COL])
     if file_size < slice_start:
         self.emit("disk-error", fid)
         return
     elif file_size == slice_start and slice_start == self.row[SIZE_COL]:
         self.emit("uploaded", fid)
         return
     fh = open(self.row[SOURCEPATH_COL], "rb")
     fh.seek(slice_start)
     while self.row[STATE_COL] == State.UPLOADING:
         if slice_end >= file_size:
             self.emit("merge-files", self.row[FID_COL])
             break
         slice_start = slice_end
         slice_end = min(slice_start + self.row[THRESHOLD_COL], file_size)
         data = fh.read(slice_end - slice_start)
         slice_end = slice_start + len(data)
         info = pcs.slice_upload(self.cookie, data)
         if info and "md5" in info:
             self.emit("slice-sent", fid, slice_end, info["md5"])
         else:
             self.emit("network-error", fid)
             break
     if not fh.closed:
         fh.close()
     return