ltdconveyor/s3/upload.py
def delete_directory(self, dirname):
        """Delete a directory (and contents) from the bucket.

        Parameters
        ----------
        dirname : `str`
            Name of the directory, relative to ``bucket_root/``.

        Raises
        ------
        RuntimeError
            Raised when there are no objects to delete (directory
            does not exist).
        """
        key = os.path.join(self._bucket_root, dirname)
        if not key.endswith('/'):
            key += '/'

        key_objects = [{'Key': obj.key}
                       for obj in self._bucket.objects.filter(Prefix=key)]
        if len(key_objects) == 0:
            msg = 'No objects in bucket directory {}'.format(dirname)
            raise RuntimeError(msg)
        delete_keys = {'Objects': key_objects}
        # based on http://stackoverflow.com/a/34888103
        s3 = self._session.resource('s3')
        r = s3.meta.client.delete_objects(Bucket=self._bucket.name,
                                          Delete=delete_keys)
        self._logger.debug(r)
        if 'Errors' in r:
            raise S3Error('S3 could not delete {0}'.format(key))
def delete_directory(self, dirname):
        """Delete a directory (and contents) from the bucket.

        Parameters
        ----------
        dirname : `str`
            Name of the directory, relative to ``bucket_root/``.

        Raises
        ------
        RuntimeError
            Raised when there are no objects to delete (directory
            does not exist).
        """
        key = os.path.join(self._bucket_root, dirname)
        if not key.endswith('/'):
            key += '/'

        key_objects = [{'Key': obj.key}
                       for obj in self._bucket.objects.filter(Prefix=key)]
        if len(key_objects) == 0:
            msg = 'No objects in bucket directory {}'.format(dirname)
            raise RuntimeError(msg)
        delete_keys = {'Objects': key_objects}
        # based on http://stackoverflow.com/a/34888103
        s3 = self._session.resource('s3')
        r = s3.meta.client.delete_objects(Bucket=self._bucket.name,
                                          Delete=delete_keys)
        self._logger.debug(r)
        if 'Errors' in r:
            raise S3Error('S3 could not delete {0}'.format(key))
Delete a directory (and contents) from the bucket.

        Parameters
        ----------
        dirname : `str`
            Name of the directory, relative to ``bucket_root/``.

        Raises
        ------
        RuntimeError
            Raised when there are no objects to delete (directory
            does not exist).