# Path: post_office/lockfile.py
# class FileLocked(Exception):
# class FileLock:
#     def __init__(self, lock_filename, timeout=None, force=False):
#     def get_lock_pid(self):
#     def valid_lock(self):
#     def is_locked(self, force=False):
#     def acquire(self):
#     def release(self):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
# 
# Path: post_office/mail.py
# def send_queued_mail_until_done(lockfile=default_lockfile, processes=1, log_level=None):
#     """
#     Send mail in queue batch by batch, until all emails have been processed.
#     """
#     try:
#         with FileLock(lockfile):
#             logger.info('Acquired lock for sending queued emails at %s.lock', lockfile)
#             while True:
#                 try:
#                     send_queued(processes, log_level)
#                 except Exception as e:
#                     logger.exception(e, extra={'status_code': 500})
#                     raise
# 
#                 # Close DB connection to avoid multiprocessing errors
#                 db_connection.close()
# 
#                 if not get_queued().exists():
#                     break
#     except FileLocked:
#         logger.info('Failed to acquire lock, terminating now.')


from django.core.management.base import BaseCommand
from ...lockfile import default_lockfile
from ...mail import send_queued_mail_until_done



class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument(
            '-p', '--processes',
            type=int,
            default=1,
            help='Number of processes used to send emails',
        )
        parser.add_argument(
            '-L', '--lockfile',
            default=default_lockfile,
            help='Absolute path of lockfile to acquire',
        )
        parser.add_argument(

# Path: post_office/lockfile.py
# class FileLocked(Exception):
# class FileLock:
#     def __init__(self, lock_filename, timeout=None, force=False):
#     def get_lock_pid(self):
#     def valid_lock(self):
#     def is_locked(self, force=False):
#     def acquire(self):
#     def release(self):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
# 
# Path: post_office/mail.py
# def send_queued_mail_until_done(lockfile=default_lockfile, processes=1, log_level=None):
#     """
#     Send mail in queue batch by batch, until all emails have been processed.
#     """
#     try:
#         with FileLock(lockfile):
#             logger.info('Acquired lock for sending queued emails at %s.lock', lockfile)
#             while True:
#                 try:
#                     send_queued(processes, log_level)
#                 except Exception as e:
#                     logger.exception(e, extra={'status_code': 500})
#                     raise
# 
#                 # Close DB connection to avoid multiprocessing errors
#                 db_connection.close()
# 
#                 if not get_queued().exists():
#                     break
#     except FileLocked:
#         logger.info('Failed to acquire lock, terminating now.')


# Path: post_office/management/commands/send_queued_mail.py
from django.core.management.base import BaseCommand
from ...lockfile import default_lockfile
from ...mail import send_queued_mail_until_done




class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument(
            '-p', '--processes',
            type=int,
            default=1,
            help='Number of processes used to send emails',
        )
        parser.add_argument(
            '-L', '--lockfile',
            default=default_lockfile,
            help='Absolute path of lockfile to acquire',
        )
        parser.add_argument(

            '-l', '--log-level',