Added random named pipe support to the OfficeConverter pipe method

This commit is contained in:
Roberto Rosario
2011-11-22 01:22:59 -04:00
parent a6a00cbc15
commit f8dbfc068a
2 changed files with 10 additions and 2 deletions

View File

@@ -3,6 +3,8 @@ import os
import re import re
import types import types
import tempfile import tempfile
import string
import random
from django.utils.http import urlquote as django_urlquote from django.utils.http import urlquote as django_urlquote
from django.utils.http import urlencode as django_urlencode from django.utils.http import urlencode as django_urlencode
@@ -358,8 +360,13 @@ def validate_path(path):
return True return True
def encapsulate(function): def encapsulate(function):
# Workaround Django ticket 15791 # Workaround Django ticket 15791
# Changeset 16045 # Changeset 16045
# http://stackoverflow.com/questions/6861601/cannot-resolve-callable-context-variable/6955045#6955045 # http://stackoverflow.com/questions/6861601/cannot-resolve-callable-context-variable/6955045#6955045
return lambda: function return lambda: function
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for x in range(size))

View File

@@ -3,6 +3,7 @@ import subprocess
from mimetype.api import get_mimetype from mimetype.api import get_mimetype
from common.conf.settings import TEMPORARY_DIRECTORY from common.conf.settings import TEMPORARY_DIRECTORY
from common.utils import id_generator
from converter.conf.settings import UNOCONV_PATH, UNOCONV_USE_PIPE from converter.conf.settings import UNOCONV_PATH, UNOCONV_USE_PIPE
from converter.exceptions import (OfficeConversionError, from converter.exceptions import (OfficeConversionError,
@@ -89,12 +90,12 @@ class OfficeConverterBackendUnoconv(object):
if UNOCONV_USE_PIPE: if UNOCONV_USE_PIPE:
command.append(u'--pipe') command.append(u'--pipe')
command.append(u'mayan') command.append(u'mayan-%s' % id_generator())
command.append(u'--format=pdf') command.append(u'--format=pdf')
command.append(u'--output=%s' % self.output_filepath) command.append(u'--output=%s' % self.output_filepath)
command.append(self.input_filepath) command.append(self.input_filepath)
try: try:
proc = subprocess.Popen(command, close_fds=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE) proc = subprocess.Popen(command, close_fds=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
return_code = proc.wait() return_code = proc.wait()