swiftly/cli/head.py
def cli_head(context, path=None):
    """
    Performs a HEAD on the item (account, container, or object).

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

    See :py:class:`CLIHead` for more information.
    """
    path = path.lstrip('/') if path else None
    with context.client_manager.with_client() as client:
        if not path:
            status, reason, headers, contents = client.head_account(
                headers=context.headers, query=context.query, cdn=context.cdn)
            mute = context.muted_account_headers
        elif '/' not in path.rstrip('/'):
            path = path.rstrip('/')
            status, reason, headers, contents = client.head_container(
                path, headers=context.headers, query=context.query,
                cdn=context.cdn)
            mute = context.muted_container_headers
        else:
            status, reason, headers, contents = client.head_object(
                *path.split('/', 1), headers=context.headers,
                query=context.query, cdn=context.cdn)
            mute = context.muted_object_headers
        if hasattr(contents, 'read'):
            contents = contents.read()
    if status // 100 != 2:
        if status == 404 and context.ignore_404:
            return
        if not path:
            raise ReturnCode('heading account: %s %s' % (status, reason))
        elif '/' not in path:
            raise ReturnCode(
                'heading container %r: %s %s' % (path, status, reason))
        else:
            raise ReturnCode(
                'heading object %r: %s %s' % (path, status, reason))
    else:
        with context.io_manager.with_stdout() as fp:
            context.write_headers(fp, headers, mute)
def cli_head(context, path=None):
    """
    Performs a HEAD on the item (account, container, or object).

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

    See :py:class:`CLIHead` for more information.
    """
    path = path.lstrip('/') if path else None
    with context.client_manager.with_client() as client:
        if not path:
            status, reason, headers, contents = client.head_account(
                headers=context.headers, query=context.query, cdn=context.cdn)
            mute = context.muted_account_headers
        elif '/' not in path.rstrip('/'):
            path = path.rstrip('/')
            status, reason, headers, contents = client.head_container(
                path, headers=context.headers, query=context.query,
                cdn=context.cdn)
            mute = context.muted_container_headers
        else:
            status, reason, headers, contents = client.head_object(
                *path.split('/', 1), headers=context.headers,
                query=context.query, cdn=context.cdn)
            mute = context.muted_object_headers
        if hasattr(contents, 'read'):
            contents = contents.read()
    if status // 100 != 2:
        if status == 404 and context.ignore_404:
            return
        if not path:
            raise ReturnCode('heading account: %s %s' % (status, reason))
        elif '/' not in path:
            raise ReturnCode(
                'heading container %r: %s %s' % (path, status, reason))
        else:
            raise ReturnCode(
                'heading object %r: %s %s' % (path, status, reason))
    else:
        with context.io_manager.with_stdout() as fp:
            context.write_headers(fp, headers, mute)
Performs a HEAD on the item (account, container, or object).

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

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