mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	associate error messages with documents
This commit is contained in:
		@@ -4,7 +4,9 @@ import multiprocessing
 | 
			
		||||
import logging
 | 
			
		||||
import os
 | 
			
		||||
import shutil
 | 
			
		||||
import sys
 | 
			
		||||
import uuid
 | 
			
		||||
from io import TextIOBase
 | 
			
		||||
 | 
			
		||||
import tqdm
 | 
			
		||||
from django import db
 | 
			
		||||
@@ -12,7 +14,6 @@ from django.conf import settings
 | 
			
		||||
from django.core.management.base import BaseCommand
 | 
			
		||||
from django.db import transaction
 | 
			
		||||
from filelock import FileLock
 | 
			
		||||
from whoosh.writing import AsyncWriter
 | 
			
		||||
 | 
			
		||||
from documents.models import Document
 | 
			
		||||
from ... import index
 | 
			
		||||
@@ -24,11 +25,28 @@ from ...parsers import get_parser_class_for_mime_type
 | 
			
		||||
logger = logging.getLogger("paperless.management.archiver")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class LoggerWriter(TextIOBase):
 | 
			
		||||
 | 
			
		||||
    def __init__(self, doc: Document):
 | 
			
		||||
        self.doc = doc
 | 
			
		||||
 | 
			
		||||
    def write(self, message):
 | 
			
		||||
        # if statement reduces the amount of newlines that are
 | 
			
		||||
        # printed to the logger
 | 
			
		||||
        if message != '\n':
 | 
			
		||||
            logger.error(
 | 
			
		||||
                f"Document {self.doc} (ID: {self.doc.pk}): {message}"
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def handle_document(document_id):
 | 
			
		||||
    document = Document.objects.get(id=document_id)
 | 
			
		||||
 | 
			
		||||
    mime_type = document.mime_type
 | 
			
		||||
 | 
			
		||||
    # redirect errors to the log and associate them with the current document
 | 
			
		||||
    sys.stderr = LoggerWriter(document)
 | 
			
		||||
 | 
			
		||||
    parser_class = get_parser_class_for_mime_type(mime_type)
 | 
			
		||||
 | 
			
		||||
    if not parser_class:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user