mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Format Python code with black
This commit is contained in:
@@ -14,9 +14,8 @@ class TextDocumentParser(DocumentParser):
|
||||
logging_name = "paperless.parsing.text"
|
||||
|
||||
def get_thumbnail(self, document_path, mime_type, file_name=None):
|
||||
|
||||
def read_text():
|
||||
with open(document_path, 'r') as src:
|
||||
with open(document_path, "r") as src:
|
||||
lines = [line.strip() for line in src.readlines()]
|
||||
text = "\n".join(lines[:50])
|
||||
return text
|
||||
@@ -26,7 +25,8 @@ class TextDocumentParser(DocumentParser):
|
||||
font = ImageFont.truetype(
|
||||
font=settings.THUMBNAIL_FONT_NAME,
|
||||
size=20,
|
||||
layout_engine=ImageFont.LAYOUT_BASIC)
|
||||
layout_engine=ImageFont.LAYOUT_BASIC,
|
||||
)
|
||||
draw.text((5, 5), read_text(), font=font, fill="black")
|
||||
|
||||
out_path = os.path.join(self.tempdir, "thumb.png")
|
||||
@@ -35,5 +35,5 @@ class TextDocumentParser(DocumentParser):
|
||||
return out_path
|
||||
|
||||
def parse(self, document_path, mime_type, file_name=None):
|
||||
with open(document_path, 'r') as f:
|
||||
with open(document_path, "r") as f:
|
||||
self.text = f.read()
|
||||
|
@@ -1,4 +1,3 @@
|
||||
|
||||
def get_parser(*args, **kwargs):
|
||||
from .parsers import TextDocumentParser
|
||||
|
||||
@@ -12,5 +11,5 @@ def text_consumer_declaration(sender, **kwargs):
|
||||
"mime_types": {
|
||||
"text/plain": ".txt",
|
||||
"text/csv": ".csv",
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@@ -7,20 +7,23 @@ from paperless_text.parsers import TextDocumentParser
|
||||
|
||||
|
||||
class TestTextParser(DirectoriesMixin, TestCase):
|
||||
|
||||
def test_thumbnail(self):
|
||||
|
||||
parser = TextDocumentParser(None)
|
||||
|
||||
# just make sure that it does not crash
|
||||
f = parser.get_thumbnail(os.path.join(os.path.dirname(__file__), "samples", "test.txt"), "text/plain")
|
||||
f = parser.get_thumbnail(
|
||||
os.path.join(os.path.dirname(__file__), "samples", "test.txt"), "text/plain"
|
||||
)
|
||||
self.assertTrue(os.path.isfile(f))
|
||||
|
||||
def test_parse(self):
|
||||
|
||||
parser = TextDocumentParser(None)
|
||||
|
||||
parser.parse(os.path.join(os.path.dirname(__file__), "samples", "test.txt"), "text/plain")
|
||||
parser.parse(
|
||||
os.path.join(os.path.dirname(__file__), "samples", "test.txt"), "text/plain"
|
||||
)
|
||||
|
||||
self.assertEqual(parser.get_text(), "This is a test file.\n")
|
||||
self.assertIsNone(parser.get_archive_path())
|
||||
|
Reference in New Issue
Block a user