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

Catalogue walk #755

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
26 changes: 26 additions & 0 deletions src/siphon/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from datetime import datetime
import logging
import re
import requests
import warnings
import xml.etree.ElementTree as ET # noqa:N814
try:
Expand Down Expand Up @@ -389,6 +390,31 @@ def _process_datasets(self):
else:
self.datasets.pop(ds_name)

def walk(self, depth=1):

"""Return a generator walking a THREDDS data catalog for datasets.

Parameters
----------
cat : TDSCatalog
THREDDS catalog.
depth : int
Maximum recursive depth. Setting 0 will return only datasets within the top-level catalog. If None,
depth is set to 1000.
"""
tlogan2000 marked this conversation as resolved.
Show resolved Hide resolved
yield from self.datasets.values()
if depth is None:
depth = 1000

if depth > 0:
for ref in self.catalog_refs.values():
try:
child = ref.follow()
yield from child.walk(depth=depth - 1)

except requests.HTTPError as exc:
log.exception(exc)

@property
def latest(self):
"""Get the latest dataset, if available."""
Expand Down
Loading