Commits

David Larlet committed 5cac7fc

Use standard Django's exception for imports in all storages.

  • Participants
  • Parent commits 3c2abbd

Comments (0)

Files changed (6)

File backends/couchdb.py

 from django.conf import settings
 from django.core.files import File
 from django.core.files.storage import Storage
+from django.core.exceptions import ImproperlyConfigured
 
 try:
-    import couchdb.client
+    import couchdb
 except ImportError:
-    raise "You must install couchdb dependency. See http://code.google.com/p/couchdb-python/"
+    raise ImproperlyConfigured, "Could not load couchdb dependency.\
+    \nSee http://code.google.com/p/couchdb-python/"
 
 DEFAULT_SERVER= getattr(settings, 'COUCHDB_DEFAULT_SERVER', 'http://couchdb.local:5984')
 STORAGE_OPTIONS= getattr(settings, 'COUCHDB_STORAGE_OPTIONS', {})

File backends/database.py

 # DatabaseStorage for django.
 # 2009 (c) GameKeeper Gambling Ltd, Ivanov E.
-
-
-from django.core.files.storage import Storage
-from django.core.files import File
-from django.conf import settings
-
 import StringIO
 import urlparse
 
-import pyodbc
+from django.conf import settings
+from django.core.files import File
+from django.core.files.storage import Storage
+from django.core.exceptions import ImproperlyConfigured
+
+try:
+    import pyodbc
+except ImportError:
+    raise ImproperlyConfigured, "Could not load pyodbc dependency.\
+    \nSee http://code.google.com/p/pyodbc/"
+
 
 class DatabaseStorage(Storage):
     """

File backends/ftp.py

     from StringIO import StringIO
 
 from django.conf import settings
-from django.core.exceptions import ImproperlyConfigured
 from django.core.files.base import File
 from django.core.files.storage import Storage
+from django.core.exceptions import ImproperlyConfigured
+
 
 class FTPStorageException(Exception): pass
 

File backends/image.py

 
 import os
-from PIL import ImageFile as PILImageFile
+
 from django.core.files.storage import FileSystemStorage
+from django.core.exceptions import ImproperlyConfigured
+
+try:
+    from PIL import ImageFile as PILImageFile
+except ImportError:
+    raise ImproperlyConfigured, "Could not load PIL dependency.\
+    \nSee http://www.pythonware.com/products/pil/"
 
 
 class ImageStorage(FileSystemStorage):

File backends/mogile.py

 import urlparse
+import mimetypes
 from StringIO import StringIO
-import mimetypes
 
+from django.conf import settings
+from django.core.cache import cache
+from django.utils.text import force_unicode
 from django.core.files.storage import Storage
+from django.http import HttpResponse, HttpResponseNotFound
 from django.core.exceptions import ImproperlyConfigured
-from django.conf import settings
-from django.utils.text import force_unicode
-from django.http import HttpResponse, HttpResponseNotFound
-from django.core.cache import cache
 
-import mogilefs
+try:
+    import mogilefs
+except ImportError:
+    raise ImproperlyConfigured, "Could not load mogilefs dependency.\
+    \nSee http://mogilefs.pbworks.com/Client-Libraries"
 
 
 class MogileFSStorage(Storage):

File backends/s3boto.py

 import os
 
 from django.conf import settings
-from django.core.exceptions import ImproperlyConfigured
 from django.core.files.base import File
 from django.core.files.storage import Storage
 from django.utils.functional import curry
+from django.core.exceptions import ImproperlyConfigured
+
+try:
+    from boto.s3.connection import S3Connection
+    from boto.s3.key import Key
+except ImportError:
+    raise ImproperlyConfigured, "Could not load Boto's S3 bindings.\
+    \nSee http://code.google.com/p/boto/"
 
 ACCESS_KEY_NAME = 'AWS_ACCESS_KEY_ID'
 SECRET_KEY_NAME = 'AWS_SECRET_ACCESS_KEY'
 
 AWS_BUCKET_PREFIX = getattr(settings, AWS_BUCKET_NAME, {})
 
-try:
-    from boto.s3.connection import S3Connection
-    from boto.s3.key import Key
-except ImportError:
-    raise ImproperlyConfigured, "Could not load Boto's S3 bindings."
 
 class S3BotoStorage(Storage):
     """Amazon Simple Storage Service using Boto"""
     
-    def __init__(self, bucket="root", bucketprefix=AWS_BUCKET_PREFIX, access_key=None, secret_key=None, acl='public-read'):
+    def __init__(self, bucket="root", bucketprefix=AWS_BUCKET_PREFIX, 
+            access_key=None, secret_key=None, acl='public-read'):
         self.acl = acl
         
         if not access_key and not secret_key:
         """ Overwrite existing file with the same name. """
         return name
 
+
 class S3BotoStorageFile(File):
     def __init__(self, name, mode, storage):
         self._storage = storage
     
     def close(self):
         self.key.close()
-