2424 merge ,
2525 with_supervisor_locked_error ,
2626)
27+ from ..request_batching import batch_resource_operation_factory
2728from .device_type import DeviceType
2829from .organization import Organization
2930
@@ -48,6 +49,12 @@ def __init__(self, pine: PineClient, settings: Settings, load_inner_models=True)
4849 self .membership = ApplicationMembership (pine , self )
4950 self .invite = ApplicationInvite (pine , self , settings )
5051
52+ self .__batch_application_operation = batch_resource_operation_factory (
53+ get_all = self .get_all ,
54+ not_found_error = exceptions .ApplicationNotFound ,
55+ ambiguous_error = exceptions .AmbiguousApplication ,
56+ )
57+
5158 def __get_access_filter (self ):
5259 return {
5360 "is_directly_accessible_by__user" : {
@@ -481,27 +488,43 @@ def create(
481488
482489 return self .__pine .post ({"resource" : "application" , "body" : body })
483490
484- # TODO: enable batch operations
485- def remove (self , slug_or_uuid_or_id : Union [str , int ]) -> None :
491+ def remove (self , slug_or_uuid_or_id_or_ids : Union [str , int , List [int ]]) -> None :
486492 """
487493 Remove application.
488494
489495 Args:
490- slug_or_uuid_or_id (Union[str, int]): application slug (string), uuid (string) or id (number).
496+ slug_or_uuid_or_id_or_ids (Union[str, int, List[int]]): application slug (string), uuid (string),
497+ id (number) or ids (List[int]).
491498
492499 Examples:
493500 >>> balena.models.application.remove('my_org/my_app')
494501 >>> balena.models.application.remove('c184556293854781aea71b0bdae10e45')
495502 >>> balena.models.application.remove(123)
496503 """
497504
505+ if isinstance (slug_or_uuid_or_id_or_ids , list ):
506+ self .__batch_application_operation (
507+ slug_or_uuid_or_id_or_ids ,
508+ parameter_name = "slug_or_uuid_or_id_or_ids" ,
509+ fn = lambda applications : self .__pine .delete (
510+ {
511+ "resource" : "application" ,
512+ "options" : {"$filter" : {"id" : {"$in" : [a ["id" ] for a in applications ]}}},
513+ }
514+ ),
515+ )
516+ return
517+
518+ if isinstance (slug_or_uuid_or_id_or_ids , str ):
519+ application_id = self .get_id (slug_or_uuid_or_id_or_ids )
520+ else :
521+ application_id = slug_or_uuid_or_id_or_ids
498522 try :
499- application_id = self .get_id (slug_or_uuid_or_id )
500523 self .__pine .delete ({"resource" : "application" , "id" : application_id })
501524 except exceptions .RequestError as e :
502525 if e .status_code == 404 :
503- raise exceptions .ApplicationNotFound (slug_or_uuid_or_id )
504- raise e
526+ raise exceptions .ApplicationNotFound (str ( slug_or_uuid_or_id_or_ids ) )
527+ raise
505528
506529 def rename (self , slug_or_uuid_or_id : Union [str , int ], new_name : str ) -> None :
507530 """
0 commit comments