Skip to content

Commit 74bf115

Browse files
committed
Code cleanup
1 parent 5cdb714 commit 74bf115

File tree

1 file changed

+34
-48
lines changed

1 file changed

+34
-48
lines changed

superannotate/db/project_images.py

Lines changed: 34 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -179,37 +179,11 @@ def _copy_images(
179179
res['skipped'] += response.json()['skipped']
180180

181181
for image_name in image_names:
182-
if include_annotations:
183-
annotations = get_image_annotations(
184-
(source_project, source_project_folder), image_name
185-
)
186-
if annotations["annotation_json"] is not None:
187-
if "annotation_mask" in annotations:
188-
if annotations["annotation_mask"] is not None:
189-
upload_image_annotations(
190-
(destination_project, destination_project_folder),
191-
image_name, annotations["annotation_json"],
192-
annotations["annotation_mask"]
193-
)
194-
else:
195-
upload_image_annotations(
196-
(destination_project, destination_project_folder),
197-
image_name, annotations["annotation_json"]
198-
)
199-
if copy_annotation_status or copy_pin:
200-
img_metadata = get_image_metadata(
201-
(source_project, source_project_folder), image_name
202-
)
203-
if copy_annotation_status:
204-
set_image_annotation_status(
205-
(destination_project, destination_project_folder),
206-
image_name, img_metadata["annotation_status"]
207-
)
208-
if copy_pin:
209-
pin_image(
210-
(destination_project, destination_project_folder),
211-
image_name, img_metadata["is_pinned"]
212-
)
182+
_copy_metadata(
183+
source_project, source_project_folder, image_name,
184+
destination_project, destination_project_folder, image_name,
185+
include_annotations, copy_annotation_status, copy_pin
186+
)
213187
return res
214188

215189

@@ -385,9 +359,6 @@ def copy_image(
385359
destination_project, destination_project_folder = get_project_and_folder_metadata(
386360
destination_project
387361
)
388-
img_metadata = get_image_metadata(
389-
(source_project, source_project_folder), image_name
390-
)
391362
img_b = get_image_bytes((source_project, source_project_folder), image_name)
392363
new_name = image_name
393364
extension = Path(image_name).suffix
@@ -416,6 +387,22 @@ def copy_image(
416387
upload_image_to_project(
417388
(destination_project, destination_project_folder), img_b, new_name
418389
)
390+
_copy_metadata(
391+
source_project, source_project_folder, image_name, destination_project,
392+
destination_project_folder, new_name, include_annotations,
393+
copy_annotation_status, copy_pin
394+
)
395+
logger.info(
396+
"Copied image %s/%s to %s/%s.", source_project["name"], image_name,
397+
destination_project["name"], new_name
398+
)
399+
400+
401+
def _copy_metadata(
402+
source_project, source_project_folder, image_name, destination_project,
403+
destination_project_folder, new_name, include_annotations,
404+
copy_annotation_status, copy_pin
405+
):
419406
if include_annotations:
420407
annotations = get_image_annotations(
421408
(source_project, source_project_folder), image_name
@@ -433,21 +420,20 @@ def copy_image(
433420
(destination_project, destination_project_folder), new_name,
434421
annotations["annotation_json"]
435422
)
436-
if copy_annotation_status:
437-
set_image_annotation_status(
438-
(destination_project, destination_project_folder), new_name,
439-
img_metadata["annotation_status"]
440-
)
441-
if copy_pin:
442-
pin_image(
443-
(destination_project, destination_project_folder), new_name,
444-
img_metadata["is_pinned"]
423+
if copy_annotation_status or copy_pin:
424+
img_metadata = get_image_metadata(
425+
(source_project, source_project_folder), image_name
445426
)
446-
447-
logger.info(
448-
"Copied image %s/%s to %s/%s.", source_project["name"], image_name,
449-
destination_project["name"], new_name
450-
)
427+
if copy_annotation_status:
428+
set_image_annotation_status(
429+
(destination_project, destination_project_folder), new_name,
430+
img_metadata["annotation_status"]
431+
)
432+
if copy_pin:
433+
pin_image(
434+
(destination_project, destination_project_folder), new_name,
435+
img_metadata["is_pinned"]
436+
)
451437

452438

453439
def move_image(

0 commit comments

Comments
 (0)