Skip to content

Commit

Permalink
Merge pull request #1938 from dandi/enh-calc_sha256
Browse files Browse the repository at this point in the history
Add calculate_sha256 management command to trigger (re)computation for a blob
  • Loading branch information
waxlamp authored Oct 4, 2024
2 parents 99e55f4 + ccf08bf commit 6bec051
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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)

0 comments on commit 6bec051

Please sign in to comment.