コード例 #1
0
 def handle(self):
     try:
         size = os.path.getsize(self.local_path)
         with open(self.local_path, 'rb') as f:
             item = self.drive.upload_file(
                 filename=self.item_name,
                 data=f,
                 size=size,
                 parent_path=self.remote_parent_path,
                 conflict_behavior=self._conflict_behavior)
             modified_time = timestamp_to_datetime(
                 os.path.getmtime(self.local_path))
             fs_info = facets.FileSystemInfoFacet(
                 modified_time=modified_time)
             item = self.drive.update_item(item_id=item.id,
                                           new_file_system_info=fs_info)
             self.items_store.update_item(item, ItemRecordStatuses.OK)
             self.logger.info('Uploaded file "%s".', self.local_path)
     except (IOError, OSError) as e:
         self.logger.error('IO error when uploading "%s": %s.',
                           self.local_path, e)
     except errors.OneDriveError as e:
         self.logger.error('API error when uploading "%s": %s.',
                           self.local_path, e)
     self.task_pool.clear_hold(self)
コード例 #2
0
ファイル: test_up_tasks.py プロジェクト: rjmuniz/onedrive-d
 def test_handle(self):
     with mock.patch(
             'onedrived.api.facets.FileSystemInfoFacet') as mock_class:
         self.task.handle()
         mock_class.assert_called_once_with(
             modified_time=timestamp_to_datetime(self.new_mtime))
     self.assertEqual(
         1,
         len(self.task.items_store.get_items_by_id(item_id=self.item.id)))
コード例 #3
0
ファイル: up_task.py プロジェクト: tinghitella/onedrive-d
 def handle(self):
     try:
         size = os.path.getsize(self.local_path)
         with open(self.local_path, 'rb') as f:
             item = self.drive.upload_file(
                     filename=self.item_name, data=f, size=size, parent_path=self.remote_parent_path,
                     conflict_behavior=self._conflict_behavior)
             modified_time = timestamp_to_datetime(os.path.getmtime(self.local_path))
             fs_info = facets.FileSystemInfoFacet(modified_time=modified_time)
             item = self.drive.update_item(item_id=item.id, new_file_system_info=fs_info)
             self.items_store.update_item(item, ItemRecordStatuses.OK)
             self.logger.info('Uploaded file "%s".', self.local_path)
     except (IOError, OSError) as e:
         self.logger.error('IO error when uploading "%s": %s.', self.local_path, e)
     except errors.OneDriveError as e:
         self.logger.error('API error when uploading "%s": %s.', self.local_path, e)
コード例 #4
0
ファイル: up_task.py プロジェクト: GitGrezly/onedrive-d
 def __init__(self, parent_task, rel_parent_path, item_name, new_mtime):
     super().__init__(parent_task, rel_parent_path, item_name, None)
     if isinstance(new_mtime, int):
         new_mtime = timestamp_to_datetime(new_mtime)
     self._new_mtime = new_mtime
コード例 #5
0
 def __init__(self, parent_task, rel_parent_path, item_name, new_mtime):
     super().__init__(parent_task, rel_parent_path, item_name, None)
     if isinstance(new_mtime, int):
         new_mtime = timestamp_to_datetime(new_mtime)
     self._new_mtime = new_mtime
コード例 #6
0
 def test_handle(self):
     with mock.patch("onedrived.api.facets.FileSystemInfoFacet") as mock_class:
         self.task.handle()
         mock_class.assert_called_once_with(modified_time=timestamp_to_datetime(self.new_mtime))
     self.assertEqual(1, len(self.task.items_store.get_items_by_id(item_id=self.item.id)))