|
| 1 | +import concurrent.futures |
1 | 2 | import io |
2 | 3 | import json |
3 | 4 | import logging |
@@ -564,34 +565,16 @@ def copy_image( |
564 | 565 | LIMITED_FUNCTIONS[source_project_metadata["project"].project_type] |
565 | 566 | ) |
566 | 567 |
|
567 | | - img_bytes = get_image_bytes(project=source_project, image_name=image_name) |
568 | | - |
569 | | - s3_response = controller.upload_image_to_s3( |
570 | | - project_name=destination_project, image_path=image_name, image_bytes=img_bytes |
571 | | - ) |
572 | | - if s3_response.errors: |
573 | | - raise AppException(s3_response.errors) |
574 | | - image_entity = s3_response.data |
575 | | - del img_bytes |
576 | | - |
577 | | - annotation_status = None |
578 | | - if copy_annotation_status: |
579 | | - res = controller.get_image( |
580 | | - project_name=source_project_name, |
581 | | - image_name=image_name, |
582 | | - folder_path=source_folder_name, |
583 | | - ) |
584 | | - annotation_status = constances.AnnotationStatus.get_name( |
585 | | - res.annotation_status_code |
586 | | - ) |
587 | | - |
588 | | - controller.attach_urls( |
589 | | - project_name=destination_project, |
590 | | - files=[image_entity], |
591 | | - folder_name=destination_folder, |
592 | | - annotation_status=annotation_status, |
593 | | - upload_state_code=constances.UploadState.BASIC.value, |
| 568 | + response = controller.copy_image( |
| 569 | + from_project_name=source_project_name, |
| 570 | + from_folder_name=source_folder_name, |
| 571 | + to_project_name=destination_project, |
| 572 | + to_folder_name=destination_folder, |
| 573 | + image_name=image_name, |
| 574 | + copy_annotation_status=copy_annotation_status |
594 | 575 | ) |
| 576 | + if response.errors: |
| 577 | + raise AppException(response.errors) |
595 | 578 |
|
596 | 579 | if include_annotations: |
597 | 580 | controller.copy_image_annotation_classes( |
@@ -729,8 +712,8 @@ def move_images( |
729 | 712 | source_project: Union[NotEmptyStr, dict], |
730 | 713 | image_names: Optional[List[NotEmptyStr]], |
731 | 714 | destination_project: Union[NotEmptyStr, dict], |
732 | | - *_, |
733 | | - **__, |
| 715 | + *args, |
| 716 | + **kwargs, |
734 | 717 | ): |
735 | 718 | """Move images in bulk between folders in a project |
736 | 719 |
|
@@ -1011,7 +994,7 @@ def delete_image(project: Union[NotEmptyStr, dict], image_name: str): |
1011 | 994 |
|
1012 | 995 | @Trackable |
1013 | 996 | @validate_arguments |
1014 | | -def get_image_metadata(project: Union[NotEmptyStr, dict], image_name: str, *_, **__): |
| 997 | +def get_image_metadata(project: Union[NotEmptyStr, dict], image_name: str, *args, **kwargs): |
1015 | 998 | """Returns image metadata |
1016 | 999 |
|
1017 | 1000 | :param project: project name or folder path (e.g., "project1/folder1") |
@@ -2009,16 +1992,15 @@ def move_image( |
2009 | 1992 | :type copy_pin: bool |
2010 | 1993 | """ |
2011 | 1994 | source_project_name, source_folder_name = extract_project_folder(source_project) |
2012 | | - destination_project_name, destination_folder = extract_project_folder( |
2013 | | - destination_project |
2014 | | - ) |
2015 | | - response = controller.move_image( |
| 1995 | + destination_project_name, destination_folder = extract_project_folder(destination_project) |
| 1996 | + response = controller.copy_image( |
2016 | 1997 | from_project_name=source_project_name, |
2017 | 1998 | from_folder_name=source_folder_name, |
2018 | 1999 | to_project_name=destination_project_name, |
2019 | 2000 | to_folder_name=destination_folder, |
2020 | 2001 | image_name=image_name, |
2021 | 2002 | copy_annotation_status=copy_annotation_status, |
| 2003 | + move=True |
2022 | 2004 | ) |
2023 | 2005 | if response.errors: |
2024 | 2006 | raise AppException(response.errors) |
@@ -2271,13 +2253,11 @@ def attach_image_urls_to_project( |
2271 | 2253 | annotation_status=annotation_status, |
2272 | 2254 | ) |
2273 | 2255 | if use_case.is_valid(): |
2274 | | - with tqdm( |
2275 | | - total=use_case.attachments_count, desc="Attaching urls" |
2276 | | - ) as progress_bar: |
| 2256 | + with tqdm(total=use_case.attachments_count, desc="Attaching urls") as progress_bar: |
2277 | 2257 | for _ in use_case.execute(): |
2278 | 2258 | progress_bar.update(1) |
2279 | 2259 | uploaded, duplications = use_case.data |
2280 | | - uploaded = [i["name"] for i in uploaded] |
| 2260 | + uploaded = [i['name'] for i in uploaded] |
2281 | 2261 | duplications.extend(duplicate_images) |
2282 | 2262 | failed_images = [ |
2283 | 2263 | image["name"] |
@@ -2324,13 +2304,11 @@ def attach_video_urls_to_project( |
2324 | 2304 | annotation_status=annotation_status, |
2325 | 2305 | ) |
2326 | 2306 | if use_case.is_valid(): |
2327 | | - with tqdm( |
2328 | | - total=use_case.attachments_count, desc="Attaching urls" |
2329 | | - ) as progress_bar: |
| 2307 | + with tqdm(total=use_case.attachments_count, desc="Attaching urls") as progress_bar: |
2330 | 2308 | for _ in use_case.execute(): |
2331 | 2309 | progress_bar.update(1) |
2332 | 2310 | uploaded, duplications = use_case.data |
2333 | | - uploaded = [i["name"] for i in uploaded] |
| 2311 | + uploaded = [i['name'] for i in uploaded] |
2334 | 2312 | duplications.extend(duplicate_images) |
2335 | 2313 | failed_images = [ |
2336 | 2314 | image["name"] |
@@ -3324,7 +3302,7 @@ def upload_image_to_project( |
3324 | 3302 | image=img, |
3325 | 3303 | annotation_status=annotation_status, |
3326 | 3304 | from_s3_bucket=from_s3_bucket, |
3327 | | - image_quality_in_editor=image_quality_in_editor, |
| 3305 | + image_quality_in_editor=image_quality_in_editor |
3328 | 3306 | ) |
3329 | 3307 | if response.errors: |
3330 | 3308 | raise AppException(response.errors) |
@@ -3535,13 +3513,11 @@ def attach_document_urls_to_project( |
3535 | 3513 | annotation_status=annotation_status, |
3536 | 3514 | ) |
3537 | 3515 | if use_case.is_valid(): |
3538 | | - with tqdm( |
3539 | | - total=use_case.attachments_count, desc="Attaching urls" |
3540 | | - ) as progress_bar: |
| 3516 | + with tqdm(total=use_case.attachments_count, desc="Attaching urls") as progress_bar: |
3541 | 3517 | for _ in use_case.execute(): |
3542 | 3518 | progress_bar.update(1) |
3543 | 3519 | uploaded, duplications = use_case.data |
3544 | | - uploaded = [i["name"] for i in uploaded] |
| 3520 | + uploaded = [i['name'] for i in uploaded] |
3545 | 3521 | duplications.extend(duplicate_images) |
3546 | 3522 | failed_images = [ |
3547 | 3523 | image["name"] |
|
0 commit comments