From 6ded89ed41799b1244cb0a57dd29c10feb51d537 Mon Sep 17 00:00:00 2001 From: randnobx Date: Thu, 18 May 2017 19:00:16 -0400 Subject: added global_inode_filter_type setting; show only directories when --choosedir merged local and global inode_filter handling; refactored hidden_inode_filter_func --- ranger/config/commands.py | 14 ++------------ ranger/container/directory.py | 23 +++++++++++++++++++++-- ranger/container/settings.py | 1 + ranger/core/main.py | 3 +++ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 4cedc4e1..c2ecb3af 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -1480,22 +1480,12 @@ class filter_inode_type(Command): f display files l display links """ - # pylint: disable=bad-whitespace - FILTER_DIRS = 'd' - FILTER_FILES = 'f' - FILTER_LINKS = 'l' - # pylint: enable=bad-whitespace def execute(self): if not self.arg(1): - self.fm.thisdir.inode_type_filter = None + self.fm.thisdir.inode_type_filter = "" else: - self.fm.thisdir.inode_type_filter = lambda file: ( - True if ( - (self.FILTER_DIRS in self.arg(1) and file.is_directory) or - (self.FILTER_FILES in self.arg(1) and file.is_file and not file.is_link) or - (self.FILTER_LINKS in self.arg(1) and file.is_link) - ) else False) + self.fm.thisdir.inode_type_filter = self.arg(1) self.fm.thisdir.refilter() diff --git a/ranger/container/directory.py b/ranger/container/directory.py index 168a46c7..958c6f28 100644 --- a/ranger/container/directory.py +++ b/ranger/container/directory.py @@ -95,6 +95,11 @@ def mtimelevel(path, level): class Directory( # pylint: disable=too-many-instance-attributes,too-many-public-methods FileSystemObject, Accumulator, Loadable): + + FILTER_DIRS = 'd' + FILTER_FILES = 'f' + FILTER_LINKS = 'l' + is_directory = True enterable = False load_generator = None @@ -252,11 +257,25 @@ class Directory( # pylint: disable=too-many-instance-attributes,too-many-public return False return True filters.append(hidden_filter_func) + if self.settings.global_inode_type_filter or self.inode_type_filter: + def hidden_inode_filter_func(obj): + # Use local inode_type_filter is present, global otherwise + if self.inode_type_filter: + inode_filter = self.inode_type_filter + else: + inode_filter = self.settings.global_inode_type_filter + # Apply filter + if self.FILTER_DIRS in inode_filter and obj.is_directory: + return True + elif self.FILTER_FILES in inode_filter and obj.is_file and not obj.is_link: + return True + elif self.FILTER_LINKS in inode_filter and obj.is_link: + return True + return False + filters.append(hidden_inode_filter_func) if self.filter: filter_search = self.filter.search filters.append(lambda fobj: filter_search(fobj.basename)) - if self.inode_type_filter: - filters.append(self.inode_type_filter) if self.temporary_filter: temporary_filter_search = self.temporary_filter.search filters.append(lambda fobj: temporary_filter_search(fobj.basename)) diff --git a/ranger/container/settings.py b/ranger/container/settings.py index 70e299c7..00563772 100644 --- a/ranger/container/settings.py +++ b/ranger/container/settings.py @@ -41,6 +41,7 @@ ALLOWED_SETTINGS = { 'draw_borders': bool, 'draw_progress_bar_in_status_bar': bool, 'flushinput': bool, + 'global_inode_type_filter': str, 'hidden_filter': str, 'idle_delay': int, 'line_numbers': str, diff --git a/ranger/core/main.py b/ranger/core/main.py index 38513970..f2434ec6 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -119,6 +119,9 @@ def main( FileManagerAware.fm_set(fm) load_settings(fm, args.clean) + if args.choosedir: + SettingsAware.settings.global_inode_type_filter = 'd' + if args.list_unused_keys: from ranger.ext.keybinding_parser import (special_keys, reversed_special_keys) -- cgit 1.4.1-2-gfad0 From b27c54d69ab53be0015615a4de364f5b7cdd1574 Mon Sep 17 00:00:00 2001 From: randnobx Date: Sat, 20 May 2017 19:42:45 -0400 Subject: refactor inode_filter assignment; change function name --- ranger/container/directory.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ranger/container/directory.py b/ranger/container/directory.py index 958c6f28..69b619ea 100644 --- a/ranger/container/directory.py +++ b/ranger/container/directory.py @@ -258,12 +258,9 @@ class Directory( # pylint: disable=too-many-instance-attributes,too-many-public return True filters.append(hidden_filter_func) if self.settings.global_inode_type_filter or self.inode_type_filter: - def hidden_inode_filter_func(obj): + def inode_filter_func(obj): # Use local inode_type_filter is present, global otherwise - if self.inode_type_filter: - inode_filter = self.inode_type_filter - else: - inode_filter = self.settings.global_inode_type_filter + inode_filter = self.inode_type_filter or self.settings.global_inode_type_filter # Apply filter if self.FILTER_DIRS in inode_filter and obj.is_directory: return True @@ -272,7 +269,7 @@ class Directory( # pylint: disable=too-many-instance-attributes,too-many-public elif self.FILTER_LINKS in inode_filter and obj.is_link: return True return False - filters.append(hidden_inode_filter_func) + filters.append(inode_filter_func) if self.filter: filter_search = self.filter.search filters.append(lambda fobj: filter_search(fobj.basename)) -- cgit 1.4.1-2-gfad0 From cb069868a4f5a162dedb75ff2a181fcf59ccd2ce Mon Sep 17 00:00:00 2001 From: randnobx Date: Sat, 20 May 2017 19:59:13 -0400 Subject: fixed SettingsAware.settings to fm.settings --- ranger/core/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ranger/core/main.py b/ranger/core/main.py index f2434ec6..35c5eb62 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -120,7 +120,7 @@ def main( load_settings(fm, args.clean) if args.choosedir: - SettingsAware.settings.global_inode_type_filter = 'd' + fm.settings.global_inode_type_filter = 'd' if args.list_unused_keys: from ranger.ext.keybinding_parser import (special_keys, -- cgit 1.4.1-2-gfad0 From 9a20699a86ae33fbf60182de4d73d1d457817233 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Sun, 21 May 2017 02:02:15 +0200 Subject: Separate the inode filter constants into their own class --- ranger/container/directory.py | 13 +++++++------ ranger/core/main.py | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ranger/container/directory.py b/ranger/container/directory.py index 69b619ea..5bc822c4 100644 --- a/ranger/container/directory.py +++ b/ranger/container/directory.py @@ -92,13 +92,14 @@ def mtimelevel(path, level): mtime = max(mtime, max([-1] + [os.stat(d).st_mtime for d in dirlist])) return mtime +class InodeFilterConstants(object): + DIRS = 'd' + FILES = 'f' + LINKS = 'l' class Directory( # pylint: disable=too-many-instance-attributes,too-many-public-methods FileSystemObject, Accumulator, Loadable): - FILTER_DIRS = 'd' - FILTER_FILES = 'f' - FILTER_LINKS = 'l' is_directory = True enterable = False @@ -262,11 +263,11 @@ class Directory( # pylint: disable=too-many-instance-attributes,too-many-public # Use local inode_type_filter is present, global otherwise inode_filter = self.inode_type_filter or self.settings.global_inode_type_filter # Apply filter - if self.FILTER_DIRS in inode_filter and obj.is_directory: + if InodeFilterConstants.DIRS in inode_filter and obj.is_directory: return True - elif self.FILTER_FILES in inode_filter and obj.is_file and not obj.is_link: + elif InodeFilterConstants.FILES in inode_filter and obj.is_file and not obj.is_link: return True - elif self.FILTER_LINKS in inode_filter and obj.is_link: + elif InodeFilterConstants.LINKS in inode_filter and obj.is_link: return True return False filters.append(inode_filter_func) diff --git a/ranger/core/main.py b/ranger/core/main.py index 35c5eb62..3e68e15c 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -120,7 +120,8 @@ def main( load_settings(fm, args.clean) if args.choosedir: - fm.settings.global_inode_type_filter = 'd' + from ranger.container.directory import InodeFilterConstants + fm.settings.global_inode_type_filter = InodeFilterConstants.DIRS if args.list_unused_keys: from ranger.ext.keybinding_parser import (special_keys, -- cgit 1.4.1-2-gfad0 From 48db8b597814a1f94b3f99f86bf1e242fd8c7a5e Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Sun, 21 May 2017 02:24:38 +0200 Subject: Resolve the pylint warnings Fix one typo too. --- ranger/container/directory.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ranger/container/directory.py b/ranger/container/directory.py index 5bc822c4..4b067d35 100644 --- a/ranger/container/directory.py +++ b/ranger/container/directory.py @@ -92,15 +92,15 @@ def mtimelevel(path, level): mtime = max(mtime, max([-1] + [os.stat(d).st_mtime for d in dirlist])) return mtime -class InodeFilterConstants(object): + +class InodeFilterConstants(object): # pylint: disable=too-few-public-methods DIRS = 'd' FILES = 'f' LINKS = 'l' + class Directory( # pylint: disable=too-many-instance-attributes,too-many-public-methods FileSystemObject, Accumulator, Loadable): - - is_directory = True enterable = False load_generator = None @@ -260,14 +260,17 @@ class Directory( # pylint: disable=too-many-instance-attributes,too-many-public filters.append(hidden_filter_func) if self.settings.global_inode_type_filter or self.inode_type_filter: def inode_filter_func(obj): - # Use local inode_type_filter is present, global otherwise + # Use local inode_type_filter if present, global otherwise inode_filter = self.inode_type_filter or self.settings.global_inode_type_filter # Apply filter - if InodeFilterConstants.DIRS in inode_filter and obj.is_directory: + if InodeFilterConstants.DIRS in inode_filter and \ + obj.is_directory: return True - elif InodeFilterConstants.FILES in inode_filter and obj.is_file and not obj.is_link: + elif InodeFilterConstants.FILES in inode_filter and \ + obj.is_file and not obj.is_link: return True - elif InodeFilterConstants.LINKS in inode_filter and obj.is_link: + elif InodeFilterConstants.LINKS in inode_filter and \ + obj.is_link: return True return False filters.append(inode_filter_func) -- cgit 1.4.1-2-gfad0