summary refs log tree commit diff stats
path: root/examples/plugin_pmount.py
diff options
context:
space:
mode:
authornfnty <git@nfnty.se>2017-01-20 12:07:53 +0100
committernfnty <git@nfnty.se>2017-01-20 12:07:53 +0100
commit1c90e610de6591e8052a1056c775219b5e767002 (patch)
tree69b56f67dee1d6dfcea869de897846baaded3fa6 /examples/plugin_pmount.py
parente26d163debc9f55a89a27f94a43771526d2ff0b7 (diff)
parent03ee065e35c6a8f0e0dc1e66d8f4c3e83c51f315 (diff)
downloadranger-1c90e610de6591e8052a1056c775219b5e767002.tar.gz
Merge branch 'lint'
Diffstat (limited to 'examples/plugin_pmount.py')
-rw-r--r--examples/plugin_pmount.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/examples/plugin_pmount.py b/examples/plugin_pmount.py
index ba61b0e5..5db85385 100644
--- a/examples/plugin_pmount.py
+++ b/examples/plugin_pmount.py
@@ -9,24 +9,37 @@
 # alt+shift+m <uppercase letter>         : unmount /dev/sd<letter>
 # alt+shift+n                            : list the devices
 
+from __future__ import (absolute_import, print_function)
+
 import ranger.api
 
 MOUNT_KEY = '<alt>m'
 UMOUNT_KEY = '<alt>M'
 LIST_MOUNTS_KEY = '<alt>N'
 
-old_hook_init = ranger.api.hook_init
+
+HOOK_INIT_OLD = ranger.api.hook_init
 
 
 def hook_init(fm):
     try:
         fm.execute_console("map {key} shell -p lsblk".format(key=LIST_MOUNTS_KEY))
         for disk in "abcdefgh":
-            fm.execute_console("map {key}{0} chain shell pmount sd{1}; cd /media/sd{1}".format(disk.upper(), disk, key=MOUNT_KEY))
-            fm.execute_console("map {key}{0} chain cd; chain shell pumount sd{1}".format(disk.upper(), disk, key=UMOUNT_KEY))
+            fm.execute_console("map {key}{0} chain shell pmount sd{1}; cd /media/sd{1}".format(
+                disk.upper(), disk, key=MOUNT_KEY))
+            fm.execute_console("map {key}{0} chain cd; chain shell pumount sd{1}".format(
+                disk.upper(), disk, key=UMOUNT_KEY))
             for part in "123456789":
-                fm.execute_console("map {key}{0}{1} chain shell pmount sd{0}{1}; cd /media/sd{0}{1}".format(disk, part, key=MOUNT_KEY))
-                fm.execute_console("map {key}{0}{1} chain cd; shell pumount sd{0}{1}".format(disk, part, key=UMOUNT_KEY))
-    finally:
-        return old_hook_init(fm)
+                fm.execute_console(
+                    "map {key}{0}{1} chain shell pmount sd{0}{1}; cd /media/sd{0}{1}".format(
+                        disk, part, key=MOUNT_KEY)
+                )
+                fm.execute_console("map {key}{0}{1} chain cd; shell pumount sd{0}{1}".format(
+                    disk, part, key=UMOUNT_KEY))
+    except Exception:
+        pass
+
+    return HOOK_INIT_OLD(fm)
+
+
 ranger.api.hook_init = hook_init