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

RF: attempt nwb metadata extraction only on .nwb, if fails -- warning #733

Merged
merged 2 commits into from
Jul 23, 2021
Merged
Changes from 1 commit
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
28 changes: 15 additions & 13 deletions dandi/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,21 +700,23 @@ def process_ndtypes(asset, nd_types):
def get_asset_metadata(
filepath, relpath, digest=None, digest_type=None, allow_any_path=True
) -> models.BareAsset:
try:
metadata = nwb2asset(filepath, digest=digest, digest_type=digest_type)
except Exception as e:
lgr.info(
"Failed to extract NWB metadata from %s: %s: %s",
filepath,
type(e).__name__,
str(e),
)
if allow_any_path:
metadata = get_default_metadata(
filepath, digest=digest, digest_type=digest_type
metadata = None
if op.splitext(filepath)[1] == ".nwb":
try:
metadata = nwb2asset(filepath, digest=digest, digest_type=digest_type)
except Exception as e:
lgr.warning(
"Failed to extract NWB metadata from %s: %s: %s",
filepath,
type(e).__name__,
str(e),
)
else:
if not allow_any_path:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be indented one level.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to this. otherwise LGTM

raise
if metadata is None:
metadata = get_default_metadata(
filepath, digest=digest, digest_type=digest_type
)
metadata.path = str(relpath)
return metadata

Expand Down