Commit 99610d20 authored by Christophe Benz's avatar Christophe Benz
Browse files

Allow loading catalog from a file too

parent 7fc79f53
......@@ -31,26 +31,22 @@ def generate_schema_from_url_func(session):
return tableschema_from_url
def is_http_url(ref) -> bool:
return isinstance(ref, str) and re.match("https?://", ref)
class SchemaCatalogRegistry:
"""Retain section_name -> catalog url matching
and creates SchemaCatalog instance on demand"""
def __init__(self, session):
self.session = session
self.url_map = {}
self.ref_map = {}
def add_ref(self, name, url):
self.url_map[name] = url
def add_ref(self, name, ref):
self.ref_map[name] = ref
def build_schema_catalog(self, name):
if name in self.url_map:
catalog_url = self.url_map[name]
if name in self.ref_map:
ref = self.ref_map[name]
catalog = opendataschema.SchemaCatalog(catalog_url, session=self.session)
catalog = opendataschema.SchemaCatalog(ref, session=self.session)
except requests.exceptions.RequestException as exc:
return None
......@@ -69,7 +65,7 @@ if config.HOMEPAGE_CONFIG:
name = section['name']'Initializing homepage section "{}"...'.format(name))
catalog_ref = section.get('catalog')
if is_http_url(catalog_ref):
if catalog_ref:
schema_catalog_registry.add_ref(name, catalog_ref)"...done")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment