s4cmd.py
def batch_delete(self, sources):
    '''Delete a list of files in batch of batch_delete_size (default=1000).'''
    assert(type(sources) == list)

    if len(sources) == 0:
      return
    elif len(sources) == 1:
      self.delete(sources[0])
    elif len(sources) > self.opt.batch_delete_size:
      for i in range(0, len(sources), self.opt.batch_delete_size):
        self.pool.batch_delete(sources[i:i+self.opt.batch_delete_size])
    else:
      bucket = S3URL(sources[0]).bucket
      deletes = []
      for source in sources:
        s3url = S3URL(source)
        if s3url.bucket != bucket:
          raise Failure('Unable to delete keys in different bucket %s and %s.' % (s3url.bucket, bucket))
        deletes.append({'Key': s3url.path})

      response = self.s3.delete_objects(Bucket=bucket, Delete={'Objects': deletes})

      # Output result of deletion.
      for res in response.get('Deleted') or []:
        message('Delete %s', S3URL.combine('s3', bucket, res['Key']))

      for err in response.get('Errors') or []:
        message('Error deleting %s, code(%s) %s', S3URL.combine('s3', bucket, res['Key']), err['Code'], err['Message'])

      if response.get('Errors') is not None:
        raise RetryFailure('Unable to complete deleting %d files.' % len(response.get('Errors')))
def batch_delete(self, sources):
    '''Delete a list of files in batch of batch_delete_size (default=1000).'''
    assert(type(sources) == list)

    if len(sources) == 0:
      return
    elif len(sources) == 1:
      self.delete(sources[0])
    elif len(sources) > self.opt.batch_delete_size:
      for i in range(0, len(sources), self.opt.batch_delete_size):
        self.pool.batch_delete(sources[i:i+self.opt.batch_delete_size])
    else:
      bucket = S3URL(sources[0]).bucket
      deletes = []
      for source in sources:
        s3url = S3URL(source)
        if s3url.bucket != bucket:
          raise Failure('Unable to delete keys in different bucket %s and %s.' % (s3url.bucket, bucket))
        deletes.append({'Key': s3url.path})

      response = self.s3.delete_objects(Bucket=bucket, Delete={'Objects': deletes})

      # Output result of deletion.
      for res in response.get('Deleted') or []:
        message('Delete %s', S3URL.combine('s3', bucket, res['Key']))

      for err in response.get('Errors') or []:
        message('Error deleting %s, code(%s) %s', S3URL.combine('s3', bucket, res['Key']), err['Code'], err['Message'])

      if response.get('Errors') is not None:
        raise RetryFailure('Unable to complete deleting %d files.' % len(response.get('Errors')))
def batch_delete ( self , sources ) : assert ( type ( sources ) == list ) if len ( sources ) == 0 : return elif len ( sources ) == 1 : self . delete ( sources [ 0 ] ) elif len ( sources ) > self . opt . batch_delete_size : for i in range ( 0 , len ( sources ) , self . opt . batch_delete_size ) : self . pool . batch_delete ( sources [ i : i + self . opt . batch_delete_size ] ) else : bucket = S3URL ( sources [ 0 ] ) . bucket deletes = [ ] for source in sources : s3url = S3URL ( source ) if s3url . bucket != bucket : raise Failure ( 'Unable to delete keys in different bucket %s and %s.' % ( s3url . bucket , bucket ) ) deletes . append ( { 'Key' : s3url . path } ) response = self . s3 . delete_objects ( Bucket = bucket , Delete = { 'Objects' : deletes } ) # Output result of deletion. for res in response . get ( 'Deleted' ) or [ ] : message ( 'Delete %s' , S3URL . combine ( 's3' , bucket , res [ 'Key' ] ) ) for err in response . get ( 'Errors' ) or [ ] : message ( 'Error deleting %s, code(%s) %s' , S3URL . combine ( 's3' , bucket , res [ 'Key' ] ) , err [ 'Code' ] , err [ 'Message' ] ) if response . get ( 'Errors' ) is not None : raise RetryFailure ( 'Unable to complete deleting %d files.' % len ( response . get ( 'Errors' ) ) )
Delete a list of files in batch of batch_delete_size (default=1000).
Delete a list of files in batch of batch_delete_size ( default = 1000 ) .