diff options
Diffstat (limited to 'src/argaze/utils/UtilsFeatures.py')
-rw-r--r-- | src/argaze/utils/UtilsFeatures.py | 58 |
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 |