|
40 | 40 | from lib.core.repositories import BaseManageableRepository |
41 | 41 | from lib.core.repositories import BaseReadOnlyRepository |
42 | 42 | from lib.core.response import Response |
| 43 | +from lib.core.reporter import Progress |
43 | 44 | from lib.core.serviceproviders import SuerannotateServiceProvider |
44 | 45 | from lib.core.usecases.base import BaseInteractiveUseCase |
45 | 46 | from lib.core.usecases.base import BaseReportableUseCae |
@@ -3237,40 +3238,37 @@ def execute(self) -> Response: |
3237 | 3238 | continue |
3238 | 3239 | uploaded_paths = [] |
3239 | 3240 | for _ in frames_generator: |
3240 | | - use_case = UploadImagesFromFolderToProject( |
3241 | | - project=self._project, |
3242 | | - folder=self._folder, |
3243 | | - backend_client=self._service, |
3244 | | - folder_path=temp_path, |
3245 | | - settings=self._settings, |
3246 | | - s3_repo=self._s3_repo, |
3247 | | - annotation_status=self.annotation_status, |
3248 | | - image_quality_in_editor=self._image_quality_in_editor, |
3249 | | - ) |
| 3241 | + with Progress(total_frames_count, f"Uploading {Path(path).name}") as progress: |
| 3242 | + use_case = UploadImagesFromFolderToProject( |
| 3243 | + project=self._project, |
| 3244 | + folder=self._folder, |
| 3245 | + backend_client=self._service, |
| 3246 | + folder_path=temp_path, |
| 3247 | + settings=self._settings, |
| 3248 | + s3_repo=self._s3_repo, |
| 3249 | + annotation_status=self.annotation_status, |
| 3250 | + image_quality_in_editor=self._image_quality_in_editor, |
| 3251 | + ) |
3250 | 3252 |
|
3251 | | - images_to_upload, duplicates = use_case.images_to_upload |
3252 | | - if not len(images_to_upload): |
3253 | | - continue |
3254 | | - progress = self.reporter.get_progress_bar( |
3255 | | - total_frames_count, f"Uploading {Path(path).name}" |
3256 | | - ) |
3257 | | - if use_case.is_valid(): |
3258 | | - for _ in use_case.execute(): |
3259 | | - progress.update() |
3260 | | - |
3261 | | - uploaded, failed_images, _ = use_case.response.data |
3262 | | - uploaded_paths.extend(uploaded) |
3263 | | - if failed_images: |
3264 | | - self.reporter.log_warning( |
3265 | | - f"Failed {len(failed_images)}." |
3266 | | - ) |
3267 | | - files = os.listdir(temp_path) |
3268 | | - image_paths = [f"{temp_path}/{f}" for f in files] |
3269 | | - for image_path in image_paths: |
3270 | | - os.remove(image_path) |
3271 | | - else: |
3272 | | - raise AppException(use_case.response.errors) |
3273 | | - progress.close() |
| 3253 | + images_to_upload, duplicates = use_case.images_to_upload |
| 3254 | + if not len(images_to_upload): |
| 3255 | + continue |
| 3256 | + if use_case.is_valid(): |
| 3257 | + for _ in use_case.execute(): |
| 3258 | + progress.update() |
| 3259 | + |
| 3260 | + uploaded, failed_images, _ = use_case.response.data |
| 3261 | + uploaded_paths.extend(uploaded) |
| 3262 | + if failed_images: |
| 3263 | + self.reporter.log_warning( |
| 3264 | + f"Failed {len(failed_images)}." |
| 3265 | + ) |
| 3266 | + files = os.listdir(temp_path) |
| 3267 | + image_paths = [f"{temp_path}/{f}" for f in files] |
| 3268 | + for image_path in image_paths: |
| 3269 | + os.remove(image_path) |
| 3270 | + else: |
| 3271 | + raise AppException(use_case.response.errors) |
3274 | 3272 | data[str(path)] = uploaded_paths |
3275 | 3273 | self._response.data = data |
3276 | 3274 | return self._response |
0 commit comments