Used pkgutil to get list of backend modules

Refs #18827.
This commit is contained in:
Claude Paroz 2012-10-07 21:16:01 +02:00
parent cb9f71dd99
commit 34a736b752
1 changed files with 4 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import os import os
import pkgutil
from threading import local from threading import local
from django.conf import settings from django.conf import settings
@ -28,9 +29,9 @@ def load_backend(backend_name):
# listing all possible (built-in) database backends. # listing all possible (built-in) database backends.
backend_dir = os.path.join(os.path.dirname(__file__), 'backends') backend_dir = os.path.join(os.path.dirname(__file__), 'backends')
try: try:
builtin_backends = [f for f in os.listdir(backend_dir) builtin_backends = [
if os.path.isdir(os.path.join(backend_dir, f)) name for _, name, ispkg in pkgutil.iter_modules([backend_dir])
and not (f.startswith('.') or f in ('__pycache__', 'dummy'))] if ispkg and name != 'dummy']
except EnvironmentError: except EnvironmentError:
builtin_backends = [] builtin_backends = []
if backend_name not in ['django.db.backends.%s' % b for b in if backend_name not in ['django.db.backends.%s' % b for b in