diff options
author | nfnty <git@nfnty.se> | 2016-12-21 05:06:55 +0100 |
---|---|---|
committer | nfnty <git@nfnty.se> | 2017-01-17 05:59:02 +0100 |
commit | b3d031a913814900467358b2adf20a148bf6de1a (patch) | |
tree | 6f5b435817ec9cbe850fb73485a7e6c77da28c14 /examples | |
parent | 76791a70467d7223a966aa9f12f5583b01d704a8 (diff) | |
download | ranger-b3d031a913814900467358b2adf20a148bf6de1a.tar.gz |
linting: pylint and flake8
Diffstat (limited to 'examples')
-rw-r--r-- | examples/plugin_chmod_keybindings.py | 7 | ||||
-rw-r--r-- | examples/plugin_file_filter.py | 11 | ||||
-rw-r--r-- | examples/plugin_hello_world.py | 5 | ||||
-rw-r--r-- | examples/plugin_ipc.py | 15 | ||||
-rw-r--r-- | examples/plugin_linemode.py | 4 | ||||
-rw-r--r-- | examples/plugin_new_macro.py | 14 | ||||
-rw-r--r-- | examples/plugin_new_sorting_method.py | 4 | ||||
-rw-r--r-- | examples/plugin_pmount.py | 11 |
8 files changed, 46 insertions, 25 deletions
diff --git a/examples/plugin_chmod_keybindings.py b/examples/plugin_chmod_keybindings.py index 63f42b0e..72e90121 100644 --- a/examples/plugin_chmod_keybindings.py +++ b/examples/plugin_chmod_keybindings.py @@ -5,11 +5,13 @@ # for the "chmod" command. 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 +20,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..486e59d9 100644 --- a/examples/plugin_file_filter.py +++ b/examples/plugin_file_filter.py @@ -5,19 +5,20 @@ # Save the original filter 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") +# Define a new one def custom_accept_file(file, filters): if not file.fm.settings.show_hidden and file.path in HIDE_FILES: return False else: - return old_accept_file(file, filters) + return ACCEPT_FILE_OLD(file, 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..dc4c3fee 100644 --- a/examples/plugin_hello_world.py +++ b/examples/plugin_hello_world.py @@ -9,7 +9,7 @@ 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 +19,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..ef87c3c5 100644 --- a/examples/plugin_ipc.py +++ b/examples/plugin_ipc.py @@ -9,15 +9,16 @@ 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 +31,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 +40,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..6f16743d 100644 --- a/examples/plugin_linemode.py +++ b/examples/plugin_linemode.py @@ -6,6 +6,7 @@ # the default linemode. import codecs + import ranger.api from ranger.core.linemode import LinemodeBase @@ -16,3 +17,6 @@ class MyLinemode(LinemodeBase): def filetitle(self, file, metadata): return codecs.encode(file.relative_path, "rot_13") + + def infostring(self, file, metadata): + raise NotImplementedError diff --git a/examples/plugin_new_macro.py b/examples/plugin_new_macro.py index 8dbe435d..1c69b841 100644 --- a/examples/plugin_new_macro.py +++ b/examples/plugin_new_macro.py @@ -4,18 +4,20 @@ # date in commands that allow macros. You can test it with the command # ":shell echo %date; read" -# Save the original macro function +import time + import ranger.core.actions -old_get_macros = ranger.core.actions.Actions._get_macros -# Define a new macro function -import time +# 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..2dd50257 100644 --- a/examples/plugin_new_sorting_method.py +++ b/examples/plugin_new_sorting_method.py @@ -3,6 +3,8 @@ # 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 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 fe0adffb..6cd325f7 100644 --- a/examples/plugin_pmount.py +++ b/examples/plugin_pmount.py @@ -15,7 +15,8 @@ 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): @@ -33,6 +34,10 @@ def hook_init(fm): ) 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) + except Exception: + pass + + return HOOK_INIT_OLD(fm) + + ranger.api.hook_init = hook_init |