summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2016-07-04 21:45:50 +0200
committerhut <hut@lepus.uberspace.de>2016-07-04 21:46:45 +0200
commita60b15b75e0d78504903bebfc45af404acfecd93 (patch)
treee88a36aee880f70ef1fbc912077688c84f7dabc1
parentf2c18a523e054308aca795b00030bfdf4de5985b (diff)
downloadranger-a60b15b75e0d78504903bebfc45af404acfecd93.tar.gz
use importlib on py2.7+ to fix loading commands from plugins
-rw-r--r--ranger/core/main.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/ranger/core/main.py b/ranger/core/main.py
index 000ded68..118a7480 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -303,8 +303,16 @@ def load_settings(fm, clean):
             ranger.fm = fm
             for plugin in sorted(plugins):
                 try:
-                    module = __import__('plugins', fromlist=[plugin])
-                    fm.commands.load_commands_from_module(module)
+                    try:
+                        # importlib does not exist before python2.7.  It's
+                        # required for loading commands from plugins, so you
+                        # can't use that feature in python2.6.
+                        import importlib
+                    except ImportError:
+                        module = __import__('plugins', fromlist=[plugin])
+                    else:
+                        module = importlib.import_module('plugins.' + plugin)
+                        fm.commands.load_commands_from_module(module)
                     fm.log.append("Loaded plugin '%s'." % plugin)
                 except Exception as e:
                     fm.log.append("Error in plugin '%s'" % plugin)