2222# Yield successive n-sized
2323# chunks from l.
2424def divide_chunks (l , n ):
25-
2625 # looping till length l
2726 for i in range (0 , len (l ), n ):
2827 yield l [i :i + n ]
@@ -42,7 +41,7 @@ def get_project_folder_string(project):
4241
4342
4443def __move_images (
45- source_project , source_folder_id , destination_folder_id , image_names
44+ source_project , source_folder_id , destination_folder_id , image_names
4645):
4746 """Move images in bulk between folders in a project
4847
@@ -90,8 +89,8 @@ def __move_images(
9089
9190
9291def _copy_images_request (
93- team_id , project_id , image_names , destination_folder_id , source_folder_id ,
94- include_annotations , copy_pin
92+ team_id , project_id , image_names , destination_folder_id , source_folder_id ,
93+ include_annotations , copy_pin
9594):
9695 response = _api .send_request (
9796 req_type = 'POST' ,
@@ -161,8 +160,8 @@ def copy_polling(image_names, source_project, poll_id):
161160
162161
163162def __copy_images (
164- source_project , source_folder_id , destination_folder_id , image_names ,
165- include_annotations , copy_pin
163+ source_project , source_folder_id , destination_folder_id , image_names ,
164+ include_annotations , copy_pin
166165):
167166 """Copy images in bulk between folders in a project
168167
@@ -233,8 +232,8 @@ def create_empty_annotation(size, image_name):
233232
234233
235234def upload_image_array_to_s3 (
236- bucket , img_name , img_name_hash , size , orig_image , lores_image , huge_image ,
237- thumbnail_image , prefix
235+ bucket , img_name , img_name_hash , size , orig_image , lores_image , huge_image ,
236+ thumbnail_image , prefix
238237):
239238 key = prefix + img_name_hash
240239 bucket .put_object (Body = orig_image , Key = key )
@@ -256,7 +255,7 @@ def upload_image_array_to_s3(
256255
257256
258257def get_image_array_to_upload (
259- img_name , byte_io_orig , image_quality_in_editor , project_type
258+ img_name , byte_io_orig , image_quality_in_editor , project_type
260259):
261260 if image_quality_in_editor not in ["original" , "compressed" ]:
262261 raise SABaseException (0 , "NA ImageQuality in get_image_array_to_upload" )
@@ -272,8 +271,8 @@ def get_image_array_to_upload(
272271 if resolution > common .MAX_IMAGE_RESOLUTION [project_type ]:
273272 raise SABaseException (
274273 0 , "Image resolution " + str (resolution ) +
275- " too large. Max supported for " + project_type + " projects is " +
276- str (common .MAX_IMAGE_RESOLUTION [project_type ])
274+ " too large. Max supported for " + project_type + " projects is " +
275+ str (common .MAX_IMAGE_RESOLUTION [project_type ])
277276 )
278277
279278 if image_quality_in_editor == "original" and im_format in ['JPEG' , 'JPG' ]:
@@ -317,9 +316,9 @@ def get_image_array_to_upload(
317316
318317
319318def __upload_images_to_aws_thread (
320- res , img_paths , project , annotation_status , prefix , thread_id , chunksize ,
321- couldnt_upload , uploaded , tried_upload , image_quality_in_editor ,
322- from_s3_bucket , project_folder_id
319+ res , img_paths , project , annotation_status , prefix , thread_id , chunksize ,
320+ couldnt_upload , uploaded , tried_upload , image_quality_in_editor ,
321+ from_s3_bucket , project_folder_id
323322):
324323 len_img_paths = len (img_paths )
325324 start_index = thread_id * chunksize
@@ -405,14 +404,14 @@ def __upload_images_to_aws_thread(
405404
406405
407406def __create_image (
408- img_names ,
409- img_paths ,
410- project ,
411- annotation_status ,
412- remote_dir ,
413- sizes ,
414- project_folder_id ,
415- upload_state = "Initial"
407+ img_names ,
408+ img_paths ,
409+ project ,
410+ annotation_status ,
411+ remote_dir ,
412+ sizes ,
413+ project_folder_id ,
414+ upload_state = "Initial"
416415):
417416 if len (img_paths ) == 0 :
418417 return
@@ -531,10 +530,9 @@ def get_duplicate_image_names(project_id, team_id, folder_id, image_paths):
531530
532531
533532def _upload_images (
534- img_paths , team_id , folder_id , project_id , annotation_status ,
535- from_s3_bucket , image_quality_in_editor , project , folder_name
533+ img_paths , team_id , folder_id , project_id , annotation_status ,
534+ from_s3_bucket , image_quality_in_editor , project , folder_name
536535):
537-
538536 _NUM_THREADS = 10
539537 uploaded = [[] for _ in range (_NUM_THREADS )]
540538 tried_upload = [[] for _ in range (_NUM_THREADS )]
@@ -601,8 +599,8 @@ def _upload_images(
601599
602600
603601def _attach_urls (
604- img_names_urls , team_id , folder_id , project_id , annotation_status , project ,
605- folder_name
602+ img_names_urls , team_id , folder_id , project_id , annotation_status , project ,
603+ folder_name
606604):
607605 _NUM_THREADS = 10
608606 params = {'team_id' : team_id , 'folder_id' : folder_id }
@@ -677,8 +675,8 @@ def _attach_urls(
677675
678676
679677def __attach_image_urls_to_project_thread (
680- res , img_names_urls , project , annotation_status , prefix , thread_id ,
681- chunksize , couldnt_upload , uploaded , tried_upload , project_folder_id
678+ res , img_names_urls , project , annotation_status , prefix , thread_id ,
679+ chunksize , couldnt_upload , uploaded , tried_upload , project_folder_id
682680):
683681 len_img_paths = len (img_names_urls )
684682 start_index = thread_id * chunksize
@@ -762,4 +760,26 @@ def get_templates_mapping():
762760 templates_map = {}
763761 for template in templates :
764762 templates_map [template ['name' ]] = template ['id' ]
765- return templates_map
763+ return templates_map
764+
765+
766+ def _assign_images (folder_name , image_names , user , project_id , team_id ):
767+ image_names_lists = divide_chunks (image_names , 500 )
768+ params = {"project_id" : project_id , "team_id" : team_id }
769+ messages = []
770+ for image_name_list in image_names_lists :
771+ json_req = {
772+ "image_names" : image_name_list ,
773+ "assign_user_id" : user ,
774+ "folder_name" : folder_name ,
775+ }
776+ response = _api .send_request (
777+ req_type = 'PUT' ,
778+ path = '/images/editAssignment' ,
779+ params = params ,
780+ json_req = json_req
781+ )
782+ if not response .ok :
783+ message = "Couldn't assign images " + response .text
784+ messages .append (message )
785+ return messages
0 commit comments