swiftly/cli/delete.py
def cli_delete(context, path, body=None, recursive=False,
               yes_empty_account=False, yes_delete_account=False,
               until_empty=False):
    """
    Deletes the item (account, container, or object) at the path.

    See :py:mod:`swiftly.cli.delete` for context usage information.

    See :py:class:`CLIDelete` for more information.

    :param context: The :py:class:`swiftly.cli.context.CLIContext` to
        use.
    :param path: The path of the item (acount, container, or object)
        to delete.
    :param body: The body to send with the DELETE request. Bodies are
        not normally sent with DELETE requests, but this can be
        useful with bulk deletes for instance.
    :param recursive: If True and the item is an account or
        container, deletes will be issued for any containing items as
        well. This does one pass at the deletion; so if objects revert
        to previous versions or if new objects otherwise arise during
        the process, the container(s) may not be empty once done. Set
        `until_empty` to True if you want multiple passes to keep trying
        to fully empty the containers.
    :param until_empty: If True and recursive is True, this will cause
        Swiftly to keep looping through the deletes until the containers
        are completely empty. Useful if you have object versioning
        turned on or otherwise have objects that seemingly reappear
        after being deleted. It could also run forever if you have
        something that's uploading objects at a faster rate than they
        are deleted.
    :param yes_empty_account: This must be set to True for
        verification when the item is an account and recursive is
        True.
    :param yes_delete_account: This must be set to True for
        verification when the item is an account and you really wish
        a delete to be issued for the account itself.
    """
    path = path.lstrip('/') if path else ''
    if not path:
        if yes_empty_account:
            cli_empty_account(
                context, yes_empty_account=yes_empty_account,
                until_empty=until_empty)
        if yes_delete_account:
            with context.client_manager.with_client() as client:
                status, reason, headers, contents = client.delete_account(
                    headers=context.headers, query=context.query,
                    cdn=context.cdn, body=body,
                    yes_i_mean_delete_the_account=yes_delete_account)
                if status // 100 != 2:
                    if status == 404 and context.ignore_404:
                        return
                    raise ReturnCode(
                        'deleting account: %s %s' % (status, reason))
    elif '/' not in path.rstrip('/'):
        path = path.rstrip('/')
        if recursive:
            cli_empty_container(context, path, until_empty=until_empty)
        with context.client_manager.with_client() as client:
            status, reason, headers, contents = client.delete_container(
                path, headers=context.headers,
                query=context.query, cdn=context.cdn, body=body)
            if status // 100 != 2:
                if status == 404 and context.ignore_404:
                    return
                raise ReturnCode(
                    'deleting container %r: %s %s' % (path, status, reason))
    else:
        with context.client_manager.with_client() as client:
            status, reason, headers, contents = client.delete_object(
                *path.split('/', 1), headers=context.headers,
                query=context.query, cdn=context.cdn, body=body)
            if status // 100 != 2:
                if status == 404 and context.ignore_404:
                    return
                raise ReturnCode(
                    'deleting object %r: %s %s' % (path, status, reason))
def cli_delete(context, path, body=None, recursive=False,
               yes_empty_account=False, yes_delete_account=False,
               until_empty=False):
    """
    Deletes the item (account, container, or object) at the path.

    See :py:mod:`swiftly.cli.delete` for context usage information.

    See :py:class:`CLIDelete` for more information.

    :param context: The :py:class:`swiftly.cli.context.CLIContext` to
        use.
    :param path: The path of the item (acount, container, or object)
        to delete.
    :param body: The body to send with the DELETE request. Bodies are
        not normally sent with DELETE requests, but this can be
        useful with bulk deletes for instance.
    :param recursive: If True and the item is an account or
        container, deletes will be issued for any containing items as
        well. This does one pass at the deletion; so if objects revert
        to previous versions or if new objects otherwise arise during
        the process, the container(s) may not be empty once done. Set
        `until_empty` to True if you want multiple passes to keep trying
        to fully empty the containers.
    :param until_empty: If True and recursive is True, this will cause
        Swiftly to keep looping through the deletes until the containers
        are completely empty. Useful if you have object versioning
        turned on or otherwise have objects that seemingly reappear
        after being deleted. It could also run forever if you have
        something that's uploading objects at a faster rate than they
        are deleted.
    :param yes_empty_account: This must be set to True for
        verification when the item is an account and recursive is
        True.
    :param yes_delete_account: This must be set to True for
        verification when the item is an account and you really wish
        a delete to be issued for the account itself.
    """
    path = path.lstrip('/') if path else ''
    if not path:
        if yes_empty_account:
            cli_empty_account(
                context, yes_empty_account=yes_empty_account,
                until_empty=until_empty)
        if yes_delete_account:
            with context.client_manager.with_client() as client:
                status, reason, headers, contents = client.delete_account(
                    headers=context.headers, query=context.query,
                    cdn=context.cdn, body=body,
                    yes_i_mean_delete_the_account=yes_delete_account)
                if status // 100 != 2:
                    if status == 404 and context.ignore_404:
                        return
                    raise ReturnCode(
                        'deleting account: %s %s' % (status, reason))
    elif '/' not in path.rstrip('/'):
        path = path.rstrip('/')
        if recursive:
            cli_empty_container(context, path, until_empty=until_empty)
        with context.client_manager.with_client() as client:
            status, reason, headers, contents = client.delete_container(
                path, headers=context.headers,
                query=context.query, cdn=context.cdn, body=body)
            if status // 100 != 2:
                if status == 404 and context.ignore_404:
                    return
                raise ReturnCode(
                    'deleting container %r: %s %s' % (path, status, reason))
    else:
        with context.client_manager.with_client() as client:
            status, reason, headers, contents = client.delete_object(
                *path.split('/', 1), headers=context.headers,
                query=context.query, cdn=context.cdn, body=body)
            if status // 100 != 2:
                if status == 404 and context.ignore_404:
                    return
                raise ReturnCode(
                    'deleting object %r: %s %s' % (path, status, reason))
Deletes the item (account, container, or object) at the path.

    See :py:mod:`swiftly.cli.delete` for context usage information.

    See :py:class:`CLIDelete` for more information.

    :param context: The :py:class:`swiftly.cli.context.CLIContext` to
        use.
    :param path: The path of the item (acount, container, or object)
        to delete.
    :param body: The body to send with the DELETE request. Bodies are
        not normally sent with DELETE requests, but this can be
        useful with bulk deletes for instance.
    :param recursive: If True and the item is an account or
        container, deletes will be issued for any containing items as
        well. This does one pass at the deletion; so if objects revert
        to previous versions or if new objects otherwise arise during
        the process, the container(s) may not be empty once done. Set
        `until_empty` to True if you want multiple passes to keep trying
        to fully empty the containers.
    :param until_empty: If True and recursive is True, this will cause
        Swiftly to keep looping through the deletes until the containers
        are completely empty. Useful if you have object versioning
        turned on or otherwise have objects that seemingly reappear
        after being deleted. It could also run forever if you have
        something that's uploading objects at a faster rate than they
        are deleted.
    :param yes_empty_account: This must be set to True for
        verification when the item is an account and recursive is
        True.
    :param yes_delete_account: This must be set to True for
        verification when the item is an account and you really wish
        a delete to be issued for the account itself.