diff options
Diffstat (limited to 'ranger/api')
-rw-r--r-- | ranger/api/__init__.py | 11 | ||||
-rw-r--r-- | ranger/api/commands.py | 54 | ||||
-rw-r--r-- | ranger/api/options.py | 11 |
3 files changed, 37 insertions, 39 deletions
diff --git a/ranger/api/__init__.py b/ranger/api/__init__.py index 5981c31a..3c7818b8 100644 --- a/ranger/api/__init__.py +++ b/ranger/api/__init__.py @@ -3,10 +3,13 @@ """Files in this module contain helper functions used in configuration files.""" -# Hooks for use in plugins: +import ranger # NOQA + +from ranger.core.linemode import LinemodeBase # NOQA -def hook_init(fm): +# Hooks for use in plugins: +def hook_init(fm): # pylint: disable=unused-argument """A hook that is called when ranger starts up. Parameters: @@ -20,7 +23,7 @@ def hook_init(fm): """ -def hook_ready(fm): +def hook_ready(fm): # pylint: disable=unused-argument """A hook that is called after the ranger UI is initialized. Parameters: @@ -32,8 +35,6 @@ def hook_ready(fm): NOT print anything to stdout anymore from here on. Use fm.notify instead. """ -from ranger.core.linemode import LinemodeBase - def register_linemode(linemode_class): """Add a custom linemode class. See ranger.core.linemode""" diff --git a/ranger/api/commands.py b/ranger/api/commands.py index 46075f26..76fe588a 100644 --- a/ranger/api/commands.py +++ b/ranger/api/commands.py @@ -4,11 +4,14 @@ # TODO: Add an optional "!" to all commands and set a flag if it's there import os -import ranger import re import inspect -from collections import deque -from ranger.api import * +# COMPAT pylint: disable=unused-import +from collections import deque # NOQA +from ranger.api import LinemodeBase, hook_init, hook_ready, register_linemode # NOQA +# pylint: enable=unused-import + +import ranger from ranger.core.shared import FileManagerAware from ranger.ext.lazy_property import lazy_property @@ -26,10 +29,12 @@ class CommandContainer(object): def alias(self, name, full_command): try: cmd = type(name, (AliasCommand, ), dict()) + # pylint: disable=protected-access cmd._based_function = name cmd._function_name = name cmd._object_name = name cmd._line = full_command + # pylint: enable=protected-access self.commands[name] = cmd except Exception: @@ -51,9 +56,11 @@ class CommandContainer(object): attribute = getattr(obj, attribute_name) if hasattr(attribute, '__call__'): cmd = type(attribute_name, (FunctionCommand, ), dict(__doc__=attribute.__doc__)) + # pylint: disable=protected-access cmd._based_function = attribute cmd._function_name = attribute.__name__ cmd._object_name = obj.__class__.__name__ + # pylint: enable=protected-access self.commands[attribute_name] = cmd def get_command(self, name, abbrev=True): @@ -99,12 +106,12 @@ class Command(FileManagerAware): self.firstpart = '' @classmethod - def get_name(self): - classdict = self.__mro__[0].__dict__ + def get_name(cls): + classdict = cls.__mro__[0].__dict__ if 'name' in classdict and classdict['name']: - return self.name + return cls.name else: - return self.__name__ + return cls.__name__ def execute(self): """Override this""" @@ -150,9 +157,6 @@ class Command(FileManagerAware): self._setting_line = None self._shifted += 1 - def tabinsert(self, word): - return ''.join([self._tabinsert_left, word, self._tabinsert_right]) - def parse_setting_line(self): """ Parses the command line argument that is passed to the `:set` command. @@ -242,18 +246,6 @@ class Command(FileManagerAware): import logging return logging.getLogger('ranger.commands.' + self.__class__.__name__) - # XXX: Lazy properties? Not so smart? self.line can change after all! - @lazy_property - def _tabinsert_left(self): - try: - return self.line[:self.line[0:self.pos].rindex(' ') + 1] - except ValueError: - return '' - - @lazy_property - def _tabinsert_right(self): - return self.line[self.pos:] - # COMPAT: this is still used in old commands.py configs def _tab_only_directories(self): from os.path import dirname, basename, expanduser, join @@ -301,7 +293,7 @@ class Command(FileManagerAware): return (self.start(1) + join(rel_dirname, dirname) for dirname in dirnames) - def _tab_directory_content(self): + def _tab_directory_content(self): # pylint: disable=too-many-locals from os.path import dirname, basename, expanduser, join cwd = self.fm.thisdir.path @@ -383,14 +375,16 @@ class FunctionCommand(Command): _object_name = "" _function_name = "unknown" - def execute(self): + def execute(self): # pylint: disable=too-many-branches if not self._based_function: return if len(self.args) == 1: try: + # pylint: disable=not-callable return self._based_function(**{'narg': self.quantifier}) + # pylint: enable=not-callable except TypeError: - return self._based_function() + return self._based_function() # pylint: disable=not-callable args, keywords = list(), dict() for arg in self.args[1:]: @@ -403,7 +397,7 @@ class FunctionCommand(Command): value = (value == 'True') else: try: - value = float(value) + value = float(value) # pylint: disable=redefined-variable-type except Exception: pass @@ -417,13 +411,13 @@ class FunctionCommand(Command): try: if self.quantifier is None: - return self._based_function(*args, **keywords) + return self._based_function(*args, **keywords) # pylint: disable=not-callable else: try: - return self._based_function(*args, **keywords) + return self._based_function(*args, **keywords) # pylint: disable=not-callable except TypeError: del keywords['narg'] - return self._based_function(*args, **keywords) + return self._based_function(*args, **keywords) # pylint: disable=not-callable except TypeError: if ranger.arg.debug: raise @@ -448,7 +442,7 @@ class AliasCommand(Command): def tab(self, tabnum): cmd = self._make_cmd() args = inspect.signature(cmd.tab).parameters if self.fm.py3 else \ - inspect.getargspec(cmd.tab).args + inspect.getargspec(cmd.tab).args # pylint: disable=deprecated-method return cmd.tab(tabnum) if 'tabnum' in args else cmd.tab() def cancel(self): diff --git a/ranger/api/options.py b/ranger/api/options.py index 0cce1364..3161a2c6 100644 --- a/ranger/api/options.py +++ b/ranger/api/options.py @@ -2,7 +2,10 @@ # License: GNU GPL version 3, see the file "AUTHORS" for details. # THIS WHOLE FILE IS OBSOLETE AND EXISTS FOR BACKWARDS COMPATIBILITIY -import re -from re import compile as regexp -from ranger.api import * -from ranger.gui import color +# pylint: disable=unused-import +import re # NOQA +from re import compile as regexp # NOQA + +from ranger.api import LinemodeBase, hook_init, hook_ready, register_linemode # NOQA +from ranger.gui import color # NOQA +# pylint: enable=unused-import |