From bccac5017c291f7b821231442f6e62fc4d6abfaf Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Mon, 21 May 2018 00:35:34 +0200 Subject: [PATCH] fixup: remove helper fn 'make_dirs' --- src/documents/consumer.py | 10 +--------- src/documents/management/commands/document_consumer.py | 5 +++-- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/documents/consumer.py b/src/documents/consumer.py index cca7c1c13..37151d1b4 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -48,7 +48,7 @@ class Consumer: self.consume = consume self.scratch = scratch - make_dirs(self.scratch) + os.makedirs(self.scratch, exists_ok=True) if not self.consume: raise ConsumerError( @@ -247,11 +247,3 @@ 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 diff --git a/src/documents/management/commands/document_consumer.py b/src/documents/management/commands/document_consumer.py index a0e2f00fe..4bf403318 100644 --- a/src/documents/management/commands/document_consumer.py +++ b/src/documents/management/commands/document_consumer.py @@ -7,7 +7,7 @@ import time from django.conf import settings from django.core.management.base import BaseCommand, CommandError -from ...consumer import Consumer, ConsumerError, make_dirs +from ...consumer import Consumer, ConsumerError from ...mail import MailFetcher, MailFetcherError try: @@ -80,7 +80,8 @@ class Command(BaseCommand): except (ConsumerError, MailFetcherError) as e: raise CommandError(e) - make_dirs(self.ORIGINAL_DOCS, self.THUMB_DOCS) + for d in (self.ORIGINAL_DOCS, self.THUMB_DOCS): + os.makedirs(d, exists_ok=True) logging.getLogger(__name__).info( "Starting document consumer at {}{}".format(