forked from georchestra/sdi-consistence-check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geometadata.py
31 lines (25 loc) · 1.16 KB
/
geometadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import xml.etree.ElementTree as etree
from owslib.iso import MD_Metadata
from owslib.util import openURL
from requests import HTTPError
from credentials import Credentials
from inconsistency import GsToGnMetadataInvalidInconsistency
class GeoMetadata:
def __init__(self, mdUrl, mdFormat, creds = Credentials()):
self.md = None
self.errorMsg = None
try:
(username, password) = creds.getFromUrl(mdUrl)
rawMd = openURL(mdUrl, username=username, password=password)
content = rawMd.read()
if mdFormat == "text/xml":
self.md = MD_Metadata(etree.fromstring(content))
except HTTPError as e:
raise GsToGnMetadataInvalidInconsistency(mdUrl,
"'%s' Metadata not found (HTTP %s): %s"
% (mdFormat, e.response.status_code, str(e)))
except BaseException as e:
raise GsToGnMetadataInvalidInconsistency(mdUrl,
"Unable to parse the %s metadata: %s" % (mdFormat, str(e)))
def getMetadata(self):
return self.md