From db6190a295383247c0762d1ff2a82a9af3d8d2cd Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Fri, 22 Aug 2014 20:02:58 -0700 Subject: [PATCH] Cleaning up management commands for PEP-8 and consistency. --- django_mailbox/management/commands/getmail.py | 25 ++++++++++++++----- .../commands/processincomingmessage.py | 11 +++++--- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/django_mailbox/management/commands/getmail.py b/django_mailbox/management/commands/getmail.py index 6041782..31b2dbd 100644 --- a/django_mailbox/management/commands/getmail.py +++ b/django_mailbox/management/commands/getmail.py @@ -1,17 +1,30 @@ +import logging + from django.core.management.base import BaseCommand from django_mailbox.models import Mailbox + +logger = logging.getLogger(__name__) +logging.basicConfig(level=logging.INFO) + + class Command(BaseCommand): def handle(self, *args, **options): mailboxes = Mailbox.active_mailboxes.all() if args: - mailboxes = mailboxes.filter(name = ' '.join(args)) + mailboxes = mailboxes.filter( + name=' '.join(args) + ) for mailbox in mailboxes: - self.stdout.write('Gathering messages for %s\n' % mailbox.name) + logger.info( + 'Gathering messages for %s', + mailbox.name + ) messages = mailbox.get_new_mail() for message in messages: - self.stdout.write('Received %s (from %s)\n' % ( - message.subject, - message.from_address - )) + logger.info( + 'Received %s (from %s)', + message.subject, + message.from_address + ) diff --git a/django_mailbox/management/commands/processincomingmessage.py b/django_mailbox/management/commands/processincomingmessage.py index 8d269b8..2fd9cba 100644 --- a/django_mailbox/management/commands/processincomingmessage.py +++ b/django_mailbox/management/commands/processincomingmessage.py @@ -7,9 +7,11 @@ from django.core.management.base import BaseCommand from django_mailbox.models import Mailbox + logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) + class Command(BaseCommand): args = "<[Mailbox Name (optional)]>" command = "Receive incoming mail via stdin" @@ -22,14 +24,17 @@ class Command(BaseCommand): else: mailbox = self.get_mailbox_for_message(message) mailbox.process_incoming_message(message) - logger.info("Message received from %s" % message['from']) + logger.info( + "Message received from %s", + message['from'] + ) else: logger.warning("Message not processable.") def get_mailbox_by_name(self, name): mailbox, created = Mailbox.objects.get_or_create( - name=name, - ) + name=name, + ) return mailbox def get_mailbox_for_message(self, message):