# Path: settings.py
# ROOT_PATH = os.path.dirname(__file__)
# 
# Path: uploads/models.py
# class Document(models.Model):
#     """Note that a number of fields have indexes in the database despite
#     lacking them here:
# 
#     mysql> show index from uploads_document;
#         +------------------+-----------------+-------------+-------------+
#         | Table            | Key_name        | Column_name | Cardinality |
#         +------------------+-----------------+-------------+-------------+
#         | uploads_document | PRIMARY         | id          |    26652929 |
#         | uploads_document | court           | court       |         206 |
#         | uploads_document | court           | casenum     |     1025112 |
#         | uploads_document | court           | docnum      |    26652929 |
#         | uploads_document | court           | subdocnum   |    26652929 |
#         | uploads_document | docid_idx       | docid       |    26652929 |
#         | uploads_document | document_free_i | free_import |           2 |
#         | uploads_document | lastdateindex   | lastdate    |    26652929 |
#         | uploads_document | modifiedindex   | modified    |     6663232 |
#         +------------------+-----------------+-------------+-------------+
# 
#     (https://dev.mysql.com/doc/refman/5.0/en/show-index.html)
# 
#     """
#     court = models.CharField(
#         maxlength=10,
#     )
#     casenum = models.CharField(
#         maxlength=30,
#     )
#     docnum = models.CharField(
#         maxlength=30,
#     )
#     subdocnum = models.CharField(
#         maxlength=30,
#     )
#     docid = models.CharField(
#         maxlength=32,
#         null=True,
#         blank=True,
#         db_index=True,
#     )
#     de_seq_num = models.PositiveIntegerField(
#         null=True,
#         blank=True,
#     )
#     dm_id = models.PositiveIntegerField(
#         null=True,
#         blank=True,
#     )
#     sha1 = models.CharField(
#         maxlength=40,
#         null=True,
#         blank=True,
#     )
#     available = models.BooleanField(
#         default=0,
#     )
#     lastdate = models.DateTimeField(
#         null=True,
#         blank=True,
#         db_index=True,
#     )
#     modified = models.DateTimeField(
#         null=True,
#         blank=True,
#         auto_now_add=True,
#         db_index=True,
#     )
#     free_import = models.BooleanField(
#         default=0,
#         db_index=True,
#     )
#     team_name = models.CharField(
#         maxlength=40,
#         null=True,
#         blank=True
#     )
# 
#     class Meta:
#         unique_together = (
#             (
#                 "court",
#                 "casenum",
#                 "docnum",
#                 "subdocnum",
#             ),
#         )
# 
# class PickledPut(models.Model):
#     filename = models.CharField(
#         maxlength=128,
#         primary_key=True,
#     )
#     docket = models.BooleanField(
#         default=0,
#     )
#     ready = models.BooleanField(
#         default=0,
#     )
#     processing = models.BooleanField(
#         default=0,
#     )
# 
# class Uploader(models.Model):
#     # implicit 'id' IntegerField being used.
#     key = models.CharField(
#         maxlength=8,
#     )
#     name = models.CharField(
#         maxlength=64,
#     )


import os
import socket
import urllib2
import httplib
import logging
import datetime
import re
import cPickle as pickle
import cStringIO as StringIO
import signal
import traceback
import pdb
import DocketXML
import UploadHandler
import BucketLockManager
import InternetArchiveDirect as IADirect
import InternetArchiveCommon as IACommon
import DocumentManager
from MySQLdb import IntegrityError
from pyPdf import PdfFileReader
from pyPdf.utils import PdfReadError
from settings import ROOT_PATH
from uploads.models import Document, PickledPut, Uploader
from django.conf import settings as config
                       invalid_PDF=False):
    fullname = "%s/_%s" % (BASE_PICKLE_JAR, filename)
    if ssn:
        destname = "%s/_ssn_%s" % (BASE_PICKLE_JAR, filename)
    elif blacklist_file:
        destname = "%s/_blacklisted_%s" % (BASE_PICKLE_JAR, filename)
    elif invalid_PDF:
        destname = "%s/_invalid_pdf_%s" % (BASE_PICKLE_JAR, filename)
    else:
        destname = "%s/_quarantined_%s" % (BASE_PICKLE_JAR, filename)

    try:
        os.rename(fullname, destname)
    except OSError:
        print "  %s quarantine failed." % (filename)
    else:
        if ssn:
            print "  %s placed in SSN quarantine." % (filename)
        elif blacklist_file:
            print "  %s placed in Blacklist quarantine." % (filename)
        elif invalid_PDF:
            print "  %s placed in Invalid PDF quarantine." % (filename)
        else:
            print "  %s placed in quarantine." % (filename)


def _in_blacklist(filename):
    if BLACKLIST_DICT == {}:
        # Initialize blacklist


