From efeba55daf3475863589b7274d66db13012c004e Mon Sep 17 00:00:00 2001 From: Vaghinak Basentsyan Date: Tue, 28 Sep 2021 12:56:04 +0400 Subject: [PATCH 1/2] copy_image changed --- .../lib/app/interface/sdk_interface.py | 41 ++++++------------- src/superannotate/lib/core/usecases/images.py | 12 +++++- .../lib/infrastructure/controller.py | 10 +++-- .../test_depricated_functions_document.py | 5 ++- 4 files changed, 31 insertions(+), 37 deletions(-) diff --git a/src/superannotate/lib/app/interface/sdk_interface.py b/src/superannotate/lib/app/interface/sdk_interface.py index 5852c62f7..2a301dc80 100644 --- a/src/superannotate/lib/app/interface/sdk_interface.py +++ b/src/superannotate/lib/app/interface/sdk_interface.py @@ -566,34 +566,16 @@ def copy_image( LIMITED_FUNCTIONS[source_project_metadata["project"].project_type] ) - img_bytes = get_image_bytes(project=source_project, image_name=image_name) - - s3_response = controller.upload_image_to_s3( - project_name=destination_project, image_path=image_name, image_bytes=img_bytes - ) - if s3_response.errors: - raise AppException(s3_response.errors) - image_entity = s3_response.data - del img_bytes - - annotation_status = None - if copy_annotation_status: - res = controller.get_image( - project_name=source_project_name, - image_name=image_name, - folder_path=source_folder_name, - ) - annotation_status = constances.AnnotationStatus.get_name( - res.annotation_status_code - ) - - controller.attach_urls( - project_name=destination_project, - files=[image_entity], - folder_name=destination_folder, - annotation_status=annotation_status, - upload_state_code=constances.UploadState.BASIC.value, + response = controller.copy_image( + from_project_name=source_project_name, + from_folder_name=source_folder_name, + to_project_name=destination_project, + to_folder_name=destination_folder, + image_name=image_name, + copy_annotation_status=copy_annotation_status ) + if response.errors: + raise AppException(response.errors) if include_annotations: controller.copy_image_annotation_classes( @@ -2010,13 +1992,14 @@ def move_image( """ source_project_name, source_folder_name = extract_project_folder(source_project) destination_project_name, destination_folder = extract_project_folder(destination_project) - response = controller.move_image( + response = controller.copy_image( from_project_name=source_project_name, from_folder_name=source_folder_name, to_project_name=destination_project_name, to_folder_name=destination_folder, image_name=image_name, - copy_annotation_status=copy_annotation_status + copy_annotation_status=copy_annotation_status, + move=True ) if response.errors: raise AppException(response.errors) diff --git a/src/superannotate/lib/core/usecases/images.py b/src/superannotate/lib/core/usecases/images.py index c88b7867d..c7f4a5d9c 100644 --- a/src/superannotate/lib/core/usecases/images.py +++ b/src/superannotate/lib/core/usecases/images.py @@ -1935,7 +1935,7 @@ def execute(self): return self._response -class MoveImageUseCase(BaseUseCase): +class CopyImageUseCase(BaseUseCase): def __init__( self, from_project: ProjectEntity, @@ -1950,6 +1950,7 @@ def __init__( include_annotations: Optional[bool] = True, copy_annotation_status: Optional[bool] = True, copy_pin: Optional[bool] = True, + move=False ): super().__init__() self._from_project = from_project @@ -1964,6 +1965,7 @@ def __init__( self._copy_pin = copy_pin self._backend_service = backend_service self._images = images + self._move = move def validate_copy_path(self): if ( @@ -1989,7 +1991,13 @@ def validate_limitations(self): errors = [] if response.data.folder_limit.remaining_image_count < 1: errors.append(constances.ATTACH_FOLDER_LIMIT_ERROR_MESSAGE) - elif self._to_project.uuid != self._from_project.uuid and response.data.project_limit.remaining_image_count < 1: + elif ( + self._move + and self._to_project.uuid != self._from_project.uuid + and response.data.project_limit.remaining_image_count < 1 + ): + errors.append(constances.ATTACH_PROJECT_LIMIT_ERROR_MESSAGE) + elif not self._move and response.data.project_limit.remaining_image_count < 1: errors.append(constances.ATTACH_PROJECT_LIMIT_ERROR_MESSAGE) if errors: raise AppValidationException("\n".join(errors)) diff --git a/src/superannotate/lib/infrastructure/controller.py b/src/superannotate/lib/infrastructure/controller.py index a894581e7..d2597704e 100644 --- a/src/superannotate/lib/infrastructure/controller.py +++ b/src/superannotate/lib/infrastructure/controller.py @@ -699,19 +699,20 @@ def get_image_bytes( ) return use_case.execute() - def move_image( + def copy_image( self, from_project_name: str, from_folder_name: str, to_project_name: str, to_folder_name: str, image_name: str, - copy_annotation_status: bool = False + copy_annotation_status: bool = False, + move: bool = False ): from_project = self._get_project(from_project_name) to_project = self._get_project(to_project_name) to_folder = self._get_folder(to_project, to_folder_name) - use_case = usecases.MoveImageUseCase( + use_case = usecases.CopyImageUseCase( from_project=from_project, from_folder=self._get_folder(from_project, from_folder_name), to_project=to_project, @@ -721,7 +722,8 @@ def move_image( images=self.images, project_settings=ProjectSettingsRepository(self._backend_client, to_project).get_all(), to_upload_s3_repo=self.get_s3_repository(self.team_id, to_project.uuid, to_folder.uuid), - copy_annotation_status=copy_annotation_status + copy_annotation_status=copy_annotation_status, + move=move ) return use_case.execute() diff --git a/tests/integration/test_depricated_functions_document.py b/tests/integration/test_depricated_functions_document.py index 742df03e3..f8444df61 100644 --- a/tests/integration/test_depricated_functions_document.py +++ b/tests/integration/test_depricated_functions_document.py @@ -1,14 +1,15 @@ import os from os.path import dirname +from unittest import TestCase + import src.superannotate as sa from src.superannotate import AppException -from tests.integration.base import BaseTestCase from src.superannotate.lib.core import LIMITED_FUNCTIONS from src.superannotate.lib.core import ProjectType from src.superannotate.lib.core import DEPRICATED_DOCUMENT_VIDEO_MESSAGE -class TestDepricatedFunctionsDocument(BaseTestCase): +class TestDeprecatedFunctionsDocument(TestCase): PROJECT_NAME = "document proj 11" PROJECT_DESCRIPTION = "desc" PROJECT_TYPE = "Document" From 998b28c54922625fe92146a81837364fdebb7638 Mon Sep 17 00:00:00 2001 From: shab Date: Tue, 28 Sep 2021 15:12:40 +0400 Subject: [PATCH 2/2] remove __ --- src/superannotate/lib/app/interface/sdk_interface.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/superannotate/lib/app/interface/sdk_interface.py b/src/superannotate/lib/app/interface/sdk_interface.py index 7e06c525c..f0f6c716d 100644 --- a/src/superannotate/lib/app/interface/sdk_interface.py +++ b/src/superannotate/lib/app/interface/sdk_interface.py @@ -712,8 +712,8 @@ def move_images( source_project: Union[NotEmptyStr, dict], image_names: Optional[List[NotEmptyStr]], destination_project: Union[NotEmptyStr, dict], - *_, - **__, + *args, + **kwargs, ): """Move images in bulk between folders in a project @@ -994,7 +994,7 @@ def delete_image(project: Union[NotEmptyStr, dict], image_name: str): @Trackable @validate_arguments -def get_image_metadata(project: Union[NotEmptyStr, dict], image_name: str, *_, **__): +def get_image_metadata(project: Union[NotEmptyStr, dict], image_name: str, *args, **kwargs): """Returns image metadata :param project: project name or folder path (e.g., "project1/folder1")