import logging

from django.conf import settings
from django.core.management.base import NoArgsCommand

from mailer.engine import send_all


# allow a sysadmin to pause the sending of mail temporarily.
PAUSE_SEND = getattr(settings, "MAILER_PAUSE_SEND", False)


class Command(NoArgsCommand):
    help = "Do one pass through the mail queue, attempting to send all mail."
    
    def handle_noargs(self, **options):
        log_levels = {
            '0': logging.WARNING,
            '1': logging.INFO,
            '2': logging.DEBUG,
        }
        level = log_levels[options['verbosity']]
        logging.basicConfig(level=level, format="%(message)s")
        # if PAUSE_SEND is turned on don't do anything.
        if not PAUSE_SEND:
            send_all()
        else:
            logging.info("sending is paused, quitting.")
