Commit e4219b6e authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents 3f5b29de 44b1d129
......@@ -19,24 +19,10 @@
#
from weblate import appsettings
from django.core.exceptions import ImproperlyConfigured
from trans.util import load_class
# Initialize checks list
CHECKS = {}
for path in appsettings.CHECK_LIST:
module, attr = path.rsplit('.', 1)
try:
mod = __import__(module, {}, {}, [attr])
except ImportError as e:
raise ImproperlyConfigured(
'Error importing translation check module %s: "%s"' %
(module, e)
)
try:
cls = getattr(mod, attr)
except AttributeError:
raise ImproperlyConfigured(
'Module "%s" does not define a "%s" callable check' %
(module, attr)
)
cls = load_class(path)
CHECKS[cls.check_id] = cls()
......@@ -19,24 +19,10 @@
#
from weblate import appsettings
from django.core.exceptions import ImproperlyConfigured
from trans.util import load_class
# Initialize checks list
SERVICES = {}
for path in appsettings.MACHINE_TRANSLATION_SERVICES:
module, attr = path.rsplit('.', 1)
try:
mod = __import__(module, {}, {}, [attr])
except ImportError as e:
raise ImproperlyConfigured(
'Error importing machine translation module %s: "%s"' %
(module, e)
)
try:
cls = getattr(mod, attr)
except AttributeError:
raise ImproperlyConfigured(
'Module "%s" does not define a "%s" class' %
(module, attr)
)
cls = load_class(path)
SERVICES[cls.mtid] = cls()
......@@ -19,11 +19,13 @@
#
import hashlib
from django.core.exceptions import ImproperlyConfigured
from django.contrib.sites.models import Site
from django.utils.translation import ugettext as _
from django.utils.html import escape
from django.utils.safestring import mark_safe
from django.conf import settings
from importlib import import_module
import urllib
import time
import random
......@@ -174,3 +176,25 @@ def sleep_while_git_locked():
Random sleep to perform when git repository is locked.
'''
time.sleep(random.random() * 2)
def load_class(name):
'''
Imports module and creates class given by name in string.
'''
module, attr = name.rsplit('.', 1)
try:
mod = import_module(module)
except ImportError as e:
raise ImproperlyConfigured(
'Error importing module %s: "%s"' %
(module, e)
)
try:
cls = getattr(mod, attr)
except AttributeError:
raise ImproperlyConfigured(
'Module "%s" does not define a "%s" class' %
(module, attr)
)
return cls
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment