flake8 cleanups
This commit is contained in:
@@ -2,9 +2,6 @@ import os
|
||||
import subprocess
|
||||
import hashlib
|
||||
|
||||
from django.utils.importlib import import_module
|
||||
from django.template.defaultfilters import slugify
|
||||
|
||||
from common import TEMPORARY_DIRECTORY
|
||||
from documents.utils import document_save_to_temp_dir
|
||||
|
||||
@@ -14,7 +11,7 @@ from converter.conf.settings import UNOCONV_PATH
|
||||
from converter.exceptions import UnpaperError, OfficeConversionError
|
||||
from converter.literals import DEFAULT_PAGE_NUMBER, \
|
||||
DEFAULT_OCR_FILE_FORMAT, QUALITY_DEFAULT, DEFAULT_ZOOM_LEVEL, \
|
||||
DEFAULT_ROTATION, DEFAULT_FILE_FORMAT, QUALITY_PRINT
|
||||
DEFAULT_ROTATION, DEFAULT_FILE_FORMAT, QUALITY_HIGH
|
||||
|
||||
from converter import backend
|
||||
from converter.literals import TRANSFORMATION_CHOICES
|
||||
@@ -119,7 +116,6 @@ def convert(input_filepath, cleanup_files=True, *args, **kwargs):
|
||||
if result:
|
||||
unoconv_output = result
|
||||
input_filepath = result
|
||||
extra_options = u''
|
||||
|
||||
transformations.append(
|
||||
{
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from converter.conf.settings import GM_PATH
|
||||
from converter.conf.settings import GM_SETTINGS
|
||||
from converter.literals import QUALITY_DEFAULT, QUALITY_SETTINGS
|
||||
@@ -32,7 +30,6 @@ class ConverterClass(ConverterBase):
|
||||
raise IdentifyError(proc.stderr.readline())
|
||||
return proc.stdout.read()
|
||||
|
||||
|
||||
def convert_file(self, input_filepath, output_filepath, transformations=None, quality=QUALITY_DEFAULT, page=DEFAULT_PAGE_NUMBER, file_format=DEFAULT_FILE_FORMAT):
|
||||
arguments = []
|
||||
if transformations:
|
||||
@@ -41,29 +38,28 @@ class ConverterClass(ConverterBase):
|
||||
dimensions = []
|
||||
dimensions.append(unicode(transformation['arguments']['width']))
|
||||
if 'height' in transformation['arguments']:
|
||||
dimensions.append(unicode(transformation['arguments']['height']))
|
||||
dimensions.append(unicode(transformation['arguments']['height']))
|
||||
arguments.append(u'-resize')
|
||||
arguments.append(u'%s' % DIMENSION_SEPARATOR.join(dimensions))
|
||||
|
||||
elif transformation['transformation'] == TRANSFORMATION_ZOOM:
|
||||
arguments.append(u'-resize')
|
||||
arguments.append(u'%d%%' % transformation['arguments']['percent'])
|
||||
|
||||
|
||||
elif transformation['transformation'] == TRANSFORMATION_ROTATE:
|
||||
arguments.append(u'-rotate')
|
||||
arguments.append(u'%s' % transformation['arguments']['degrees'])
|
||||
|
||||
|
||||
if format == u'jpg':
|
||||
arguments.append(u'-quality')
|
||||
arguments.append(u'85')
|
||||
|
||||
|
||||
# Graphicsmagick page number is 0 base
|
||||
input_arg = u'%s[%d]' % (input_filepath, page - 1)
|
||||
|
||||
|
||||
# Specify the file format next to the output filename
|
||||
output_filepath = u'%s:%s' % (file_format, output_filepath)
|
||||
|
||||
|
||||
command = []
|
||||
command.append(unicode(GM_PATH))
|
||||
command.append(u'convert')
|
||||
@@ -84,13 +80,12 @@ class ConverterClass(ConverterBase):
|
||||
else:
|
||||
raise ConvertError(error_line)
|
||||
|
||||
|
||||
def get_format_list(self):
|
||||
"""
|
||||
Call GraphicsMagick to parse all of it's supported file formats, and
|
||||
return a list of the names and descriptions
|
||||
"""
|
||||
format_regex = re.compile(' *([A-Z0-9]+)[*]? +([A-Z0-9]+) +([rw\-+]+) *(.*).*')
|
||||
format_regex = re.compile(' *([A-Z0-9]+)[*]? +([A-Z0-9]+) +([rw\-+]+) *(.*).*')
|
||||
formats = []
|
||||
command = []
|
||||
command.append(unicode(GM_PATH))
|
||||
@@ -101,14 +96,13 @@ class ConverterClass(ConverterBase):
|
||||
return_code = proc.wait()
|
||||
if return_code != 0:
|
||||
raise ConvertError(proc.stderr.readline())
|
||||
|
||||
|
||||
for line in proc.stdout.readlines():
|
||||
fields = format_regex.findall(line)
|
||||
if fields:
|
||||
formats.append((fields[0][0], fields[0][3]))
|
||||
|
||||
return formats
|
||||
|
||||
return formats
|
||||
|
||||
def get_available_transformations(self):
|
||||
return [
|
||||
@@ -116,7 +110,6 @@ class ConverterClass(ConverterBase):
|
||||
TRANSFORMATION_DENSITY, TRANSFORMATION_ZOOM
|
||||
]
|
||||
|
||||
|
||||
def get_page_count(self, input_filepath):
|
||||
try:
|
||||
return len(self.identify_file(unicode(input_filepath)).splitlines())
|
||||
|
||||
@@ -6,9 +6,7 @@ from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.template import RequestContext
|
||||
from django.contrib import messages
|
||||
from django.views.generic.list_detail import object_list
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.conf import settings
|
||||
|
||||
from celery.task.control import inspect
|
||||
from permissions.api import check_permissions
|
||||
|
||||
Reference in New Issue
Block a user