Replace custom 'load_backend' with Django's 'import_string'.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from common.utils import load_backend
|
||||
from django.utils.module_loading import import_string
|
||||
|
||||
from .settings import SHARED_STORAGE
|
||||
|
||||
shared_storage_backend = load_backend(SHARED_STORAGE)()
|
||||
shared_storage_backend = import_string(SHARED_STORAGE)()
|
||||
|
||||
@@ -209,17 +209,6 @@ def copyfile(source, destination, buffer_size=1024 * 1024):
|
||||
destination_descriptor.close()
|
||||
|
||||
|
||||
def load_backend(backend_string):
|
||||
logger.debug('loading: %s', backend_string)
|
||||
module_name, klass = backend_string.rsplit('.', 1)
|
||||
|
||||
try:
|
||||
return getattr(import_module(module_name), klass)
|
||||
except ImportError as exception:
|
||||
logger.debug('error importing: %s; %s', backend_string, exception)
|
||||
raise
|
||||
|
||||
|
||||
def fs_cleanup(filename, suppress_exceptions=True):
|
||||
"""
|
||||
Tries to remove the given filename. Ignores non-existent files
|
||||
|
||||
@@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
from common.utils import load_backend
|
||||
from django.utils.module_loading import import_string
|
||||
|
||||
from .exceptions import OfficeBackendError
|
||||
from .office_converter import OfficeConverter
|
||||
@@ -20,4 +20,4 @@ else:
|
||||
logger.debug('office_backend initialized')
|
||||
|
||||
|
||||
backend = load_backend(GRAPHICS_BACKEND)()
|
||||
backend = import_string(GRAPHICS_BACKEND)()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from common.utils import load_backend
|
||||
from django.utils.module_loading import import_string
|
||||
|
||||
from .settings import STORAGE_BACKEND
|
||||
|
||||
storage_backend = load_backend(STORAGE_BACKEND)()
|
||||
storage_backend = import_string(STORAGE_BACKEND)()
|
||||
|
||||
@@ -7,9 +7,9 @@ import re
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db.models import Q
|
||||
from django.db.models.loading import get_model
|
||||
from django.utils.module_loading import import_string
|
||||
|
||||
from acls.models import AccessEntry
|
||||
from common.utils import load_backend
|
||||
from permissions.models import Permission
|
||||
|
||||
from .settings import LIMIT
|
||||
@@ -24,7 +24,7 @@ class SearchModel(object):
|
||||
def get(cls, full_name):
|
||||
result = cls.registry[full_name]
|
||||
if not hasattr(result, 'serializer'):
|
||||
result.serializer = load_backend(result.serializer_string)
|
||||
result.serializer = import_string(result.serializer_string)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -6,10 +6,11 @@ import tempfile
|
||||
|
||||
import sh
|
||||
|
||||
from django.utils.module_loading import import_string
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common.settings import TEMPORARY_DIRECTORY
|
||||
from common.utils import fs_cleanup, load_backend
|
||||
from common.utils import fs_cleanup
|
||||
from converter.api import convert
|
||||
from documents.models import DocumentPage
|
||||
|
||||
@@ -87,7 +88,7 @@ def ocr_cleanup(language, text):
|
||||
cleanup filter
|
||||
"""
|
||||
try:
|
||||
language_backend = load_backend('.'.join(['ocr', 'lang', language, 'LanguageBackend']))()
|
||||
language_backend = import_string('.'.join(['ocr', 'lang', language, 'LanguageBackend']))()
|
||||
except ImportError:
|
||||
language_backend = None
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from common.utils import load_backend
|
||||
from django.utils.module_loading import import_string
|
||||
|
||||
from .settings import BACKEND
|
||||
|
||||
ocr_backend = load_backend(BACKEND)()
|
||||
ocr_backend = import_string(BACKEND)()
|
||||
|
||||
@@ -2,8 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.conf.urls import include, patterns, url
|
||||
from django.conf import settings
|
||||
|
||||
from common.utils import load_backend
|
||||
from django.utils.module_loading import import_string
|
||||
|
||||
|
||||
class APIEndPoint(object):
|
||||
@@ -24,7 +23,7 @@ class APIEndPoint(object):
|
||||
self.name = name
|
||||
self.endpoints = []
|
||||
try:
|
||||
api_urls = load_backend('{0}.urls.api_urls'.format(app_name or name))
|
||||
api_urls = import_string('{0}.urls.api_urls'.format(app_name or name))
|
||||
except Exception:
|
||||
if settings.DEBUG:
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user