aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThéo de la Hogue2024-04-16 18:30:33 +0200
committerThéo de la Hogue2024-04-16 18:30:33 +0200
commita3e92996a3e7ab21a5c493a138f9f97e1026cabf (patch)
tree5824dd5ea7d2a682799f6af28205150468353a65
parent59ed6dea2dc429d039e86c648c58480930b16146 (diff)
downloadargaze-a3e92996a3e7ab21a5c493a138f9f97e1026cabf.zip
argaze-a3e92996a3e7ab21a5c493a138f9f97e1026cabf.tar.gz
argaze-a3e92996a3e7ab21a5c493a138f9f97e1026cabf.tar.bz2
argaze-a3e92996a3e7ab21a5c493a138f9f97e1026cabf.tar.xz
Adding new FileRerader class.
-rw-r--r--src/argaze/utils/UtilsFeatures.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/argaze/utils/UtilsFeatures.py b/src/argaze/utils/UtilsFeatures.py
index c04d20a..3c5be35 100644
--- a/src/argaze/utils/UtilsFeatures.py
+++ b/src/argaze/utils/UtilsFeatures.py
@@ -19,6 +19,7 @@ __license__ = "GPLv3"
import os
import pathlib
import time
+import csv
import types
import traceback
@@ -243,6 +244,63 @@ class FileWriter(DataFeatures.PipelineStepObject):
# Write into file
print(data, file=self.__file, flush=True)
+class FileReader(DataFeatures.PipelineStepObject):
+ """Read data from a file line by line."""
+
+ # noinspection PyMissingConstructor
+ @DataFeatures.PipelineStepInit
+ def __init__(self, **kwargs):
+
+ # Init private attributes
+ self.__path = None
+ self.__separator = ','
+
+ @property
+ def path(self) -> str:
+ """File path where to read data."""
+ return self.__path
+
+ @path.setter
+ def path(self, path: str):
+
+ self.__path = pathlib.Path(path)
+
+ @property
+ def separator(self) -> str:
+ """String used to separate elements during string to tuple conversion."""
+ return self.__separator
+
+ @separator.setter
+ def separator(self, separator: str):
+
+ self.__separator = separator
+
+ @DataFeatures.PipelineStepEnter
+ def __enter__(self):
+
+ # Open file
+ self.__file = csv.reader(open(self.__path), delimiter= self.__separator)
+
+ @DataFeatures.PipelineStepExit
+ def __exit__(self, exception_type, exception_value, exception_traceback):
+
+ pass
+
+ def read(self) -> str|tuple:
+ """Read next data from file.
+
+ !!! note
+ Quoted strings separated by separator string are converted into tuple elements.
+ """
+
+ try:
+
+ return next(self.__file)
+
+ except Exception:
+
+ raise EOFError
+
class VideoWriter(DataFeatures.PipelineStepObject, DataFeatures.SharedObject):
"""Open ffmpeg application as sub-process.
FFmpeg input PIPE: RAW images in BGR color format