Skip to content

Commit

Permalink
Added support for a FOLIAPY_FORCE_LOCALSETDIR environment variable th…
Browse files Browse the repository at this point in the history
…at disables remote downloads of set definitions and looks locally instead. (proycon/flat#182)

Enables off-line usage.
  • Loading branch information
proycon committed May 13, 2022
1 parent 1a93e7d commit f7d4119
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions folia/foliaset.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import sys
import io
import os
import rdflib
from lxml import etree as ElementTree
if sys.version < '3':
Expand Down Expand Up @@ -361,6 +362,8 @@ def __init__(self, url, format=None, basens="",verbose=False):
elif url.endswith('.xml'): #other XML will be considered legacy
format = 'application/foliaset+xml' #legacy

if os.environ.get("FOLIAPY_FORCE_LOCALSETDIR"):
url = os.path.join(os.environ['FOLIAPY_FORCE_LOCALSETDIR'], os.path.basename(url))
if format in ('application/foliaset+xml','legacy',None):
#legacy format, has some checks and fallbacks if the format turns out to be RDF anyway
self.legacyset = None
Expand Down Expand Up @@ -405,6 +408,8 @@ def __init__(self, url, format=None, basens="",verbose=False):
self.graph.parse(location=url, format=format)
except HTTPError:
raise DeepValidationError("Unable to download set definition from " + url)
except FileNotFoundError:
raise DeepValidationError("Set definition not found: " + url)
if self.verbose:
print("Loaded set " + url + " (" + str(len(self.graph)) + " triples)",file=sys.stderr)

Expand Down

0 comments on commit f7d4119

Please sign in to comment.