aboutsummaryrefslogtreecommitdiffstats
path: root/bsie/reader
diff options
context:
space:
mode:
Diffstat (limited to 'bsie/reader')
-rw-r--r--bsie/reader/__init__.py19
-rw-r--r--bsie/reader/path.py28
-rw-r--r--bsie/reader/stat.py32
3 files changed, 79 insertions, 0 deletions
diff --git a/bsie/reader/__init__.py b/bsie/reader/__init__.py
new file mode 100644
index 0000000..a45f22b
--- /dev/null
+++ b/bsie/reader/__init__.py
@@ -0,0 +1,19 @@
+"""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.
+
+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
+read exif or pixel data of an image. Hence, this module is organized by content
+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
+"""
+
+## EOF ##
diff --git a/bsie/reader/path.py b/bsie/reader/path.py
new file mode 100644
index 0000000..d60f187
--- /dev/null
+++ b/bsie/reader/path.py
@@ -0,0 +1,28 @@
+"""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
+"""
+# imports
+import typing
+
+# bsie imports
+from bsie.base import reader
+
+# exports
+__all__: typing.Sequence[str] = (
+ 'Path',
+ )
+
+
+## code ##
+
+class Path(reader.Reader):
+ """Return the path."""
+
+ def __call__(self, path: str) -> str:
+ return path
+
+
+## EOF ##
diff --git a/bsie/reader/stat.py b/bsie/reader/stat.py
new file mode 100644
index 0000000..fc5fb24
--- /dev/null
+++ b/bsie/reader/stat.py
@@ -0,0 +1,32 @@
+"""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
+"""
+# imports
+import os
+import typing
+
+# bsie imports
+from bsie.base import errors, reader
+
+# exports
+__all__: typing.Sequence[str] = (
+ 'Stat',
+ )
+
+
+## code ##
+
+class Stat(reader.Reader):
+ """Read and return the filesystem's stat infos."""
+
+ def __call__(self, path: str) -> os.stat_result:
+ try:
+ return os.stat(path)
+ except Exception as err:
+ raise errors.ReaderError(path) from err
+
+
+## EOF ##