From b97ab98dc72d18476b89bd65944b275ba7776c87 Mon Sep 17 00:00:00 2001 From: user Date: Mon, 19 Feb 2024 23:32:57 +0300 Subject: [PATCH] Changes in FileMonitor - allow providing path to non-existing file - ensure path can be opened by calling open() at config parsing time - when parsing entire file as a record content skip empty lines --- avtdl/plugins/file/text_file.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/avtdl/plugins/file/text_file.py b/avtdl/plugins/file/text_file.py index ca629d0..34d2808 100644 --- a/avtdl/plugins/file/text_file.py +++ b/avtdl/plugins/file/text_file.py @@ -39,7 +39,11 @@ class FileMonitorEntity(TaskMonitorEntity): @classmethod def check_length(cls, path: Path) -> Path: try: - path.exists() + if path.is_dir(): + raise ValueError(f'path is a directory: "{path}"') + if path.exists(): + with open(path, 'rb') as _: + pass except OSError as e: raise ValueError(f'{e}') return path @@ -104,8 +108,10 @@ def get_records(self, entity: FileMonitorEntity) -> List[TextRecord]: else: lines = [text] for line in lines: - record = TextRecord(text=line.strip()) - records.append(record) + text = line.strip() + if text: + record = TextRecord(text=text) + records.append(record) return records