5252
5353class GetImagesUseCase (BaseUseCase ):
5454 def __init__ (
55- self ,
56- project : ProjectEntity ,
57- folder : FolderEntity ,
58- images : BaseReadOnlyRepository ,
59- annotation_status : str = None ,
60- image_name_prefix : str = None ,
55+ self ,
56+ project : ProjectEntity ,
57+ folder : FolderEntity ,
58+ images : BaseReadOnlyRepository ,
59+ annotation_status : str = None ,
60+ image_name_prefix : str = None ,
6161 ):
6262 super ().__init__ ()
6363 self ._project = project
@@ -74,18 +74,18 @@ def validate_project_type(self):
7474
7575 def validate_annotation_status (self ):
7676 if (
77- self ._annotation_status
78- and self ._annotation_status .lower ()
79- not in constances .AnnotationStatus .values ()
77+ self ._annotation_status
78+ and self ._annotation_status .lower ()
79+ not in constances .AnnotationStatus .values ()
8080 ):
8181 raise AppValidationException ("Invalid annotations status." )
8282
8383 def execute (self ):
8484 if self .is_valid ():
8585 condition = (
86- Condition ("team_id" , self ._project .team_id , EQ )
87- & Condition ("project_id" , self ._project .uuid , EQ )
88- & Condition ("folder_id" , self ._folder .uuid , EQ )
86+ Condition ("team_id" , self ._project .team_id , EQ )
87+ & Condition ("project_id" , self ._project .uuid , EQ )
88+ & Condition ("folder_id" , self ._folder .uuid , EQ )
8989 )
9090 if self ._image_name_prefix :
9191 condition = condition & Condition ("name" , self ._image_name_prefix , EQ )
@@ -102,12 +102,12 @@ def execute(self):
102102
103103class GetImageUseCase (BaseUseCase ):
104104 def __init__ (
105- self ,
106- project : ProjectEntity ,
107- folder : FolderEntity ,
108- image_name : str ,
109- images : BaseReadOnlyRepository ,
110- service : SuerannotateServiceProvider ,
105+ self ,
106+ project : ProjectEntity ,
107+ folder : FolderEntity ,
108+ image_name : str ,
109+ images : BaseReadOnlyRepository ,
110+ service : SuerannotateServiceProvider ,
111111 ):
112112 super ().__init__ ()
113113 self ._project = project
@@ -137,11 +137,11 @@ def execute(self):
137137
138138class GetAllImagesUseCase (BaseUseCase ):
139139 def __init__ (
140- self ,
141- project : ProjectEntity ,
142- service_provider : SuerannotateServiceProvider ,
143- annotation_status : str = None ,
144- name_prefix : str = None ,
140+ self ,
141+ project : ProjectEntity ,
142+ service_provider : SuerannotateServiceProvider ,
143+ annotation_status : str = None ,
144+ name_prefix : str = None ,
145145 ):
146146 super ().__init__ ()
147147 self ._project = project
@@ -155,9 +155,9 @@ def annotation_status(self):
155155
156156 def execute (self ):
157157 condition = (
158- Condition ("team_id" , self ._project .team_id , EQ )
159- & Condition ("project_id" , self ._project .uuid , EQ )
160- & Condition ("folder_id" , 0 , EQ )
158+ Condition ("team_id" , self ._project .team_id , EQ )
159+ & Condition ("project_id" , self ._project .uuid , EQ )
160+ & Condition ("folder_id" , 0 , EQ )
161161 )
162162 if self ._annotation_status :
163163 condition &= Condition ("annotation_status" , self .annotation_status , EQ )
@@ -1991,13 +1991,7 @@ def validate_limitations(self):
19911991 errors = []
19921992 if response .data .folder_limit .remaining_image_count < 1 :
19931993 errors .append (constances .ATTACH_FOLDER_LIMIT_ERROR_MESSAGE )
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 :
1994+ elif self ._to_project .uuid != self ._from_project .uuid and response .data .project_limit .remaining_image_count < 1 :
20011995 errors .append (constances .ATTACH_PROJECT_LIMIT_ERROR_MESSAGE )
20021996 if errors :
20031997 raise AppValidationException ("\n " .join (errors ))
@@ -2031,7 +2025,7 @@ def execute(self) -> Response:
20312025 image = image_bytes ,
20322026 project_settings = self ._project_settings ,
20332027 upload_path = auth_data ["filePath" ],
2034- s3_repo = self ._to_upload_s3_repo
2028+ s3_repo = self ._to_upload_s3_repo ,
20352029 ).execute ()
20362030 if s3_response .errors :
20372031 raise AppException (s3_response .errors )
@@ -2043,7 +2037,9 @@ def execute(self) -> Response:
20432037 folder = self ._to_folder ,
20442038 attachments = [image_entity ],
20452039 backend_service_provider = self ._backend_service ,
2046- annotation_status = image .annotation_status_code if self ._copy_annotation_status else None ,
2040+ annotation_status = image .annotation_status_code
2041+ if self ._copy_annotation_status
2042+ else None ,
20472043 upload_state_code = constances .UploadState .BASIC .value ,
20482044 ).execute ()
20492045 self ._response .data = image_entity
@@ -2613,8 +2609,8 @@ def execute(self):
26132609 failed_annotations = []
26142610 for _ in range (0 , len (self .annotations_to_upload ), self .AUTH_DATA_CHUNK_SIZE ):
26152611 annotations_to_upload = self .annotations_to_upload [
2616- _ : _ + self .AUTH_DATA_CHUNK_SIZE # noqa: E203
2617- ]
2612+ _ : _ + self .AUTH_DATA_CHUNK_SIZE # noqa: E203
2613+ ]
26182614
26192615 if self ._pre_annotation :
26202616 response = self ._backend_service .get_pre_annotation_upload_data (
@@ -2689,7 +2685,7 @@ def execute(self):
26892685 return self ._response
26902686
26912687 def upload_to_s3 (
2692- self , image_id : int , image_info , bucket , from_s3 , image_id_name_map
2688+ self , image_id : int , image_info , bucket , from_s3 , image_id_name_map
26932689 ):
26942690 if from_s3 :
26952691 file = io .BytesIO ()
@@ -2712,14 +2708,14 @@ def upload_to_s3(
27122708 )
27132709 if self ._project .project_type == constances .ProjectType .PIXEL .value :
27142710 mask_filename = (
2715- image_id_name_map [image_id ].name + constances .ANNOTATION_MASK_POSTFIX
2711+ image_id_name_map [image_id ].name + constances .ANNOTATION_MASK_POSTFIX
27162712 )
27172713 if from_s3 :
27182714 file = io .BytesIO ()
2719- s3_object = self . _client_s3_bucket . Objcect (
2720- self ._client_s3_bucket , self ._folder_path + mask_filename
2715+ s3_object = from_s3 . Object (
2716+ self ._client_s3_bucket , f" { self ._folder_path } / { mask_filename } "
27212717 )
2722- s3_object .download_file (file )
2718+ s3_object .download_fileobj (file )
27232719 file .seek (0 )
27242720 else :
27252721 with open (f"{ self ._folder_path } /{ mask_filename } " , "rb" ) as mask_file :
0 commit comments