PEP8 and Pylint cleanups
This commit is contained in:
@@ -2,9 +2,8 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from django.utils.importlib import import_module
|
from django.utils.importlib import import_module
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
|
||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify
|
||||||
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
|
||||||
from converter.conf.settings import UNPAPER_PATH
|
from converter.conf.settings import UNPAPER_PATH
|
||||||
from converter.conf.settings import OCR_OPTIONS
|
from converter.conf.settings import OCR_OPTIONS
|
||||||
@@ -24,17 +23,20 @@ QUALITY_DEFAULT = 'quality_default'
|
|||||||
QUALITY_LOW = 'quality_low'
|
QUALITY_LOW = 'quality_low'
|
||||||
QUALITY_HIGH = 'quality_high'
|
QUALITY_HIGH = 'quality_high'
|
||||||
|
|
||||||
QUALITY_SETTINGS = {QUALITY_DEFAULT:DEFAULT_OPTIONS, QUALITY_LOW:LOW_QUALITY_OPTIONS,
|
QUALITY_SETTINGS = {QUALITY_DEFAULT: DEFAULT_OPTIONS,
|
||||||
QUALITY_HIGH:HIGH_QUALITY_OPTIONS}
|
QUALITY_LOW: LOW_QUALITY_OPTIONS, QUALITY_HIGH: HIGH_QUALITY_OPTIONS}
|
||||||
|
|
||||||
|
|
||||||
def _lazy_load(fn):
|
def _lazy_load(fn):
|
||||||
_cached = []
|
_cached = []
|
||||||
|
|
||||||
def _decorated():
|
def _decorated():
|
||||||
if not _cached:
|
if not _cached:
|
||||||
_cached.append(fn())
|
_cached.append(fn())
|
||||||
return _cached[0]
|
return _cached[0]
|
||||||
return _decorated
|
return _decorated
|
||||||
|
|
||||||
|
|
||||||
@_lazy_load
|
@_lazy_load
|
||||||
def _get_backend():
|
def _get_backend():
|
||||||
return import_module(GRAPHICS_BACKEND)
|
return import_module(GRAPHICS_BACKEND)
|
||||||
@@ -44,6 +46,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError('Missing or incorrect converter backend: %s' % GRAPHICS_BACKEND)
|
raise ImportError('Missing or incorrect converter backend: %s' % GRAPHICS_BACKEND)
|
||||||
|
|
||||||
|
|
||||||
def cleanup(filename):
|
def cleanup(filename):
|
||||||
''' tries to remove the given filename. Ignores non-existent files '''
|
''' tries to remove the given filename. Ignores non-existent files '''
|
||||||
try:
|
try:
|
||||||
@@ -51,6 +54,7 @@ def cleanup(filename):
|
|||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def execute_unpaper(input_filepath, output_filepath):
|
def execute_unpaper(input_filepath, output_filepath):
|
||||||
command = []
|
command = []
|
||||||
command.append(UNPAPER_PATH)
|
command.append(UNPAPER_PATH)
|
||||||
@@ -97,6 +101,7 @@ def create_image_cache_filename(input_filepath, *args, **kwargs):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def in_image_cache(input_filepath, size, page=0, format='jpg', quality=QUALITY_DEFAULT, extra_options=''):
|
def in_image_cache(input_filepath, size, page=0, format='jpg', quality=QUALITY_DEFAULT, extra_options=''):
|
||||||
output_filepath = create_image_cache_filename(input_filepath, size=size, page=page, format=format, quality=quality, extra_options=extra_options)
|
output_filepath = create_image_cache_filename(input_filepath, size=size, page=page, format=format, quality=quality, extra_options=extra_options)
|
||||||
if os.path.exists(output_filepath):
|
if os.path.exists(output_filepath):
|
||||||
@@ -104,6 +109,7 @@ def in_image_cache(input_filepath, size, page=0, format='jpg', quality=QUALITY_D
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def convert(input_filepath, size, quality=QUALITY_DEFAULT, cache=True, page=0, format='jpg', extra_options='', mimetype=None, extension=None, cleanup_files=True):
|
def convert(input_filepath, size, quality=QUALITY_DEFAULT, cache=True, page=0, format='jpg', extra_options='', mimetype=None, extension=None, cleanup_files=True):
|
||||||
unoconv_output = None
|
unoconv_output = None
|
||||||
output_filepath = create_image_cache_filename(input_filepath, size=size, page=page, format=format, quality=quality, extra_options=extra_options)
|
output_filepath = create_image_cache_filename(input_filepath, size=size, page=page, format=format, quality=quality, extra_options=extra_options)
|
||||||
@@ -132,6 +138,7 @@ def convert(input_filepath, size, quality=QUALITY_DEFAULT, cache=True, page=0, f
|
|||||||
|
|
||||||
return output_filepath
|
return output_filepath
|
||||||
|
|
||||||
|
|
||||||
def get_page_count(input_filepath):
|
def get_page_count(input_filepath):
|
||||||
try:
|
try:
|
||||||
return int(backend.execute_identify(input_filepath, '-format %n'))
|
return int(backend.execute_identify(input_filepath, '-format %n'))
|
||||||
@@ -139,6 +146,7 @@ def get_page_count(input_filepath):
|
|||||||
#TODO: send to other page number identifying program
|
#TODO: send to other page number identifying program
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def convert_document_for_ocr(document, page=0, format='tif'):
|
def convert_document_for_ocr(document, page=0, format='tif'):
|
||||||
#Extract document file
|
#Extract document file
|
||||||
input_filepath = document_save_to_temp_dir(document, document.uuid)
|
input_filepath = document_save_to_temp_dir(document, document.uuid)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from converter.exceptions import ConvertError, UnknownFormat, IdentifyError
|
|||||||
|
|
||||||
CONVERTER_ERROR_STRING_NO_DECODER = 'No decode delegate for this image format'
|
CONVERTER_ERROR_STRING_NO_DECODER = 'No decode delegate for this image format'
|
||||||
|
|
||||||
|
|
||||||
def execute_identify(input_filepath, arguments):
|
def execute_identify(input_filepath, arguments):
|
||||||
command = []
|
command = []
|
||||||
command.append(GM_PATH)
|
command.append(GM_PATH)
|
||||||
@@ -20,6 +21,7 @@ def execute_identify(input_filepath, arguments):
|
|||||||
raise IdentifyError(proc.stderr.readline())
|
raise IdentifyError(proc.stderr.readline())
|
||||||
return proc.stdout.read()
|
return proc.stdout.read()
|
||||||
|
|
||||||
|
|
||||||
def execute_convert(input_filepath, output_filepath, quality=QUALITY_DEFAULT, arguments=None):
|
def execute_convert(input_filepath, output_filepath, quality=QUALITY_DEFAULT, arguments=None):
|
||||||
command = []
|
command = []
|
||||||
command.append(GM_PATH)
|
command.append(GM_PATH)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from converter.exceptions import ConvertError, UnknownFormat, \
|
|||||||
|
|
||||||
CONVERTER_ERROR_STRING_NO_DECODER = 'no decode delegate for this image format'
|
CONVERTER_ERROR_STRING_NO_DECODER = 'no decode delegate for this image format'
|
||||||
|
|
||||||
|
|
||||||
def execute_identify(input_filepath, arguments):
|
def execute_identify(input_filepath, arguments):
|
||||||
command = []
|
command = []
|
||||||
command.append(IM_IDENTIFY_PATH)
|
command.append(IM_IDENTIFY_PATH)
|
||||||
@@ -21,6 +22,7 @@ def execute_identify(input_filepath, arguments):
|
|||||||
raise IdentifyError(proc.stderr.readline())
|
raise IdentifyError(proc.stderr.readline())
|
||||||
return proc.stdout.read()
|
return proc.stdout.read()
|
||||||
|
|
||||||
|
|
||||||
def execute_convert(input_filepath, output_filepath, quality=QUALITY_DEFAULT, arguments=None):
|
def execute_convert(input_filepath, output_filepath, quality=QUALITY_DEFAULT, arguments=None):
|
||||||
command = []
|
command = []
|
||||||
command.append(IM_CONVERT_PATH)
|
command.append(IM_CONVERT_PATH)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#http://stackoverflow.com/questions/123198/how-do-i-copy-a-file-in-python
|
#http://stackoverflow.com/questions/123198/how-do-i-copy-a-file-in-python
|
||||||
|
|
||||||
|
|
||||||
def copyfile(source, dest, buffer_size=1024 * 1024):
|
def copyfile(source, dest, buffer_size=1024 * 1024):
|
||||||
"""
|
"""
|
||||||
Copy a file from source to dest. source and dest
|
Copy a file from source to dest. source and dest
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ def document_create_fs_links(document):
|
|||||||
else:
|
else:
|
||||||
raise OSError(_(u'Unable to create metadata indexing directory: %s') % exc)
|
raise OSError(_(u'Unable to create metadata indexing directory: %s') % exc)
|
||||||
|
|
||||||
|
|
||||||
next_available_filename(document, metadata_index, target_directory, slugify(document.file_filename), slugify(document.file_extension))
|
next_available_filename(document, metadata_index, target_directory, slugify(document.file_filename), slugify(document.file_extension))
|
||||||
except NameError, exc:
|
except NameError, exc:
|
||||||
warnings.append(_(u'Error in metadata indexing expression: %s') % exc)
|
warnings.append(_(u'Error in metadata indexing expression: %s') % exc)
|
||||||
@@ -50,6 +49,7 @@ def document_create_fs_links(document):
|
|||||||
|
|
||||||
return warnings
|
return warnings
|
||||||
|
|
||||||
|
|
||||||
def document_delete_fs_links(document):
|
def document_delete_fs_links(document):
|
||||||
if FILESERVING_ENABLE:
|
if FILESERVING_ENABLE:
|
||||||
for document_metadata_index in document.documentmetadataindex_set.all():
|
for document_metadata_index in document.documentmetadataindex_set.all():
|
||||||
@@ -88,7 +88,6 @@ def document_delete_fs_links(document):
|
|||||||
except OSError, exc:
|
except OSError, exc:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
#Remove the directory if it is empty
|
#Remove the directory if it is empty
|
||||||
try:
|
try:
|
||||||
os.removedirs(path)
|
os.removedirs(path)
|
||||||
@@ -118,7 +117,6 @@ def next_available_filename(document, metadata_index, path, filename, extension,
|
|||||||
return next_available_filename(document, metadata_index, path, filename, extension, suffix)
|
return next_available_filename(document, metadata_index, path, filename, extension, suffix)
|
||||||
except Exception, exc:
|
except Exception, exc:
|
||||||
raise Exception(_(u'Unable to create symbolic link, filename clash: %(filepath)s; %(exc)s') % {'filepath': filepath, 'exc': exc})
|
raise Exception(_(u'Unable to create symbolic link, filename clash: %(filepath)s; %(exc)s') % {'filepath': filepath, 'exc': exc})
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise OSError(_(u'Unable to create symbolic link: %(filepath)s; %(exc)s') % {'filepath': filepath, 'exc': exc})
|
raise OSError(_(u'Unable to create symbolic link: %(filepath)s; %(exc)s') % {'filepath': filepath, 'exc': exc})
|
||||||
|
|
||||||
@@ -155,5 +153,5 @@ def do_recreate_all_links(raise_exception=True):
|
|||||||
errors.append('%s: %s' % (document, e))
|
errors.append('%s: %s' % (document, e))
|
||||||
|
|
||||||
for warning in create_warnings:
|
for warning in create_warnings:
|
||||||
warnings.append('%s: %s' % (document, e))
|
warnings.append('%s: %s' % (document, warning))
|
||||||
return errors, warnings
|
return errors, warnings
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
'''Configuration options for the filesystem_serving app
|
||||||
|
'''
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from common.utils import proper_name
|
from common.utils import proper_name
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
from django.template.defaultfilters import capfirst
|
||||||
|
|
||||||
|
|
||||||
class MultiItemForm(forms.Form):
|
class MultiItemForm(forms.Form):
|
||||||
|
|||||||
@@ -34,15 +34,13 @@ def process_links(links, view_name, url):
|
|||||||
active = True
|
active = True
|
||||||
active_item = item
|
active_item = item
|
||||||
|
|
||||||
items.append(
|
items.append({
|
||||||
{
|
|
||||||
'first': count == 0,
|
'first': count == 0,
|
||||||
'active': active,
|
'active': active,
|
||||||
'url': item_view and reverse(item_view) or item_url or '#',
|
'url': item_view and reverse(item_view) or item_url or '#',
|
||||||
'text': unicode(item['text']),
|
'text': unicode(item['text']),
|
||||||
'famfam': 'famfam' in item and item['famfam'],
|
'famfam': 'famfam' in item and item['famfam'],
|
||||||
}
|
})
|
||||||
)
|
|
||||||
return items, active_item
|
return items, active_item
|
||||||
|
|
||||||
|
|
||||||
@@ -76,6 +74,7 @@ def main_navigation(parser, token):
|
|||||||
#http://www.djangosnippets.org/snippets/1378/
|
#http://www.djangosnippets.org/snippets/1378/
|
||||||
__all__ = ('resolve_to_name',)
|
__all__ = ('resolve_to_name',)
|
||||||
|
|
||||||
|
|
||||||
def _pattern_resolve_to_name(self, path):
|
def _pattern_resolve_to_name(self, path):
|
||||||
match = self.regex.search(path)
|
match = self.regex.search(path)
|
||||||
if match:
|
if match:
|
||||||
@@ -88,6 +87,7 @@ def _pattern_resolve_to_name(self, path):
|
|||||||
name = "%s.%s" % (self.callback.__module__, self.callback.func_name)
|
name = "%s.%s" % (self.callback.__module__, self.callback.func_name)
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
|
||||||
def _resolver_resolve_to_name(self, path):
|
def _resolver_resolve_to_name(self, path):
|
||||||
tried = []
|
tried = []
|
||||||
match = self.regex.search(path)
|
match = self.regex.search(path)
|
||||||
@@ -109,13 +109,16 @@ def _resolver_resolve_to_name(self, path):
|
|||||||
RegexURLPattern.resolve_to_name = _pattern_resolve_to_name
|
RegexURLPattern.resolve_to_name = _pattern_resolve_to_name
|
||||||
RegexURLResolver.resolve_to_name = _resolver_resolve_to_name
|
RegexURLResolver.resolve_to_name = _resolver_resolve_to_name
|
||||||
|
|
||||||
|
|
||||||
def resolve_to_name(path, urlconf=None):
|
def resolve_to_name(path, urlconf=None):
|
||||||
return get_resolver(urlconf).resolve_to_name(path)
|
return get_resolver(urlconf).resolve_to_name(path)
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def resolve_url_name(value):
|
def resolve_url_name(value):
|
||||||
return resolve_to_name(value)
|
return resolve_to_name(value)
|
||||||
|
|
||||||
|
|
||||||
def resolve_arguments(context, src_args):
|
def resolve_arguments(context, src_args):
|
||||||
args = []
|
args = []
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
@@ -172,7 +175,7 @@ def resolve_links(context, links, current_view, current_path):
|
|||||||
|
|
||||||
def _get_object_navigation_links(context, menu_name=None, links_dict=object_navigation):
|
def _get_object_navigation_links(context, menu_name=None, links_dict=object_navigation):
|
||||||
current_path = Variable('request').resolve(context).META['PATH_INFO']
|
current_path = Variable('request').resolve(context).META['PATH_INFO']
|
||||||
current_view = resolve_to_name(current_path)#.get_full_path())
|
current_view = resolve_to_name(current_path)
|
||||||
context_links = []
|
context_links = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from permissions import PERMISSION_ROLE_VIEW, PERMISSION_ROLE_EDIT, \
|
|||||||
|
|
||||||
from models import Permission, Role
|
from models import Permission, Role
|
||||||
|
|
||||||
|
|
||||||
def register_permissions(namespace, permissions):
|
def register_permissions(namespace, permissions):
|
||||||
if permissions:
|
if permissions:
|
||||||
for permission in permissions:
|
for permission in permissions:
|
||||||
@@ -25,6 +26,7 @@ def register_permissions(namespace, permissions):
|
|||||||
#Special case for ./manage.py syncdb
|
#Special case for ./manage.py syncdb
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
#TODO: Handle anonymous users
|
#TODO: Handle anonymous users
|
||||||
def check_permissions(requester, namespace, permission_list):
|
def check_permissions(requester, namespace, permission_list):
|
||||||
if isinstance(requester, User):
|
if isinstance(requester, User):
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ from django.core.files.storage import FileSystemStorage
|
|||||||
|
|
||||||
from storage.conf.settings import FILESTORAGE_LOCATION
|
from storage.conf.settings import FILESTORAGE_LOCATION
|
||||||
|
|
||||||
|
|
||||||
class FileBasedStorage(FileSystemStorage):
|
class FileBasedStorage(FileSystemStorage):
|
||||||
|
'''Simple wrapper for the stock Django FileSystemStorage class
|
||||||
|
'''
|
||||||
separator = os.path.sep
|
separator = os.path.sep
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(FileBasedStorage, self).__init__(*args, **kwargs)
|
super(FileBasedStorage, self).__init__(*args, **kwargs)
|
||||||
self.location = FILESTORAGE_LOCATION
|
self.location = FILESTORAGE_LOCATION
|
||||||
|
|
||||||
|
|||||||
@@ -20,4 +20,3 @@ os.environ['CELERY_LOADER'] = 'django'
|
|||||||
|
|
||||||
from django.core.handlers.wsgi import WSGIHandler
|
from django.core.handlers.wsgi import WSGIHandler
|
||||||
application = WSGIHandler()
|
application = WSGIHandler()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user