Skip to content
This repository has been archived by the owner on Jan 14, 2019. It is now read-only.

Commit

Permalink
made backend loading mechanism a bit more robust
Browse files Browse the repository at this point in the history
git-svn-id: https://django-rcsfield.googlecode.com/svn/trunk@57 d91cc5cc-1343-0410-b1ed-e1360c4e4ba3
  • Loading branch information
jezdez committed Sep 3, 2008
1 parent c77bf6b commit 3ff6ea3
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions rcsfield/backends/__init__.py
Expand Up @@ -5,27 +5,25 @@

__all__ = ('backend')

if not settings.RCS_BACKEND:
settings.RCS_BACKEND = 'dummy'

RCS_BACKEND = getattr(settings, 'RCS_BACKEND', 'dummy')

try:
# Try to import one of the bundled backends
_import_path = 'rcsfield.backends.'
backend = __import__('%s%s' % (_import_path, settings.RCS_BACKEND), {}, {}, [''])
backend = __import__('%s%s' % (_import_path, RCS_BACKEND), {}, {}, [''])
except ImportError, e:
# If the above import failed try to load an external backend
try:
_import_path = ''
backend = __import__('%s%s' % (_import_path, settings.RCS_BACKEND), {}, {}, [''])
backend = __import__('%s%s' % (_import_path, RCS_BACKEND), {}, {}, [''])
except ImportError, e_user:
# No backend found, display an error message and a list of all
# bundled backends.
backend_dir = __path__[0]
available_backends = [f.split('.py')[0] for f in os.listdir(backend_dir) if not f.startswith('_') and not f.startswith('.') and not f.endswith('.pyc')]
available_backends.sort()
if settings.RCS_BACKEND not in available_backends:
if RCS_BACKEND not in available_backends:
raise ImproperlyConfigured("%s isn't an available revision control (rcsfield) backend. Available options are: %s" % \
(settings.RCS_BACKEND, ', '.join(map(repr, available_backends))))
(RCS_BACKEND, ', '.join(map(repr, available_backends))))
else:
raise

0 comments on commit 3ff6ea3

Please sign in to comment.