Simplify converter backend and return exceptions for better diagnostics.

This commit is contained in:
Roberto Rosario
2012-10-08 18:47:46 -04:00
parent e9817ee1ac
commit 82299a49c4

View File

@@ -28,28 +28,7 @@ def load_backend():
return module
except ImportError, e:
# Look for a fully qualified converter backend name
try:
return import_module('.base', backend_name)
except ImportError, e_user:
# The converter backend wasn't found. Display a helpful error message
# listing all possible (built-in) converter backends.
backend_dir = os.path.join(os.path.dirname(__file__), 'backends')
try:
available_backends = [f for f in os.listdir(backend_dir)
if os.path.isdir(os.path.join(backend_dir, f))
and not f.startswith('.')]
except EnvironmentError:
available_backends = []
available_backends.sort()
if backend_name 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)
raise ImproperlyConfigured(error_msg)
else:
# If there's some other error, this must be an error in Mayan itself.
raise
return import_module('.base', backend_name)
def cleanup(filename):