12 | | try: |
13 | | # Most of the time, the database backend will be one of the official |
14 | | # backends that ships with Django, so look there first. |
15 | | _import_path = 'django.db.backends.' |
16 | | backend = __import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {}, {}, ['']) |
17 | | except ImportError, e: |
18 | | # If the import failed, we might be looking for a database backend |
19 | | # distributed external to Django. So we'll try that next. |
| 12 | def load_backend(path): |
21 | | _import_path = '' |
22 | | backend = __import__('%s.base' % settings.DATABASE_ENGINE, {}, {}, ['']) |
23 | | except ImportError, e_user: |
24 | | # The database backend wasn't found. Display a helpful error message |
25 | | # listing all possible (built-in) database backends. |
26 | | backend_dir = os.path.join(__path__[0], 'backends') |
| 14 | # Most of the time, the database backend will be one of the official |
| 15 | # backends that ships with Django, so look there first. |
| 16 | _import_path = 'django.db.backends.' |
| 17 | return __import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {}, {}, ['']) |
| 18 | except ImportError, e: |
| 19 | # If the import failed, we might be looking for a database backend |
| 20 | # distributed external to Django. So we'll try that next. |
28 | | available_backends = [f for f in os.listdir(backend_dir) |
29 | | if os.path.isdir(os.path.join(backend_dir, f))] |
30 | | except EnvironmentError: |
31 | | available_backends = [] |
32 | | available_backends.sort() |
33 | | if settings.DATABASE_ENGINE not in available_backends: |
34 | | raise ImproperlyConfigured, "%r isn't an available database backend. Available options are: %s\nError was: %s" % \ |
35 | | (settings.DATABASE_ENGINE, ", ".join(map(repr, available_backends)), e_user) |
36 | | else: |
37 | | raise # If there's some other error, this must be an error in Django itself. |
| 22 | _import_path = '' |
| 23 | return __import__('%s.base' % settings.DATABASE_ENGINE, {}, {}, ['']) |
| 24 | except ImportError, e_user: |
| 25 | # The database backend wasn't found. Display a helpful error message |
| 26 | # listing all possible (built-in) database backends. |
| 27 | backend_dir = os.path.join(__path__[0], 'backends') |
| 28 | try: |
| 29 | available_backends = [f for f in os.listdir(backend_dir) |
| 30 | if os.path.isdir(os.path.join(backend_dir, f))] |
| 31 | except EnvironmentError: |
| 32 | available_backends = [] |
| 33 | available_backends.sort() |
| 34 | if settings.DATABASE_ENGINE not in available_backends: |
| 35 | raise ImproperlyConfigured, "%r isn't an available database backend. Available options are: %s\nError was: %s" % \ |
| 36 | (settings.DATABASE_ENGINE, ", ".join(map(repr, available_backends)), e_user) |
| 37 | else: |
| 38 | raise # If there's some other error, this must be an error in Django itself. |