mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Refactor: extract fn 'make_dirs'
This commit is contained in:
parent
ea287e0db2
commit
873c98dddb
@ -43,10 +43,7 @@ class Consumer:
|
||||
self.consume = consume
|
||||
self.scratch = scratch
|
||||
|
||||
try:
|
||||
os.makedirs(self.scratch)
|
||||
except FileExistsError:
|
||||
pass
|
||||
make_dirs(self.scratch)
|
||||
|
||||
if not self.consume:
|
||||
raise ConsumerError(
|
||||
@ -245,3 +242,11 @@ class Consumer:
|
||||
with open(doc, "rb") as f:
|
||||
checksum = hashlib.md5(f.read()).hexdigest()
|
||||
return Document.objects.filter(checksum=checksum).exists()
|
||||
|
||||
|
||||
def make_dirs(*dirs):
|
||||
for dir in dirs:
|
||||
try:
|
||||
os.makedirs(dir)
|
||||
except FileExistsError:
|
||||
pass
|
||||
|
@ -6,7 +6,7 @@ import time
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from ...consumer import Consumer, ConsumerError
|
||||
from ...consumer import Consumer, ConsumerError, make_dirs
|
||||
from ...mail import MailFetcher, MailFetcherError
|
||||
|
||||
|
||||
@ -67,11 +67,7 @@ class Command(BaseCommand):
|
||||
except (ConsumerError, MailFetcherError) as e:
|
||||
raise CommandError(e)
|
||||
|
||||
for path in (self.ORIGINAL_DOCS, self.THUMB_DOCS):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except FileExistsError:
|
||||
pass
|
||||
make_dirs(self.ORIGINAL_DOCS, self.THUMB_DOCS)
|
||||
|
||||
logging.getLogger(__name__).info(
|
||||
"Starting document consumer at {}".format(directory)
|
||||
|
Loading…
x
Reference in New Issue
Block a user