-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1938 from dandi/enh-calc_sha256
Add calculate_sha256 management command to trigger (re)computation for a blob
- Loading branch information
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |