Skip to content

Commit b423904

Browse files
safeguard some properties (#288)
* safeguard bbox safeguard $graph remove utc reference * Update run_tests.py --------- Co-authored-by: Tom Kralidis <[email protected]>
1 parent ecd14dc commit b423904

File tree

5 files changed

+466
-8
lines changed

5 files changed

+466
-8
lines changed

pygeometa/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
# =================================================================
4646

4747
from collections.abc import Mapping
48-
from datetime import date, datetime
4948
from importlib.metadata import version, PackageNotFoundError
49+
import datetime
5050
import json
5151
import logging
5252
import os
@@ -125,14 +125,14 @@ def normalize_datestring(datestring: str, format_: str = 'default') -> str:
125125
:returns: string of properly formatted datestring
126126
"""
127127

128-
today_and_now = datetime.utcnow()
128+
today_and_now = datetime.datetime.now(datetime.UTC)
129129

130130
re1 = r'\$Date: (?P<year>\d{4})'
131131
re2 = r'\$Date: (?P<date>\d{4}-\d{2}-\d{2}) (?P<time>\d{2}:\d{2}:\d{2})'
132132
re3 = r'(?P<start>.*)\$Date: (?P<year>\d{4}).*\$(?P<end>.*)'
133133

134134
try:
135-
if isinstance(datestring, date):
135+
if isinstance(datestring, datetime.date):
136136
if datestring.year < 1900:
137137
datestring2 = '{0.day:02d}.{0.month:02d}.{0.year:4d}'.format(
138138
datestring)

pygeometa/schemas/cwl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def import_(self, metadata: str) -> dict:
108108

109109
now = datetime.datetime.now(datetime.UTC)
110110

111-
wf = list(filter(lambda x: x['class'] == 'Workflow', metadata['$graph']))[0] # noqa
111+
wf = list(filter(lambda x: x['class'] == 'Workflow', metadata.get('$graph')))[0] # noqa
112112

113113
mcf['metadata']['identifier'] = wf['id']
114114
mcf['metadata']['hierarchylevel'] = 'application'

pygeometa/schemas/iso19139/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,19 @@ def import_(self, metadata: str) -> dict:
136136

137137
mcf['identification']['extents'] = {
138138
'spatial': [{
139-
'bbox': [
139+
'bbox': []
140+
}],
141+
'temporal': []
142+
}
143+
try:
144+
mcf['identification']['extents']['spatial'][0]['bbox'] = [
140145
ast.literal_eval(identification.extent.boundingBox.minx),
141146
ast.literal_eval(identification.extent.boundingBox.miny),
142147
ast.literal_eval(identification.extent.boundingBox.maxx),
143148
ast.literal_eval(identification.extent.boundingBox.maxy)
144149
]
145-
}],
146-
'temporal': []
147-
}
150+
except ValueError as err:
151+
LOGGER.info(f'boundingBox missing: {err}')
148152

149153
temp_extent = {
150154
'begin': None,

0 commit comments

Comments
 (0)