checking file types against parsers in the consumer.

This commit is contained in:
jonaswinkler
2020-12-01 15:26:05 +01:00
parent daf2e345c4
commit e4eeb29f54
5 changed files with 127 additions and 113 deletions

View File

@@ -11,6 +11,7 @@ from watchdog.events import FileSystemEventHandler
from watchdog.observers.polling import PollingObserver
from documents.models import Tag
from documents.parsers import is_file_ext_supported
try:
from inotifyrecursive import INotify, flags
@@ -37,11 +38,19 @@ def _tags_from_path(filepath):
def _consume(filepath):
if os.path.isdir(filepath):
return
if not os.path.isfile(filepath):
logger.debug(
f"Not consuming file {filepath}: File has moved.")
return
if not is_file_ext_supported(os.path.splitext(filepath)[1]):
logger.debug(
f"Not consuming file {filepath}: Unknown file extension.")
return
tag_ids = None
try:
if settings.CONSUMER_SUBDIRS_AS_TAGS:
@@ -181,7 +190,7 @@ class Command(BaseCommand):
try:
while not self.stop_flag:
for event in inotify.read(timeout=1000, read_delay=1000):
for event in inotify.read(timeout=1000):
if recursive:
path = inotify.get_path(event.wd)
else: