Skip to content

Commit

Permalink
Process dataset elements with access element children
Browse files Browse the repository at this point in the history
  • Loading branch information
lesserwhirls committed Mar 18, 2017
1 parent 669af16 commit cfdcd62
Show file tree
Hide file tree
Showing 3 changed files with 1,162 additions and 7 deletions.
60 changes: 53 additions & 7 deletions siphon/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,28 @@ def __init__(self, catalog_url):
self.services = []
self.catalog_refs = OrderedDict()
self.metadata = {}
self.ds_with_access_elements_to_process = []
service_skip_count = 0
service_skip = 0
current_dataset = None
previous_dataset = None
for child in root.iter():
tag_type = child.tag.split('}')[-1]
if tag_type == "dataset":
current_dataset = child.attrib['name']
self._process_dataset(child)

if previous_dataset:
# see if the previously processed dataset has access elements as children
# if so, these datasets need to be processed specially when making access_urls
has_access_element_info = any(self.datasets[previous_dataset].access_element_info)
if has_access_element_info:
self.ds_with_access_elements_to_process.append(previous_dataset)

previous_dataset = current_dataset

elif tag_type == "access":
self.datasets[current_dataset].add_access_element_info(child)
elif tag_type == "catalogRef":
self._process_catalog_ref(child)
elif (tag_type == "metadata") or (tag_type == ""):
Expand All @@ -114,12 +130,13 @@ def __init__(self, catalog_url):
self._process_datasets()

def _process_dataset(self, element):
catalog_url = ''
if "urlPath" in element.attrib:
if element.attrib["urlPath"] == "latest.xml":
ds = Dataset(element, self.catalog_url)
else:
ds = Dataset(element)
self.datasets[ds.name] = ds
catalog_url = self.catalog_url

ds = Dataset(element, catalog_url=catalog_url)
self.datasets[ds.name] = ds

def _process_catalog_ref(self, element):
catalog_ref = CatalogRef(self.catalog_url, element)
Expand All @@ -132,8 +149,14 @@ def _process_metadata(self, element, tag_type):

def _process_datasets(self):
for dsName in list(self.datasets.keys()):
self.datasets[dsName].make_access_urls(
self.base_tds_url, self.services, metadata=self.metadata)
# check to see if dataset needs to have access urls created, if not, remove the dataset
has_url_path = not self.datasets[dsName].url_path is None
is_ds_with_access_elements_to_process = dsName in self.ds_with_access_elements_to_process
if has_url_path or is_ds_with_access_elements_to_process:
self.datasets[dsName].make_access_urls(
self.base_tds_url, self.services, metadata=self.metadata)
else:
self.datasets.pop(dsName)


class CatalogRef(object):
Expand Down Expand Up @@ -208,8 +231,12 @@ def __init__(self, element_node, catalog_url=""):
"""
self.name = element_node.attrib['name']
self.url_path = element_node.attrib['urlPath']
if ("urlPath" in element_node.attrib):
self.url_path = element_node.attrib['urlPath']
else:
self.url_path = None
self.catalog_name = ''
self.access_element_info = {}
self._resolved = False
self._resolverUrl = None
# if latest.xml, resolve the latest url
Expand Down Expand Up @@ -297,8 +324,27 @@ def make_access_urls(self, catalog_url, all_services, metadata=None):
access_urls[service.service_type] = server_url + \
service.base + self.url_path

if any(self.access_element_info):

for service_type in self.access_element_info:
url_path = self.access_element_info[service_type]
found_service = None
for service in all_services:
if service.name == service_type:
found_service = service
break

if found_service:
access_urls[service_type] = server_url + \
found_service.base + url_path

self.access_urls = access_urls

def add_access_element_info(self, access_element):
service_name = access_element.attrib["serviceName"]
url_path = access_element.attrib["urlPath"]
self.access_element_info[service_name] = url_path


class SimpleService(object):
r"""
Expand Down
Loading

0 comments on commit cfdcd62

Please sign in to comment.