Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add calculate_sha256 management command to trigger (re)computation for a blob #1938

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[codespell]
skip = .git,node_modules,dist,venv,.venv,.mypy_cache,.tox,yarn.lock,CHANGELOG.md,./htmlcov,*.pyc,*.log
skip = .git,node_modules,dist,venv,.venv,.mypy_cache,.tox,yarn.lock,CHANGELOG.md,./htmlcov,*.pyc,*.log,build,venvs
# Disabled until https://github.com/codespell-project/codespell/issues/2727
# got answer/re-solution
# dictionary = .codespell_dict
Expand Down
28 changes: 28 additions & 0 deletions dandiapi/api/management/commands/calculate_sha256.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import annotations

import djclick as click

from dandiapi.api.models import Asset
from dandiapi.api.tasks import calculate_sha256 as do_calculate_sha256


@click.command()
@click.option('--blob-id', 'blob_id', help='Blob ID')
@click.option('--asset-id', 'asset_id', help='Asset ID')
def calculate_sha256(asset_id: str | None = None, blob_id: str | None = None):
"""Trigger computation of sha256 for a blob.

Either blob-id or asset-id should be provided.
"""
# Handle mutually exclusive option failure cases.
if not asset_id and not blob_id:
raise ValueError('Provide either asset_id or blob_id')
if asset_id and blob_id:
raise ValueError('Provide only asset_id or blob_id, not both')

# Make sure we have a good blob_id to work with.
if asset_id:
asset = Asset.objects.get(asset_id=asset_id)
blob_id = asset.blob_id

do_calculate_sha256(blob_id=blob_id)