about summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
author5hir0kur0 <12101162+5hir0kur0@users.noreply.github.com>2020-03-07 20:25:59 +0100
committer5hir0kur0 <12101162+5hir0kur0@users.noreply.github.com>2020-03-07 20:35:23 +0100
commita9123b0f6b31987782c162c2dd9a7f16d4a68894 (patch)
treee139d5a6830d7202eb1d6310739340a0418c8d26 /ranger
parent461d423b5a509e9939d2cc044bf954c864e8ce14 (diff)
downloadranger-a9123b0f6b31987782c162c2dd9a7f16d4a68894.tar.gz
trash: Move paths_to_filesystem_objects to fm.py
This commit also renames the method to "get_filesystem_objects" for
symmetry to "get_directory".
Diffstat (limited to 'ranger')
-rwxr-xr-xranger/config/commands.py39
-rw-r--r--ranger/core/fm.py37
2 files changed, 38 insertions, 38 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index 499bf3ef..0105c171 100755
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -728,7 +728,7 @@ class trash(Command):
 
         if self.rest(1):
             file_names = shlex.split(self.rest(1))
-            files = self.paths_to_filesystem_objects(file_names)
+            files = self.fm.get_filesystem_objects(file_names)
             if files is None:
                 return
             many_files = (len(files) > 1 or is_directory_with_files(files[0].path))
@@ -755,43 +755,6 @@ class trash(Command):
             # no need for a confirmation, just delete
             self._trash_files_catch_arg_list_error(files)
 
-    @staticmethod
-    def group_paths_by_dirname(paths):
-        """
-        Groups the paths into a dictionary with their dirnames as keys and a set of
-        basenames as entries.
-        """
-        groups = dict()
-        for path in paths:
-            abspath = os.path.abspath(os.path.expanduser(path))
-            dirname, basename = os.path.split(abspath)
-            groups.setdefault(dirname, set()).add(basename)
-        return groups
-
-    def paths_to_filesystem_objects(self, paths):
-        """
-        Find FileSystemObjects corresponding to the paths if they are already in
-        memory and load those that are not.
-        """
-        result = []
-        # Grouping the files by dirname avoids the potentially quadratic running time of doing
-        # a linear search in the directory for each entry name that is supposed to be deleted.
-        groups = trash.group_paths_by_dirname(paths)
-        for dirname, basenames in groups.items():
-            directory = self.fm.get_directory(dirname)
-            directory.load_content_if_outdated()
-            for entry in directory.files_all:
-                if entry.basename in basenames:
-                    result.append(entry)
-                    basenames.remove(entry.basename)
-            if basenames != set():
-                # Abort the operation with an error message if there are entries
-                # that weren't found.
-                names = ', '.join(basenames)
-                self.fm.notify('Error: No such file or directory: {}'.format(names), bad=True)
-                return None
-        return result
-
     def tab(self, tabnum):
         return self._tab_directory_content()
 
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index 7d23c9b6..77aa2260 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -329,6 +329,43 @@ class FM(Actions,  # pylint: disable=too-many-instance-attributes
             self.directories[path] = obj
             return obj
 
+    @staticmethod
+    def group_paths_by_dirname(paths):
+        """
+        Groups the paths into a dictionary with their dirnames as keys and a set of
+        basenames as entries.
+        """
+        groups = dict()
+        for path in paths:
+            abspath = os.path.abspath(os.path.expanduser(path))
+            dirname, basename = os.path.split(abspath)
+            groups.setdefault(dirname, set()).add(basename)
+        return groups
+
+    def get_filesystem_objects(self, paths):
+        """
+        Find FileSystemObjects corresponding to the paths if they are already in
+        memory and load those that are not.
+        """
+        result = []
+        # Grouping the files by dirname avoids the potentially quadratic running time of doing
+        # a linear search in the directory for each entry name that is supposed to be deleted.
+        groups = self.group_paths_by_dirname(paths)
+        for dirname, basenames in groups.items():
+            directory = self.fm.get_directory(dirname)
+            directory.load_content_if_outdated()
+            for entry in directory.files_all:
+                if entry.basename in basenames:
+                    result.append(entry)
+                    basenames.remove(entry.basename)
+            if basenames != set():
+                # Abort the operation with an error message if there are entries
+                # that weren't found.
+                names = ', '.join(basenames)
+                self.fm.notify('Error: No such file or directory: {}'.format(names), bad=True)
+                return None
+        return result
+
     def garbage_collect(
             self, age,
             tabs=None):  # tabs=None is for COMPATibility pylint: disable=unused-argument