Exemple #1
0
 def handle(self):
     try:
         self._async_status.update_status()
         if self._async_status.status == options.AsyncOperationStatuses.FAILED:
             # If failed, fall back to an upload task.
             if os.path.isfile(self.local_path):
                 self.logger.info(
                     'Server failed to copy to item "%s". Upload the file instead.',
                     self.remote_path)
                 self.task_pool.add_task(
                     UploadFileTask(self,
                                    rel_parent_path=self.rel_parent_path,
                                    item_name=self.item_name))
             else:
                 self.logger.error(
                     'Failed to copy file "%s" to server and local entry is no longer a file. Abort.',
                     self.local_path)
         elif self._async_status.status == options.AsyncOperationStatuses.COMPLETED:
             # If completed, update the item.
             item = self._async_status.get_item()
             self.items_store.update_item(item, ItemRecordStatuses.OK)
             self.logger.info('Successfully copied file "%s" to server',
                              self.local_path)
         else:
             # Put the task back to task pool.
             th = threading.Thread(target=self.put_back, args=())
             th.daemon = True
             th.start()
     except errors.OneDriveError as e:
         self.logger.error(
             'API error when polling copy status for file "%s": %s.',
             self.local_path, e)
Exemple #2
0
 def _create_upload_task(self, local_item_name, is_dir):
     if is_dir:
         self._create_remote_dir(local_item_name)
     else:
         self.logger.debug('Created task uploading file "%s/%s".',
                           self.rel_path, local_item_name)
         self.task_pool.add_task(
             UploadFileTask(self, self.rel_path + '/', local_item_name))
Exemple #3
0
 def setUp(self):
     self.initialize_obj()
     self.task = UploadFileTask(self.parent_task, '/', self.data['name'])
     self.parent_task.drive.upload_file = mock.MagicMock(
         return_value=self.item)