summaryrefslogtreecommitdiff
path: root/glanceclient/openstack/common/importutils.py
diff options
context:
space:
mode:
Diffstat (limited to 'glanceclient/openstack/common/importutils.py')
-rw-r--r--glanceclient/openstack/common/importutils.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/glanceclient/openstack/common/importutils.py b/glanceclient/openstack/common/importutils.py
index f45372b..9dec764 100644
--- a/glanceclient/openstack/common/importutils.py
+++ b/glanceclient/openstack/common/importutils.py
@@ -29,7 +29,7 @@ def import_class(import_str):
try:
__import__(mod_str)
return getattr(sys.modules[mod_str], class_str)
- except (ValueError, AttributeError), exc:
+ except (ValueError, AttributeError):
raise ImportError('Class %s cannot be found (%s)' %
(class_str,
traceback.format_exception(*sys.exc_info())))
@@ -57,3 +57,11 @@ def import_module(import_str):
"""Import a module."""
__import__(import_str)
return sys.modules[import_str]
+
+
+def try_import(import_str, default=None):
+ """Try to import a module and if it fails return default."""
+ try:
+ return import_module(import_str)
+ except ImportError:
+ return default