summary refs log tree commit diff stats
path: root/examples
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
parente26d163debc9f55a89a27f94a43771526d2ff0b7 (diff)
parent03ee065e35c6a8f0e0dc1e66d8f4c3e83c51f315 (diff)
downloadranger-1c90e610de6591e8052a1056c775219b5e767002.tar.gz
Merge branch 'lint'
Diffstat (limited to 'examples')
-rw-r--r--examples/plugin_chmod_keybindings.py9
-rw-r--r--examples/plugin_file_filter.py19
-rw-r--r--examples/plugin_hello_world.py7
-rw-r--r--examples/plugin_ipc.py17
-rw-r--r--examples/plugin_linemode.py10
-rw-r--r--examples/plugin_new_macro.py16
-rw-r--r--examples/plugin_new_sorting_method.py6
-rw-r--r--examples/plugin_pmount.py27
8 files changed, 77 insertions, 34 deletions
diff --git a/examples/plugin_chmod_keybindings.py b/examples/plugin_chmod_keybindings.py
index 63f42b0e..faab2345 100644
--- a/examples/plugin_chmod_keybindings.py
+++ b/examples/plugin_chmod_keybindings.py
@@ -4,12 +4,16 @@
 # It could replace the ten lines in the rc.conf that create the key bindings
 # for the "chmod" command.
 
+from __future__ import (absolute_import, print_function)
+
 import ranger.api
-old_hook_init = ranger.api.hook_init
+
+
+HOOK_INIT_OLD = ranger.api.hook_init
 
 
 def hook_init(fm):
-    old_hook_init(fm)
+    HOOK_INIT_OLD(fm)
 
     # Generate key bindings for the chmod command
     command = "map {0}{1}{2} shell -d chmod {1}{0}{2} %s"
@@ -18,4 +22,5 @@ def hook_init(fm):
             fm.execute_console(command.format('-', mode, perm))
             fm.execute_console(command.format('+', mode, perm))
 
+
 ranger.api.hook_init = hook_init
diff --git a/examples/plugin_file_filter.py b/examples/plugin_file_filter.py
index 5d5f1466..f5c474c5 100644
--- a/examples/plugin_file_filter.py
+++ b/examples/plugin_file_filter.py
@@ -4,20 +4,23 @@
 # the "show_hidden" option is activated.
 
 # Save the original filter function
+
+from __future__ import (absolute_import, print_function)
+
 import ranger.container.directory
-old_accept_file = ranger.container.directory.accept_file
 
-HIDE_FILES = ("/boot", "/sbin", "/proc", "/sys")
 
-# Define a new one
+ACCEPT_FILE_OLD = ranger.container.directory.accept_file
 
+HIDE_FILES = ("/boot", "/sbin", "/proc", "/sys")
 
-def custom_accept_file(file, filters):
-    if not file.fm.settings.show_hidden and file.path in HIDE_FILES:
+
+# Define a new one
+def custom_accept_file(fobj, filters):
+    if not fobj.fm.settings.show_hidden and fobj.path in HIDE_FILES:
         return False
-    else:
-        return old_accept_file(file, filters)
+    return ACCEPT_FILE_OLD(fobj, filters)
+
 
 # Overwrite the old function
-import ranger.container.directory
 ranger.container.directory.accept_file = custom_accept_file
diff --git a/examples/plugin_hello_world.py b/examples/plugin_hello_world.py
index 0158a653..b1451be1 100644
--- a/examples/plugin_hello_world.py
+++ b/examples/plugin_hello_world.py
@@ -3,13 +3,15 @@
 # This is a sample plugin that displays "Hello World" in ranger's console after
 # it started.
 
+from __future__ import (absolute_import, print_function)
+
 # We are going to extend the hook "ranger.api.hook_ready", so first we need
 # to import ranger.api:
 import ranger.api
 
 # Save the previously existing hook, because maybe another module already
 # extended that hook and we don't want to lose it:
-old_hook_ready = ranger.api.hook_ready
+HOOK_READY_OLD = ranger.api.hook_ready
 
 # Create a replacement for the hook that...
 
@@ -19,7 +21,8 @@ def hook_ready(fm):
     fm.notify("Hello World")
     # ...and calls the saved hook.  If you don't care about the return value,
     # simply return the return value of the previous hook to be safe.
-    return old_hook_ready(fm)
+    return HOOK_READY_OLD(fm)
+
 
 # Finally, "monkey patch" the existing hook_ready function with our replacement:
 ranger.api.hook_ready = hook_ready
