Skip to content

Commit

Permalink
added custom S2ReaderIOError exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ungarj committed Sep 14, 2017
1 parent 44f3eac commit d06f80f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions s2reader/exceptions.py
@@ -0,0 +1,5 @@
"""Errors and Warnings."""


class S2ReaderIOError(IOError):
"""Raised if an expected file cannot be found."""
12 changes: 7 additions & 5 deletions s2reader/s2reader.py
Expand Up @@ -17,6 +17,8 @@
from cached_property import cached_property
import zipfile

from .exceptions import S2ReaderIOError


def open(safe_file):
"""Return a SentinelDataSet object."""
Expand Down Expand Up @@ -59,7 +61,7 @@ def __init__(self, path):
else:
self._zip_root = os.path.basename(filename) + "/"
if self._zip_root not in self._zipfile.namelist():
raise IOError("unknown zipfile structure")
raise S2ReaderIOError("unknown zipfile structure")
self.manifest_safe_path = os.path.join(
self._zip_root, "manifest.safe")
else:
Expand All @@ -72,7 +74,7 @@ def __init__(self, path):
assert os.path.isfile(self.manifest_safe_path) or \
self.manifest_safe_path in self._zipfile.namelist()
except AssertionError:
raise IOError(
raise S2ReaderIOError(
"manifest.safe not found: %s" % self.manifest_safe_path
)

Expand Down Expand Up @@ -107,7 +109,7 @@ def product_metadata_path(self):
abspath = os.path.join(self.path, relpath)
assert os.path.isfile(abspath)
except AssertionError:
raise IOError(
raise S2ReaderIOError(
"S2_Level-1C_product_metadata_path not found: %s \
" % abspath
)
Expand Down Expand Up @@ -276,7 +278,7 @@ def metadata_path(self):
assert os.path.isfile(metadata_path) or \
metadata_path in self.dataset._zipfile.namelist()
except AssertionError:
raise IOError(
raise S2ReaderIOError(
"Granule metadata XML does not exist:", metadata_path)
return metadata_path

Expand Down Expand Up @@ -477,7 +479,7 @@ def metadata_path(self):
assert os.path.isfile(metadata_path) or \
metadata_path in self.dataset._zipfile.namelist()
except AssertionError:
raise IOError(
raise S2ReaderIOError(
"Granule metadata XML does not exist:", metadata_path)
return metadata_path

Expand Down

0 comments on commit d06f80f

Please sign in to comment.