@@ -268,13 +268,29 @@ def delete_images(project, image_names):
268268 :param image_names: to be deleted images' names. If None, all the images will be deleted
269269 :type image_names: list of strs
270270 """
271+ NUM_TO_SEND = 1000
271272 project , project_folder = get_project_and_folder_metadata (project )
272273 params = {"team_id" : project ["team_id" ], "project_id" : project ["id" ]}
273274 if image_names is None :
274- if project_folder is not None :
275- data = {"folder_id" : project_folder ["id" ]}
276- else :
277- data = {"folder_id" : get_project_root_folder_id (project )}
275+ images = search_images ((project , project_folder ), return_metadata = True )
276+ else :
277+ if not isinstance (image_names , list ):
278+ raise SABaseException (
279+ 0 , "image_names should be a list of strs or None"
280+ )
281+ images = get_image_metadata (
282+ (project , project_folder ),
283+ image_names ,
284+ return_dict_on_single_output = False
285+ )
286+ for start_index in range (0 , len (images ), NUM_TO_SEND ):
287+ data = {
288+ "image_ids" :
289+ [
290+ image ["id" ]
291+ for image in images [start_index :start_index + NUM_TO_SEND ]
292+ ]
293+ }
278294 response = _api .send_request (
279295 req_type = 'PUT' ,
280296 path = '/image/delete/images' ,
@@ -285,35 +301,6 @@ def delete_images(project, image_names):
285301 raise SABaseException (
286302 response .status_code , "Couldn't delete images " + response .text
287303 )
288- else :
289- NUM_TO_SEND = 1000
290- if not isinstance (image_names , list ):
291- raise SABaseException (
292- 0 , "image_names should be a list of strs or None"
293- )
294- images = get_image_metadata (
295- project , image_names , return_dict_on_single_output = False
296- )
297- for start_index in range (0 , len (image_names ), NUM_TO_SEND ):
298- data = {
299- "image_ids" :
300- [
301- image ["id" ]
302- for image in images [start_index :start_index +
303- NUM_TO_SEND ]
304- ]
305- }
306- response = _api .send_request (
307- req_type = 'PUT' ,
308- path = '/image/delete/images' ,
309- params = params ,
310- json_req = data
311- )
312- if not response .ok :
313- raise SABaseException (
314- response .status_code ,
315- "Couldn't delete images " + response .text
316- )
317304 logger .info (
318305 "Images deleted in project %s%s" , project ["name" ],
319306 "" if project_folder is None else "/" + project_folder ["name" ]
0 commit comments