diff --git a/examples/plugin_ipc.py b/examples/plugin_ipc.py
index 47fb1c84..99637272 100644
--- a/examples/plugin_ipc.py
+++ b/examples/plugin_ipc.py
@@ -7,17 +7,20 @@
 # Example:
 #   $ echo tab_new ~/images > /tmp/ranger-ipc.1234
 
+from __future__ import (absolute_import, print_function)
+
 import ranger.api
 
-old_hook_init = ranger.api.hook_init
+
+HOOK_INIT_OLD = ranger.api.hook_init
 
 
 def hook_init(fm):
     try:
         # Create a FIFO.
         import os
-        IPC_FIFO = "/tmp/ranger-ipc." + str(os.getpid())
-        os.mkfifo(IPC_FIFO)
+        ipc_fifo = "/tmp/ranger-ipc." + str(os.getpid())
+        os.mkfifo(ipc_fifo)
 
         # Start the reader thread.
         try:
@@ -30,7 +33,7 @@ def hook_init(fm):
                 with open(filepath, 'r') as fifo:
                     line = fifo.read()
                     fm.execute_console(line.strip())
-        thread.start_new_thread(ipc_reader, (IPC_FIFO,))
+        thread.start_new_thread(ipc_reader, (ipc_fifo,))
 
         # Remove the FIFO on ranger exit.
         def ipc_cleanup(filepath):
@@ -39,10 +42,12 @@ def hook_init(fm):
             except IOError:
                 pass
         import atexit
-        atexit.register(ipc_cleanup, IPC_FIFO)
+        atexit.register(ipc_cleanup, ipc_fifo)
     except IOError:
         # IPC support disabled
         pass
     finally:
-        old_hook_init(fm)
+        HOOK_INIT_OLD(fm)
+
+
 ranger.api.hook_init = hook_init
diff --git a/examples/plugin_linemode.py b/examples/plugin_linemode.py
index 851d6213..84cc57cc 100644
--- a/examples/plugin_linemode.py
+++ b/examples/plugin_linemode.py
@@ -5,7 +5,10 @@
 # the linemode by typing ":linemode rot13" in ranger.  Type Mf to restore
 # the default linemode.
 
+from __future__ import (absolute_import, print_function)
+
 import codecs
+
 import ranger.api
 from ranger.core.linemode import LinemodeBase
 
@@ -14,5 +17,8 @@ from ranger.core.linemode import LinemodeBase
 class MyLinemode(LinemodeBase):
     name = "rot13"
 
-    def filetitle(self, file, metadata):
-        return codecs.encode(file.relative_path, "rot_13")
+    def filetitle(self, fobj, metadata):
+        return codecs.encode(fobj.relative_path, "rot_13")
+
+    def infostring(self, fobj, metadata):
+        raise NotImplementedError
diff --git a/examples/plugin_new_macro.py b/examples/plugin_new_macro.py
index 8dbe435d..0e44cdd3 100644
--- a/examples/plugin_new_macro.py
+++ b/examples/plugin_new_macro.py
@@ -4,18 +4,22 @@
 # date in commands that allow macros.  You can test it with the command
 # ":shell echo %date; read"
 
-# Save the original macro function
-import ranger.core.actions
-old_get_macros = ranger.core.actions.Actions._get_macros
+from __future__ import (absolute_import, print_function)
 
-# Define a new macro function
 import time
 
+import ranger.core.actions
 
+# Save the original macro function
+GET_MACROS_OLD = ranger.core.actions.Actions._get_macros  # pylint: disable=protected-access
+
+
+# Define a new macro function
 def get_macros_with_date(self):
-    macros = old_get_macros(self)
+    macros = GET_MACROS_OLD(self)
     macros['date'] = time.strftime('%m/%d/%Y')
     return macros
 
+
 # Overwrite the old one
-ranger.core.actions.Actions._get_macros = get_macros_with_date
+ranger.core.actions.Actions._get_macros = get_macros_with_date  # pylint: disable=protected-access
diff --git a/examples/plugin_new_sorting_method.py b/examples/plugin_new_sorting_method.py
index 012bd7a2..fefeaad9 100644
--- a/examples/plugin_new_sorting_method.py
+++ b/examples/plugin_new_sorting_method.py
@@ -3,6 +3,10 @@
 # This plugin adds the sorting algorithm called 'random'.  To enable it, type
 # ":set sort=random" or create a key binding with ":map oz set sort=random"
 
-from ranger.container.directory import Directory
+from __future__ import (absolute_import, print_function)
+
 from random import random
+
+from ranger.container.directory import Directory
+
 Directory.sort_dict['random'] = lambda path: random()
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