# Path: uploads/models.py
# class BucketLock(models.Model):
#     court = models.CharField(
#         maxlength=10,
#     )
#     casenum = models.CharField(
#         maxlength=30,
#     )
#     uploaderid = models.IntegerField()
#     nonce = models.CharField(
#         maxlength=6,
#     )
#     ready = models.BooleanField(
#         default=0,
#     )
#     processing = models.BooleanField(
#         default=0,
#     )
#     locktime = models.DateTimeField(
#         auto_now_add=True,
#     )
# 
#     class Meta:
#         unique_together = (
#             (
#                 "court",
#                 "casenum",
#             ),
#         )
# 
#     def __unicode__(self):
#         return str(self.court) + "." + str(self.casenum)


import logging
import DocketXML
from MySQLdb import IntegrityError
from uploads.models import BucketLock
            locklist.append(lock)

    return locklist


def mark_expired_for_processing(timeout_cutoff):
    # Get all expired entries regardless of readiness.
    expiredquery = BucketLock.objects.filter(processing=0,
                                             locktime__lt=timeout_cutoff)

    locklist = []
    # Set all expired entries to the processing state
    for expiredlock in expiredquery:
        expiredlock.ready = 1
        expiredlock.processing = 1
        expiredlock.nonce = ""
        try:
            expiredlock.save()
        except IntegrityError:
            logging.error("mark_expired_for_processing: could not save %s %s" %
                          (expiredlock.court, unicode(expiredlock.casenum)))
        else:
            locklist.append(expiredlock)

    return locklist


def try_lock_later(lock):
    lock.processing = 0


# Path: uploads/models.py
# class BucketLock(models.Model):
#     court = models.CharField(
#         maxlength=10,
#     )
#     casenum = models.CharField(
#         maxlength=30,
#     )
#     uploaderid = models.IntegerField()
#     nonce = models.CharField(
#         maxlength=6,
#     )
#     ready = models.BooleanField(
#         default=0,
#     )
#     processing = models.BooleanField(
#         default=0,
#     )
#     locktime = models.DateTimeField(
#         auto_now_add=True,
#     )
# 
#     class Meta:
#         unique_together = (
#             (
#                 "court",
#                 "casenum",
#             ),
#         )
# 
#     def __unicode__(self):
#         return str(self.court) + "." + str(self.casenum)


# Path: uploads/BucketLockManager.py
import logging
import DocketXML
from MySQLdb import IntegrityError
from uploads.models import BucketLock

            locklist.append(lock)

    return locklist


def mark_expired_for_processing(timeout_cutoff):
    # Get all expired entries regardless of readiness.
    expiredquery = BucketLock.objects.filter(processing=0,
                                             locktime__lt=timeout_cutoff)

    locklist = []
    # Set all expired entries to the processing state
    for expiredlock in expiredquery:
        expiredlock.ready = 1
        expiredlock.processing = 1
        expiredlock.nonce = ""
        try:
            expiredlock.save()
        except IntegrityError:
            logging.error("mark_expired_for_processing: could not save %s %s" %
                          (expiredlock.court, unicode(expiredlock.casenum)))
        else:
            locklist.append(expiredlock)

    return locklist


def try_lock_later(lock):
    lock.processing = 0


    try: