Skip to content

Commit

Permalink
Changes in FileMonitor
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
user authored and user committed Feb 21, 2024
1 parent 57739fc commit b97ab98
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions avtdl/plugins/file/text_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit b97ab98

Please sign in to comment.