aboutsummaryrefslogtreecommitdiffstats
path: root/bsie/reader
diff options
context:
space:
mode:
Diffstat (limited to 'bsie/reader')
-rw-r--r--bsie/reader/__init__.py8
-rw-r--r--bsie/reader/base.py9
-rw-r--r--bsie/reader/builder.py5
-rw-r--r--bsie/reader/chain.py5
-rw-r--r--bsie/reader/exif.py44
-rw-r--r--bsie/reader/image/__init__.py5
-rw-r--r--bsie/reader/image/_pillow.py5
-rw-r--r--bsie/reader/image/_raw.py5
-rw-r--r--bsie/reader/path.py4
-rw-r--r--bsie/reader/preview/__init__.py5
-rw-r--r--bsie/reader/preview/_pg.py5
-rw-r--r--bsie/reader/preview/_pillow.py7
-rw-r--r--bsie/reader/preview/_rawpy.py5
-rw-r--r--bsie/reader/preview/utils.py5
-rw-r--r--bsie/reader/stat.py4
15 files changed, 47 insertions, 74 deletions
diff --git a/bsie/reader/__init__.py b/bsie/reader/__init__.py
index 4163d1c..a1c38a9 100644
--- a/bsie/reader/__init__.py
+++ b/bsie/reader/__init__.py
@@ -1,8 +1,8 @@
"""The Reader classes return high-level content structures from files.
The Reader fulfills two purposes:
- First, it brokers between multiple libraries and file formats.
- Second, it separates multiple aspects of a file into distinct content types.
+First, it brokers between multiple libraries and file formats.
+Second, it separates multiple aspects of a file into distinct content types.
Often, different libraries focus on reading different types of content from a
file. E.g. one would use different modules to read file system infos than to
@@ -11,9 +11,6 @@ type. Each distinct type can be implemented in a file or submodule that
provides a Reader implementation. Through utilization of submodules, different
file formats can be supported.
-Part of the bsie module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
"""
# standard imports
import typing
@@ -29,4 +26,3 @@ __all__: typing.Sequence[str] = (
)
## EOF ##
-## EOF ##
diff --git a/bsie/reader/base.py b/bsie/reader/base.py
index 099a327..a775701 100644
--- a/bsie/reader/base.py
+++ b/bsie/reader/base.py
@@ -1,13 +1,4 @@
-"""The Reader classes return high-level content structures from files.
-The Reader fulfills two purposes:
- First, it brokers between multiple libraries and file formats.
- Second, it separates multiple aspects of a file into distinct content types.
-
-Part of the bsie module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
-"""
# standard imports
import abc
import typing
diff --git a/bsie/reader/builder.py b/bsie/reader/builder.py
index 8699e75..d32700b 100644
--- a/bsie/reader/builder.py
+++ b/bsie/reader/builder.py
@@ -1,9 +1,4 @@
-"""
-Part of the bsie module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
-"""
# standard imports
import typing
diff --git a/bsie/reader/chain.py b/bsie/reader/chain.py
index 1dbc52b..79b44b4 100644
--- a/bsie/reader/chain.py
+++ b/bsie/reader/chain.py
@@ -1,9 +1,4 @@
-"""
-Part of the bsie module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
-"""
# standard imports
import logging
import typing
diff --git a/bsie/reader/exif.py b/bsie/reader/exif.py
new file mode 100644
index 0000000..2d0428b
--- /dev/null
+++ b/bsie/reader/exif.py
@@ -0,0 +1,44 @@
+
+# standard imports
+import typing
+
+# external imports
+import pyexiv2
+
+# bsie imports
+from bsie.utils import errors, filematcher
+
+# inner-module imports
+from . import base
+
+# constants
+MATCH_RULE = 'mime=image/jpeg'
+
+# exports
+__all__: typing.Sequence[str] = (
+ 'Exif',
+ )
+
+
+## code ##
+
+class Exif(base.Reader):
+ """Use pyexiv2 to read exif metadata from image files."""
+
+ def __init__(self):
+ self._match = filematcher.parse(MATCH_RULE)
+
+ def __call__(self, path: str) -> dict:
+ # perform quick checks first
+ if not self._match(path):
+ raise errors.UnsupportedFileFormatError(path)
+
+ try:
+ # open the file
+ img = pyexiv2.Image(path)
+ # read metadata
+ return img.read_exif()
+ except (TypeError, OSError, RuntimeError) as err:
+ raise errors.ReaderError(path) from err
+
+## EOF ##
diff --git a/bsie/reader/image/__init__.py b/bsie/reader/image/__init__.py
index c5d2a2a..89642f2 100644
--- a/bsie/reader/image/__init__.py
+++ b/bsie/reader/image/__init__.py
@@ -1,9 +1,4 @@
-"""
-Part of the bsie module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
-"""
# standard imports
import typing
diff --git a/bsie/reader/image/_pillow.py b/bsie/reader/image/_pillow.py
index 5b2bdf2..0611d3c 100644
--- a/bsie/reader/image/_pillow.py
+++ b/bsie/reader/image/_pillow.py
@@ -1,9 +1,4 @@
-"""
-Part of the bsie module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
-"""
# standard imports
import typing
diff --git a/bsie/reader/image/_raw.py b/bsie/reader/image/_raw.py
index 257fdb3..e5745aa 100644
--- a/bsie/reader/image/_raw.py
+++ b/bsie/reader/image/_raw.py
@@ -1,9 +1,4 @@
-"""
-Part of the bsie module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
-"""
# standard imports
import typing
diff --git a/bsie/reader/path.py b/bsie/reader/path.py
index 1ca05a0..45eb127 100644
--- a/bsie/reader/path.py
+++ b/bsie/reader/path.py
@@ -1,8 +1,4 @@
"""The Path reader produces a file path.
-
-Part of the bsie module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
"""
# standard imports
import typing
diff --git a/bsie/reader/preview/__init__.py b/bsie/reader/preview/__init__.py
index 3e69a4a..791a133 100644
--- a/bsie/reader/preview/__init__.py
+++ b/bsie/reader/preview/__init__.py
@@ -1,9 +1,4 @@
-"""
-Part of the bsie module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
-"""
# imports
import typing
diff --git a/bsie/reader/preview/_pg.py b/bsie/reader/preview/_pg.py
index 097c513..401b33d 100644
--- a/bsie/reader/preview/_pg.py
+++ b/bsie/reader/preview/_pg.py
@@ -1,9 +1,4 @@
-"""
-Part of the bsie module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
-"""
# standard imports
from functools import partial
import contextlib
diff --git a/bsie/reader/preview/_pillow.py b/bsie/reader/preview/_pillow.py
index 174d509..2b797c6 100644
--- a/bsie/reader/preview/_pillow.py
+++ b/bsie/reader/preview/_pillow.py
@@ -1,9 +1,4 @@
-"""
-Part of the bsie module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
-"""
# standard imports
from functools import partial
import typing
@@ -38,7 +33,7 @@ class PillowPreviewReader(base.Reader):
except PIL.UnidentifiedImageError as err:
# failed to open, skip file
raise errors.UnsupportedFileFormatError(path) from err
- except IOError as err:
+ except OSError as err:
raise errors.ReaderError(path) from err
# EOF ##
diff --git a/bsie/reader/preview/_rawpy.py b/bsie/reader/preview/_rawpy.py
index 2c20a48..16e8675 100644
--- a/bsie/reader/preview/_rawpy.py
+++ b/bsie/reader/preview/_rawpy.py
@@ -1,9 +1,4 @@
-"""
-Part of the bsie module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
-"""
# standard imports
from functools import partial
import typing
diff --git a/bsie/reader/preview/utils.py b/bsie/reader/preview/utils.py
index 2ef1562..82ecc31 100644
--- a/bsie/reader/preview/utils.py
+++ b/bsie/reader/preview/utils.py
@@ -1,9 +1,4 @@
-"""
-Part of the tagit module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
-"""
# standard imports
import typing
diff --git a/bsie/reader/stat.py b/bsie/reader/stat.py
index 706dc47..f42e7fb 100644
--- a/bsie/reader/stat.py
+++ b/bsie/reader/stat.py
@@ -1,8 +1,4 @@
"""The Stat reader produces filesystem stat information.
-
-Part of the bsie module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
"""
# standard imports
import os