diff options
Diffstat (limited to 'ranger/ext')
-rw-r--r-- | ranger/ext/accumulator.py | 4 | ||||
-rw-r--r-- | ranger/ext/cached_function.py | 1 | ||||
-rw-r--r-- | ranger/ext/direction.py | 23 | ||||
-rw-r--r-- | ranger/ext/img_display.py | 2 | ||||
-rw-r--r-- | ranger/ext/lazy_property.py | 37 | ||||
-rw-r--r-- | ranger/ext/next_available_filename.py | 1 | ||||
-rwxr-xr-x | ranger/ext/rifle.py | 5 | ||||
-rw-r--r-- | ranger/ext/signals.py | 6 | ||||
-rw-r--r-- | ranger/ext/vcs/vcs.py | 7 | ||||
-rw-r--r-- | ranger/ext/widestring.py | 4 |
10 files changed, 74 insertions, 16 deletions
diff --git a/ranger/ext/accumulator.py b/ranger/ext/accumulator.py index b0e4a1c5..c2e33b59 100644 --- a/ranger/ext/accumulator.py +++ b/ranger/ext/accumulator.py @@ -29,12 +29,12 @@ class Accumulator(object): def move_to_obj(self, arg, attr=None): if not arg: - return + return None lst = self.get_list() if not lst: - return + return None do_get_attr = isinstance(attr, str) diff --git a/ranger/ext/cached_function.py b/ranger/ext/cached_function.py index 4255443c..7fdd579e 100644 --- a/ranger/ext/cached_function.py +++ b/ranger/ext/cached_function.py @@ -4,6 +4,7 @@ from __future__ import (absolute_import, division, print_function) +# Similar to functools.lru_cache of python3 def cached_function(fnc): cache = {} diff --git a/ranger/ext/direction.py b/ranger/ext/direction.py index bbb69c9b..7df45556 100644 --- a/ranger/ext/direction.py +++ b/ranger/ext/direction.py @@ -20,6 +20,8 @@ False from __future__ import (absolute_import, division, print_function) +import math + class Direction(dict): @@ -94,6 +96,10 @@ class Direction(dict): def cycle(self): return self.get('cycle') in (True, 'true', 'on', 'yes') + def one_indexed(self): + return ('one_indexed' in self and + self.get('one_indexed') in (True, 'true', 'on', 'yes')) + def multiply(self, n): for key in ('up', 'right', 'down', 'left'): try: @@ -127,7 +133,10 @@ class Direction(dict): pos = direction if override is not None: if self.absolute(): - pos = override + if self.one_indexed(): + pos = override - 1 + else: + pos = override else: pos *= override if self.pages(): @@ -142,8 +151,16 @@ class Direction(dict): if self.cycle(): cycles, pos = divmod(pos, (maximum + offset - minimum)) self['_move_cycles'] = int(cycles) - return int(minimum + pos) - return int(max(min(pos, maximum + offset - 1), minimum)) + ret = minimum + pos + else: + ret = max(min(pos, maximum + offset - 1), minimum) + # Round towards the direction we're moving from. + # From the UI point of view, round down. See: #912. + if direction < 0: + ret = int(math.ceil(ret)) + else: + ret = int(ret) + return ret def move_cycles(self): return self.get('_move_cycles', 0) diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py index e561b80d..f8316270 100644 --- a/ranger/ext/img_display.py +++ b/ranger/ext/img_display.py @@ -122,6 +122,8 @@ class W3MImageDisplayer(ImageDisplayer): self.process.stdin.write(input_gen) self.process.stdin.flush() self.process.stdout.readline() + self.quit() + self.is_initialized = False def clear(self, start_x, start_y, width, height): if not self.is_initialized or self.process.poll() is not None: diff --git a/ranger/ext/lazy_property.py b/ranger/ext/lazy_property.py index 92dc309d..bb54bd5e 100644 --- a/ranger/ext/lazy_property.py +++ b/ranger/ext/lazy_property.py @@ -1,4 +1,6 @@ -# From http://blog.pythonisito.com/2008/08/lazy-descriptors.html +# This file is part of ranger, the console file manager. +# License: GNU GPL version 3, see the file "AUTHORS" for details. +# Based on http://blog.pythonisito.com/2008/08/lazy-descriptors.html from __future__ import (absolute_import, division, print_function) @@ -7,16 +9,30 @@ class lazy_property(object): # pylint: disable=invalid-name,too-few-public-meth """A @property-like decorator with lazy evaluation >>> class Foo: + ... counter = 0 ... @lazy_property ... def answer(self): - ... print("calculating answer...") - ... return 2*3*7 + ... Foo.counter += 1 + ... return Foo.counter >>> foo = Foo() >>> foo.answer - calculating answer... - 42 + 1 >>> foo.answer - 42 + 1 + >>> foo.answer__reset() + >>> foo.answer + 2 + >>> foo.answer + 2 + + Avoid interaction between multiple objects: + + >>> bar = Foo() + >>> bar.answer + 3 + >>> foo.answer__reset() + >>> bar.answer + 3 """ def __init__(self, method): @@ -27,6 +43,15 @@ class lazy_property(object): # pylint: disable=invalid-name,too-few-public-meth def __get__(self, obj, cls=None): if obj is None: # to fix issues with pydoc return None + + reset_function_name = self.__name__ + "__reset" + + if not hasattr(obj, reset_function_name): + def reset_function(): + setattr(obj, self.__name__, self) + del obj.__dict__[self.__name__] # force "__get__" being called + obj.__dict__[reset_function_name] = reset_function + result = self._method(obj) obj.__dict__[self.__name__] = result return result diff --git a/ranger/ext/next_available_filename.py b/ranger/ext/next_available_filename.py index 91d48631..0a5e0856 100644 --- a/ranger/ext/next_available_filename.py +++ b/ranger/ext/next_available_filename.py @@ -19,3 +19,4 @@ def next_available_filename(fname, directory="."): for i in range(1, len(existing_files) + 1): if fname + str(i) not in existing_files: return fname + str(i) + return None diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py index cfb07f5f..a6c0b9f0 100755 --- a/ranger/ext/rifle.py +++ b/ranger/ext/rifle.py @@ -244,6 +244,7 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes return bool(os.environ.get(argument)) elif function == 'else': return True + return None def get_mimetype(self, fname): # Spawn "file" to determine the mime-type of the given file. @@ -295,7 +296,7 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes count = self._skip yield (count, cmd, self._app_label, self._app_flags) - def execute(self, files, # pylint: disable=too-many-branches,too-many-statements + def execute(self, files, # noqa: E501 pylint: disable=too-many-branches,too-many-statements,too-many-locals number=0, label=None, flags="", mimetype=None): """Executes the given list of files. @@ -379,6 +380,8 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes finally: self.hook_after_executing(command, self._mimetype, self._app_flags) + return None + def find_conf_path(): # Find configuration file path diff --git a/ranger/ext/signals.py b/ranger/ext/signals.py index cbd35643..67c8960d 100644 --- a/ranger/ext/signals.py +++ b/ranger/ext/signals.py @@ -155,6 +155,7 @@ class SignalDispatcher(object): key=lambda handler: -handler.priority) return handler + # TODO: Do we still use this method? Should we remove it? def signal_force_sort(self, signal_name=None): """Forces a sorting of signal handlers by priority. @@ -165,11 +166,12 @@ class SignalDispatcher(object): for handlers in self._signals.values(): handlers.sort( key=lambda handler: -handler.priority) + return None elif signal_name in self._signals: self._signals[signal_name].sort( key=lambda handler: -handler.priority) - else: - return False + return None + return False def signal_unbind(self, signal_handler): """Removes a signal binding. diff --git a/ranger/ext/vcs/vcs.py b/ranger/ext/vcs/vcs.py index ba28d141..e2838f8d 100644 --- a/ranger/ext/vcs/vcs.py +++ b/ranger/ext/vcs/vcs.py @@ -112,7 +112,11 @@ class Vcs(object): # pylint: disable=too-many-instance-attributes def _run(self, args, path=None, # pylint: disable=too-many-arguments catchout=True, retbytes=False, rstrip_newline=True): """Run a command""" - cmd = [self.repotype] + args + if self.repotype == 'hg': + # use "chg", a faster built-in client + cmd = ['chg'] + args + else: + cmd = [self.repotype] + args if path is None: path = self.path @@ -125,6 +129,7 @@ class Vcs(object): # pylint: disable=too-many-instance-attributes else: with open(os.devnull, mode='w') as fd_devnull: subprocess.check_call(cmd, cwd=path, stdout=fd_devnull, stderr=fd_devnull) + return None except (subprocess.CalledProcessError, OSError): raise VcsError('{0:s}: {1:s}'.format(str(cmd), path)) diff --git a/ranger/ext/widestring.py b/ranger/ext/widestring.py index ed66f3c7..2721643c 100644 --- a/ranger/ext/widestring.py +++ b/ranger/ext/widestring.py @@ -1,4 +1,4 @@ -# -*- encoding: utf8 -*- +# -*- encoding: utf-8 -*- # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. @@ -81,6 +81,7 @@ class WideString(object): # pylint: disable=too-few-public-methods return WideString(self.string + string) elif isinstance(string, WideString): return WideString(self.string + string.string, self.chars + string.chars) + return None def __radd__(self, string): """ @@ -91,6 +92,7 @@ class WideString(object): # pylint: disable=too-few-public-methods return WideString(string + self.string) elif isinstance(string, WideString): return WideString(string.string + self.string, string.chars + self.chars) + return None def __str__(self): return self.string |