Skip to content

Commit efeba55

Browse files
Vaghinak BasentsyanVaghinak Basentsyan
authored andcommitted
copy_image changed
1 parent a0b9100 commit efeba55

File tree

4 files changed

+31
-37
lines changed

4 files changed

+31
-37
lines changed

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -566,34 +566,16 @@ def copy_image(
566566
LIMITED_FUNCTIONS[source_project_metadata["project"].project_type]
567567
)
568568

569-
img_bytes = get_image_bytes(project=source_project, image_name=image_name)
570-
571-
s3_response = controller.upload_image_to_s3(
572-
project_name=destination_project, image_path=image_name, image_bytes=img_bytes
573-
)
574-
if s3_response.errors:
575-
raise AppException(s3_response.errors)
576-
image_entity = s3_response.data
577-
del img_bytes
578-
579-
annotation_status = None
580-
if copy_annotation_status:
581-
res = controller.get_image(
582-
project_name=source_project_name,
583-
image_name=image_name,
584-
folder_path=source_folder_name,
585-
)
586-
annotation_status = constances.AnnotationStatus.get_name(
587-
res.annotation_status_code
588-
)
589-
590-
controller.attach_urls(
591-
project_name=destination_project,
592-
files=[image_entity],
593-
folder_name=destination_folder,
594-
annotation_status=annotation_status,
595-
upload_state_code=constances.UploadState.BASIC.value,
569+
response = controller.copy_image(
570+
from_project_name=source_project_name,
571+
from_folder_name=source_folder_name,
572+
to_project_name=destination_project,
573+
to_folder_name=destination_folder,
574+
image_name=image_name,
575+
copy_annotation_status=copy_annotation_status
596576
)
577+
if response.errors:
578+
raise AppException(response.errors)
597579

598580
if include_annotations:
599581
controller.copy_image_annotation_classes(
@@ -2010,13 +1992,14 @@ def move_image(
20101992
"""
20111993
source_project_name, source_folder_name = extract_project_folder(source_project)
20121994
destination_project_name, destination_folder = extract_project_folder(destination_project)
2013-
response = controller.move_image(
1995+
response = controller.copy_image(
20141996
from_project_name=source_project_name,
20151997
from_folder_name=source_folder_name,
20161998
to_project_name=destination_project_name,
20171999
to_folder_name=destination_folder,
20182000
image_name=image_name,
2019-
copy_annotation_status=copy_annotation_status
2001+
copy_annotation_status=copy_annotation_status,
2002+
move=True
20202003
)
20212004
if response.errors:
20222005
raise AppException(response.errors)

src/superannotate/lib/core/usecases/images.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,7 +1935,7 @@ def execute(self):
19351935
return self._response
19361936

19371937

1938-
class MoveImageUseCase(BaseUseCase):
1938+
class CopyImageUseCase(BaseUseCase):
19391939
def __init__(
19401940
self,
19411941
from_project: ProjectEntity,
@@ -1950,6 +1950,7 @@ def __init__(
19501950
include_annotations: Optional[bool] = True,
19511951
copy_annotation_status: Optional[bool] = True,
19521952
copy_pin: Optional[bool] = True,
1953+
move=False
19531954
):
19541955
super().__init__()
19551956
self._from_project = from_project
@@ -1964,6 +1965,7 @@ def __init__(
19641965
self._copy_pin = copy_pin
19651966
self._backend_service = backend_service
19661967
self._images = images
1968+
self._move = move
19671969

19681970
def validate_copy_path(self):
19691971
if (
@@ -1989,7 +1991,13 @@ def validate_limitations(self):
19891991
errors = []
19901992
if response.data.folder_limit.remaining_image_count < 1:
19911993
errors.append(constances.ATTACH_FOLDER_LIMIT_ERROR_MESSAGE)
1992-
elif self._to_project.uuid != self._from_project.uuid and response.data.project_limit.remaining_image_count < 1:
1994+
elif (
1995+
self._move
1996+
and self._to_project.uuid != self._from_project.uuid
1997+
and response.data.project_limit.remaining_image_count < 1
1998+
):
1999+
errors.append(constances.ATTACH_PROJECT_LIMIT_ERROR_MESSAGE)
2000+
elif not self._move and response.data.project_limit.remaining_image_count < 1:
19932001
errors.append(constances.ATTACH_PROJECT_LIMIT_ERROR_MESSAGE)
19942002
if errors:
19952003
raise AppValidationException("\n".join(errors))

src/superannotate/lib/infrastructure/controller.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,19 +699,20 @@ def get_image_bytes(
699699
)
700700
return use_case.execute()
701701

702-
def move_image(
702+
def copy_image(
703703
self,
704704
from_project_name: str,
705705
from_folder_name: str,
706706
to_project_name: str,
707707
to_folder_name: str,
708708
image_name: str,
709-
copy_annotation_status: bool = False
709+
copy_annotation_status: bool = False,
710+
move: bool = False
710711
):
711712
from_project = self._get_project(from_project_name)
712713
to_project = self._get_project(to_project_name)
713714
to_folder = self._get_folder(to_project, to_folder_name)
714-
use_case = usecases.MoveImageUseCase(
715+
use_case = usecases.CopyImageUseCase(
715716
from_project=from_project,
716717
from_folder=self._get_folder(from_project, from_folder_name),
717718
to_project=to_project,
@@ -721,7 +722,8 @@ def move_image(
721722
images=self.images,
722723
project_settings=ProjectSettingsRepository(self._backend_client, to_project).get_all(),
723724
to_upload_s3_repo=self.get_s3_repository(self.team_id, to_project.uuid, to_folder.uuid),
724-
copy_annotation_status=copy_annotation_status
725+
copy_annotation_status=copy_annotation_status,
726+
move=move
725727
)
726728
return use_case.execute()
727729

tests/integration/test_depricated_functions_document.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import os
22
from os.path import dirname
3+
from unittest import TestCase
4+
35
import src.superannotate as sa
46
from src.superannotate import AppException
5-
from tests.integration.base import BaseTestCase
67
from src.superannotate.lib.core import LIMITED_FUNCTIONS
78
from src.superannotate.lib.core import ProjectType
89
from src.superannotate.lib.core import DEPRICATED_DOCUMENT_VIDEO_MESSAGE
910

1011

11-
class TestDepricatedFunctionsDocument(BaseTestCase):
12+
class TestDeprecatedFunctionsDocument(TestCase):
1213
PROJECT_NAME = "document proj 11"
1314
PROJECT_DESCRIPTION = "desc"
1415
PROJECT_TYPE = "Document"

0 commit comments

Comments
 (0)