Skip to content

Commit

Permalink
Merge pull request #922 from dandi/gh-920
Browse files Browse the repository at this point in the history
Recognize video files as non-generic assets
  • Loading branch information
yarikoptic authored Mar 11, 2022
2 parents aeaa03f + cb160b6 commit a941ab4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
23 changes: 14 additions & 9 deletions dandi/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from . import get_logger
from .consts import (
MAX_ZARR_DEPTH,
VIDEO_FILE_EXTENSIONS,
ZARR_MIME_TYPE,
ZARR_UPLOAD_BATCH_SIZE,
EmbargoStatus,
Expand Down Expand Up @@ -314,6 +315,15 @@ class LocalFileAsset(LocalAsset):

EXTENSIONS: ClassVar[List[str]] = []

def get_metadata(
self,
digest: Optional[Digest] = None,
ignore_errors: bool = True,
) -> BareAsset:
metadata = get_default_metadata(self.filepath, digest=digest)
metadata.path = self.path
return metadata

def get_digest(self) -> Digest:
"""Calculate a dandi-etag digest for the asset"""
value = get_digest(self.filepath, digest="dandi-etag")
Expand Down Expand Up @@ -526,22 +536,17 @@ def get_validation_errors(
return errors


class VideoAsset(LocalFileAsset):
EXTENSIONS: ClassVar[List[str]] = VIDEO_FILE_EXTENSIONS


class GenericAsset(LocalFileAsset):
"""
Representation of a generic regular file, one that is not of any known type
"""

EXTENSIONS: ClassVar[List[str]] = []

def get_metadata(
self,
digest: Optional[Digest] = None,
ignore_errors: bool = True,
) -> BareAsset:
metadata = get_default_metadata(self.filepath, digest=digest)
metadata.path = self.path
return metadata


class LocalDirectoryAsset(LocalAsset, Generic[P]):
"""
Expand Down
5 changes: 5 additions & 0 deletions dandi/tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DandisetMetadataFile,
GenericAsset,
NWBAsset,
VideoAsset,
ZarrAsset,
dandi_file,
find_dandi_files,
Expand All @@ -36,6 +37,7 @@ def test_find_dandi_files(tmp_path: Path) -> None:
(tmp_path / "subdir" / "gnusto").touch()
(tmp_path / "subdir" / "cleesh.txt").touch()
(tmp_path / "empty.zarr").mkdir()
(tmp_path / "glarch.mp4").touch()
(tmp_path / ".ignored").touch()
(tmp_path / ".ignored.dir").mkdir()
(tmp_path / ".ignored.dir" / "ignored.nwb").touch()
Expand All @@ -44,6 +46,7 @@ def test_find_dandi_files(tmp_path: Path) -> None:
find_dandi_files(tmp_path, dandiset_path=tmp_path), key=attrgetter("filepath")
)
assert files == [
VideoAsset(filepath=tmp_path / "glarch.mp4", path="glarch.mp4"),
ZarrAsset(filepath=tmp_path / "sample01.zarr", path="sample01.zarr"),
NWBAsset(filepath=tmp_path / "sample02.nwb", path="sample02.nwb"),
NWBAsset(
Expand All @@ -62,6 +65,7 @@ def test_find_dandi_files(tmp_path: Path) -> None:
GenericAsset(filepath=tmp_path / "bar.txt", path="bar.txt"),
DandisetMetadataFile(filepath=tmp_path / dandiset_metadata_file),
GenericAsset(filepath=tmp_path / "foo", path="foo"),
VideoAsset(filepath=tmp_path / "glarch.mp4", path="glarch.mp4"),
ZarrAsset(filepath=tmp_path / "sample01.zarr", path="sample01.zarr"),
NWBAsset(filepath=tmp_path / "sample02.nwb", path="sample02.nwb"),
GenericAsset(
Expand All @@ -82,6 +86,7 @@ def test_find_dandi_files(tmp_path: Path) -> None:
)
assert files == [
DandisetMetadataFile(filepath=tmp_path / dandiset_metadata_file),
VideoAsset(filepath=tmp_path / "glarch.mp4", path="glarch.mp4"),
ZarrAsset(filepath=tmp_path / "sample01.zarr", path="sample01.zarr"),
NWBAsset(filepath=tmp_path / "sample02.nwb", path="sample02.nwb"),
NWBAsset(
Expand Down

0 comments on commit a941ab4

Please sign in to comment.