Moved the converter to its own app

This commit is contained in:
Roberto Rosario
2011-02-08 19:46:46 -04:00
parent 584f525783
commit 37f74a3f26
7 changed files with 42 additions and 7 deletions

View File

@@ -0,0 +1,5 @@
import tempfile
from documents.conf import settings as documents_settings
TEMPORARY_DIRECTORY = documents_settings.TEMPORARY_DIRECTORY if documents_settings.TEMPORARY_DIRECTORY else tempfile.mkdtemp()

View File

@@ -4,13 +4,14 @@ import subprocess
import tempfile
#from django.core.files.base import File
from documents.conf.settings import TEMPORARY_DIRECTORY
#from documents.conf.settings import TEMPORARY_DIRECTORY
from converter import TEMPORARY_DIRECTORY
def in_cache(input_filepath, size, page=0, format='jpg'):
temp_directory = TEMPORARY_DIRECTORY if TEMPORARY_DIRECTORY else tempfile.mkdtemp()
#temp_directory = TEMPORARY_DIRECTORY if TEMPORARY_DIRECTORY else tempfile.mkdtemp()
temp_filename, separator = os.path.splitext(os.path.basename(input_filepath))
temp_path = os.path.join(temp_directory, temp_filename)
temp_path = os.path.join(TEMPORARY_DIRECTORY, temp_filename)
output_arg = '%s_%s%s%s' % (temp_path, size, os.extsep, format)
input_arg = '%s[%s]' % (input_filepath, page)
if os.path.exists(output_arg):
@@ -20,13 +21,13 @@ def in_cache(input_filepath, size, page=0, format='jpg'):
def convert(input_filepath, size, cache=True, page=0, format='jpg'):
temp_directory = TEMPORARY_DIRECTORY if TEMPORARY_DIRECTORY else tempfile.mkdtemp()
#temp_directory = TEMPORARY_DIRECTORY if TEMPORARY_DIRECTORY else tempfile.mkdtemp()
#TODO: generate output file using lightweight hash function on
#file name or file content
#descriptor, temp_filepath = tempfile.mkstemp()
temp_filename, separator = os.path.splitext(os.path.basename(input_filepath))
temp_path = os.path.join(temp_directory, temp_filename)
temp_path = os.path.join(TEMPORARY_DIRECTORY, temp_filename)
output_arg = '%s_%s%s%s' % (temp_path, size, os.extsep, format)
input_arg = '%s[%s]' % (input_filepath, page)
if os.path.exists(output_arg):

3
apps/converter/models.py Normal file
View File

@@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

23
apps/converter/tests.py Normal file
View File

@@ -0,0 +1,23 @@
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)
__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}

1
apps/converter/views.py Normal file
View File

@@ -0,0 +1 @@
# Create your views here.

View File

@@ -12,9 +12,10 @@ from django.forms.formsets import formset_factory
from django.core.files.base import File
from filetransfers.api import serve_file
from converter.api import convert, in_cache
from common.utils import pretty_size
from convert import convert, in_cache
from utils import from_descriptor_to_tempfile, pretty_size
from utils import from_descriptor_to_tempfile
from models import Document, DocumentMetadata, DocumentType, MetadataType
from forms import DocumentTypeSelectForm, DocumentCreateWizard, \

View File

@@ -124,6 +124,7 @@ INSTALLED_APPS = (
'pagination',
'dynamic_search',
'filetransfers',
'converter',
)
TEMPLATE_CONTEXT_PROCESSORS = (