Initial version of the GridFS storage driver
This commit is contained in:
@@ -1,16 +1,3 @@
|
||||
import tempfile
|
||||
|
||||
from common.conf import settings as common_settings
|
||||
|
||||
TEMPORARY_DIRECTORY = common_settings.TEMPORARY_DIRECTORY if common_settings.TEMPORARY_DIRECTORY else tempfile.mkdtemp()
|
||||
|
||||
#ugettext = lambda s: s
|
||||
|
||||
#TRANFORMATION_ROTATE = (u'-rotate %(degrees)d', ugettext(u'Rotation, arguments: degrees'))
|
||||
TRANFORMATION_CHOICES = {
|
||||
'rotate':'-rotate %(degrees)d'
|
||||
}
|
||||
|
||||
#getattr(settings, 'CONVERTER_TRANSFORMATION_LIST', [
|
||||
# TRANFORMATION_ROTATE,
|
||||
# ])
|
||||
|
||||
@@ -15,10 +15,9 @@ from converter.conf.settings import LOW_QUALITY_OPTIONS
|
||||
from converter.conf.settings import HIGH_QUALITY_OPTIONS
|
||||
|
||||
#from converter.conf.settings import UNOCONV_PATH
|
||||
|
||||
from converter import TEMPORARY_DIRECTORY, TRANFORMATION_CHOICES
|
||||
from utils import from_descriptor_to_tempfile
|
||||
|
||||
from common import TEMPORARY_DIRECTORY
|
||||
from converter import TRANFORMATION_CHOICES
|
||||
from documents.utils import document_save_to_temp_dir
|
||||
|
||||
QUALITY_DEFAULT = 'quality_default'
|
||||
QUALITY_LOW = 'quality_low'
|
||||
@@ -175,10 +174,8 @@ def get_page_count(input_filepath):
|
||||
#TODO: slugify OCR_OPTIONS and add to file name to cache
|
||||
def convert_document_for_ocr(document, page=0, format='tif'):
|
||||
#Extract document file
|
||||
document.file.open()
|
||||
desc = document.file.storage.open(document.file.path)
|
||||
input_filepath = from_descriptor_to_tempfile(desc, document.uuid)
|
||||
|
||||
input_filepath = document_save_to_temp_dir(document, document.uuid)
|
||||
|
||||
#Convert for OCR
|
||||
temp_filename, separator = os.path.splitext(os.path.basename(input_filepath))
|
||||
temp_path = os.path.join(TEMPORARY_DIRECTORY, temp_filename)
|
||||
|
||||
+1
-34
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from converter import TEMPORARY_DIRECTORY
|
||||
from common import TEMPORARY_DIRECTORY
|
||||
|
||||
#http://stackoverflow.com/questions/123198/how-do-i-copy-a-file-in-python
|
||||
def copyfile(source, dest, buffer_size=1024*1024):
|
||||
@@ -24,36 +24,3 @@ def copyfile(source, dest, buffer_size=1024*1024):
|
||||
|
||||
source.close()
|
||||
dest.close()
|
||||
|
||||
|
||||
def from_descriptor_to_tempfile(input_descriptor, filename, buffer_size=1024*1024):
|
||||
path = os.path.join(TEMPORARY_DIRECTORY, filename)
|
||||
|
||||
output_descriptor = open(path, 'wb')
|
||||
|
||||
while 1:
|
||||
copy_buffer = input_descriptor.read(buffer_size)
|
||||
if copy_buffer:
|
||||
output_descriptor.write(copy_buffer)
|
||||
else:
|
||||
break
|
||||
|
||||
input_descriptor.close()
|
||||
output_descriptor.close()
|
||||
return path
|
||||
|
||||
|
||||
def from_descriptor_to_new_tempfile(input_descriptor, buffer_size=1024*1024):
|
||||
output_descriptor, tmp_filename = tempfile.mkstemp()
|
||||
|
||||
while 1:
|
||||
copy_buffer = input_descriptor.read(buffer_size)
|
||||
if copy_buffer:
|
||||
#output_descriptor.write(copy_buffer)
|
||||
os.write(output_descriptor, copy_buffer)
|
||||
else:
|
||||
break
|
||||
|
||||
input_descriptor.close()
|
||||
os.close(output_descriptor)
|
||||
return tmp_filename
|
||||
|
||||
Reference in New Issue
Block a user