Update converter app to new settings and icon apps
This commit is contained in:
@@ -7,7 +7,7 @@ from project_tools.api import register_tool
|
||||
|
||||
from .utils import load_backend
|
||||
from .links import formats_list
|
||||
from .conf.settings import GRAPHICS_BACKEND
|
||||
from .settings import GRAPHICS_BACKEND
|
||||
|
||||
register_sidebar_template(['formats_list'], 'converter_file_formats_help.html')
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import logging
|
||||
|
||||
from django.utils.encoding import smart_str
|
||||
|
||||
from common.conf.settings import TEMPORARY_DIRECTORY
|
||||
from common.settings import TEMPORARY_DIRECTORY
|
||||
from common.textparser import TextParser, TEXT_PARSER_MIMETYPES
|
||||
from mimetype.api import get_mimetype
|
||||
|
||||
|
||||
7
apps/converter/icons.py
Normal file
7
apps/converter/icons.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from icons.literals import PICTURES
|
||||
from icons import Icon
|
||||
|
||||
icon_format_list = Icon(PICTURES)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from navigation.api import Link
|
||||
|
||||
from .icons import icon_format_list
|
||||
|
||||
def is_superuser(context):
|
||||
return context['request'].user.is_staff or context['request'].user.is_superuser
|
||||
|
||||
formats_list = Link(text=_('file formats'), view='formats_list', sprite='pictures', icon='pictures.png', condition=is_superuser, children_view_regex=[r'formats_list'])
|
||||
formats_list = Link(text=_('file formats'), view='formats_list', icon=icon_format_list, condition=is_superuser, children_view_regex=[r'formats_list'])
|
||||
|
||||
@@ -5,9 +5,9 @@ import subprocess
|
||||
import logging
|
||||
|
||||
from mimetype.api import get_mimetype
|
||||
from common.conf.settings import TEMPORARY_DIRECTORY
|
||||
from common.settings import TEMPORARY_DIRECTORY
|
||||
|
||||
from .conf.settings import LIBREOFFICE_PATH
|
||||
from .settings import LIBREOFFICE_PATH
|
||||
from .exceptions import OfficeBackendError, UnknownFileFormat
|
||||
|
||||
CACHED_FILE_SUFFIX = u'_office_converter'
|
||||
|
||||
@@ -2,60 +2,54 @@
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from smart_settings.api import Setting, SettingNamespace
|
||||
from smart_settings import SettingsNamespace, LocalScope
|
||||
|
||||
namespace = SettingNamespace('converter', _(u'Converter'), module='converter.conf.settings')
|
||||
namespace = SettingsNamespace('converter', _(u'Converter'), module='converter.settings')
|
||||
|
||||
Setting(
|
||||
namespace=namespace,
|
||||
namespace.add_setting(
|
||||
name='IM_CONVERT_PATH',
|
||||
global_name='CONVERTER_IM_CONVERT_PATH',
|
||||
default=u'/usr/bin/convert',
|
||||
description=_(u'File path to imagemagick\'s convert program.'),
|
||||
exists=True,
|
||||
scopes=[LocalScope]
|
||||
)
|
||||
|
||||
Setting(
|
||||
namespace=namespace,
|
||||
namespace.add_setting(
|
||||
name='IM_IDENTIFY_PATH',
|
||||
global_name='CONVERTER_IM_IDENTIFY_PATH',
|
||||
default=u'/usr/bin/identify',
|
||||
description=_(u'File path to imagemagick\'s identify program.'),
|
||||
exists=True,
|
||||
scopes=[LocalScope]
|
||||
)
|
||||
|
||||
Setting(
|
||||
namespace=namespace,
|
||||
namespace.add_setting(
|
||||
name='GM_PATH',
|
||||
global_name='CONVERTER_GM_PATH',
|
||||
default=u'/usr/bin/gm',
|
||||
description=_(u'File path to graphicsmagick\'s program.'),
|
||||
exists=True,
|
||||
scopes=[LocalScope]
|
||||
)
|
||||
|
||||
Setting(
|
||||
namespace=namespace,
|
||||
namespace.add_setting(
|
||||
name='GM_SETTINGS',
|
||||
global_name='CONVERTER_GM_SETTINGS',
|
||||
default=u'',
|
||||
description=_(u'Set of configuration options to pass to the GraphicsMagick executable to fine tune it\'s functionality as explained in the GraphicsMagick documentation.'),
|
||||
scopes=[LocalScope]
|
||||
)
|
||||
|
||||
Setting(
|
||||
namespace=namespace,
|
||||
namespace.add_setting(
|
||||
name='GRAPHICS_BACKEND',
|
||||
global_name='CONVERTER_GRAPHICS_BACKEND',
|
||||
default=u'converter.backends.python',
|
||||
description=_(u'Graphics conversion backend to use. Options are: converter.backends.imagemagick, converter.backends.graphicsmagick and converter.backends.python.'),
|
||||
scopes=[LocalScope]
|
||||
)
|
||||
|
||||
Setting(
|
||||
namespace=namespace,
|
||||
namespace.add_setting(
|
||||
name='LIBREOFFICE_PATH',
|
||||
global_name='CONVERTER_LIBREOFFICE_PATH',
|
||||
default=u'/usr/bin/libreoffice',
|
||||
description=_(u'Path to the libreoffice program.'),
|
||||
exists=True
|
||||
exists=True,
|
||||
scopes=[LocalScope]
|
||||
)
|
||||
|
||||
#{'name': u'OCR_OPTIONS', 'global_name': u'CONVERTER_OCR_OPTIONS', 'default': u'-colorspace Gray -depth 8 -resample 200x200'},
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.utils.importlib import import_module
|
||||
|
||||
from .settings import GRAPHICS_BACKEND
|
||||
|
||||
|
||||
def _lazy_load(fn):
|
||||
_cached = []
|
||||
@@ -16,10 +20,9 @@ def _lazy_load(fn):
|
||||
|
||||
@_lazy_load
|
||||
def load_backend():
|
||||
from converter.conf.settings import GRAPHICS_BACKEND as backend_name
|
||||
|
||||
try:
|
||||
module = import_module('.base', 'converter.backends.%s' % backend_name)
|
||||
module = import_module('.base', 'converter.backends.%s' % GRAPHICS_BACKEND)
|
||||
import warnings
|
||||
warnings.warn(
|
||||
"Short names for CONVERTER_BACKEND are deprecated; prepend with 'converter.backends.'",
|
||||
@@ -29,7 +32,7 @@ def load_backend():
|
||||
except ImportError, e:
|
||||
# Look for a fully qualified converter backend name
|
||||
try:
|
||||
return import_module('.base', backend_name)
|
||||
return import_module('.base', GRAPHICS_BACKEND)
|
||||
except ImportError, e_user:
|
||||
# The converter backend wasn't found. Display a helpful error message
|
||||
# listing all possible (built-in) converter backends.
|
||||
@@ -41,11 +44,11 @@ def load_backend():
|
||||
except EnvironmentError:
|
||||
available_backends = []
|
||||
available_backends.sort()
|
||||
if backend_name not in available_backends:
|
||||
if GRAPHICS_BACKEND not in available_backends:
|
||||
error_msg = ("%r isn't an available converter backend. \n" +
|
||||
"Try using converter.backends.XXX, where XXX is one of:\n %s\n" +
|
||||
"Error was: %s") % \
|
||||
(backend_name, ", ".join(map(repr, available_backends)), e_user)
|
||||
(GRAPHICS_BACKEND, ", ".join(map(repr, available_backends)), e_user)
|
||||
raise ImproperlyConfigured(error_msg)
|
||||
else:
|
||||
# If there's some other error, this must be an error in Mayan itself.
|
||||
|
||||
@@ -8,7 +8,7 @@ from django.core.exceptions import PermissionDenied
|
||||
from common.utils import encapsulate
|
||||
|
||||
from .api import get_format_list
|
||||
from .conf.settings import GRAPHICS_BACKEND
|
||||
from .settings import GRAPHICS_BACKEND
|
||||
|
||||
|
||||
def formats_list(request):
|
||||
|
||||
Reference in New Issue
Block a user