# Path: settings.py
# ROOT_PATH = os.path.dirname(__file__)
# 
# Path: uploads/models.py
# class Document(models.Model):
#     """Note that a number of fields have indexes in the database despite
#     lacking them here:
# 
#     mysql> show index from uploads_document;
#         +------------------+-----------------+-------------+-------------+
#         | Table            | Key_name        | Column_name | Cardinality |
#         +------------------+-----------------+-------------+-------------+
#         | uploads_document | PRIMARY         | id          |    26652929 |
#         | uploads_document | court           | court       |         206 |
#         | uploads_document | court           | casenum     |     1025112 |
#         | uploads_document | court           | docnum      |    26652929 |
#         | uploads_document | court           | subdocnum   |    26652929 |
#         | uploads_document | docid_idx       | docid       |    26652929 |
#         | uploads_document | document_free_i | free_import |           2 |
#         | uploads_document | lastdateindex   | lastdate    |    26652929 |
#         | uploads_document | modifiedindex   | modified    |     6663232 |
#         +------------------+-----------------+-------------+-------------+
# 
#     (https://dev.mysql.com/doc/refman/5.0/en/show-index.html)
# 
#     """
#     court = models.CharField(
#         maxlength=10,
#     )
#     casenum = models.CharField(
#         maxlength=30,
#     )
#     docnum = models.CharField(
#         maxlength=30,
#     )
#     subdocnum = models.CharField(
#         maxlength=30,
#     )
#     docid = models.CharField(
#         maxlength=32,
#         null=True,
#         blank=True,
#         db_index=True,
#     )
#     de_seq_num = models.PositiveIntegerField(
#         null=True,
#         blank=True,
#     )
#     dm_id = models.PositiveIntegerField(
#         null=True,
#         blank=True,
#     )
#     sha1 = models.CharField(
#         maxlength=40,
#         null=True,
#         blank=True,
#     )
#     available = models.BooleanField(
#         default=0,
#     )
#     lastdate = models.DateTimeField(
#         null=True,
#         blank=True,
#         db_index=True,
#     )
#     modified = models.DateTimeField(
#         null=True,
#         blank=True,
#         auto_now_add=True,
#         db_index=True,
#     )
#     free_import = models.BooleanField(
#         default=0,
#         db_index=True,
#     )
#     team_name = models.CharField(
#         maxlength=40,
#         null=True,
#         blank=True
#     )
# 
#     class Meta:
#         unique_together = (
#             (
#                 "court",
#                 "casenum",
#                 "docnum",
#                 "subdocnum",
#             ),
#         )
# 
# class PickledPut(models.Model):
#     filename = models.CharField(
#         maxlength=128,
#         primary_key=True,
#     )
#     docket = models.BooleanField(
#         default=0,
#     )
#     ready = models.BooleanField(
#         default=0,
#     )
#     processing = models.BooleanField(
#         default=0,
#     )
# 
# class Uploader(models.Model):
#     # implicit 'id' IntegerField being used.
#     key = models.CharField(
#         maxlength=8,
#     )
#     name = models.CharField(
#         maxlength=64,
#     )


# Path: uploads/InternetArchive.py
import os
import socket
import urllib2
import httplib
import logging
import datetime
import re
import cPickle as pickle
import cStringIO as StringIO
import signal
import traceback
import pdb
import DocketXML
import UploadHandler
import BucketLockManager
import InternetArchiveDirect as IADirect
import InternetArchiveCommon as IACommon
import DocumentManager
from MySQLdb import IntegrityError
from pyPdf import PdfFileReader
from pyPdf.utils import PdfReadError
from settings import ROOT_PATH
from uploads.models import Document, PickledPut, Uploader
from django.conf import settings as config

                       invalid_PDF=False):
    fullname = "%s/_%s" % (BASE_PICKLE_JAR, filename)
    if ssn:
        destname = "%s/_ssn_%s" % (BASE_PICKLE_JAR, filename)
    elif blacklist_file:
        destname = "%s/_blacklisted_%s" % (BASE_PICKLE_JAR, filename)
    elif invalid_PDF:
        destname = "%s/_invalid_pdf_%s" % (BASE_PICKLE_JAR, filename)
    else:
        destname = "%s/_quarantined_%s" % (BASE_PICKLE_JAR, filename)

    try:
        os.rename(fullname, destname)
    except OSError:
        print "  %s quarantine failed." % (filename)
    else:
        if ssn:
            print "  %s placed in SSN quarantine." % (filename)
        elif blacklist_file:
            print "  %s placed in Blacklist quarantine." % (filename)
        elif invalid_PDF:
            print "  %s placed in Invalid PDF quarantine." % (filename)
        else:
            print "  %s placed in quarantine." % (filename)


def _in_blacklist(filename):
    if BLACKLIST_DICT == {}:
        # Initialize blacklist


        BLACKLIST_LOCATION = ROOT_PATH + "/blacklist"