예제 #1
0
    def on_text_changed(self, text: str) -> None:
        """Update trash model the once when text changed.

        This is required in addition to on_enter as it is very likely to enter trash
        completion by typing :undelete.
        """
        if self._initialized:
            return
        self.clear()
        data = []
        for path in files.listdir(trash_manager.files_directory()):
            cmd = "undelete %s" % (os.path.basename(path))
            # Get info and format it neatly
            original, date = trash_manager.trash_info(path)
            original = original.replace(os.path.expanduser("~"), "~")
            original = os.path.dirname(original)
            date = "%s-%s-%s %s:%s" % (
                date[2:4],
                date[4:6],
                date[6:8],
                date[9:11],
                date[11:13],
            )
            # Append data in column form
            data.append((cmd, original, date))
        self.set_data(data)
        self._initialized = True
예제 #2
0
def _load_single(path: str) -> None:
    """Populate list of paths in same directory for single path."""
    if path in _paths:
        goto(_paths.index(path) + 1)  # goto is indexed from 1
    else:
        directory = os.path.dirname(path)
        paths, _ = files.supported(files.listdir(directory))
        _load_paths(paths, path)
예제 #3
0
    def _get_content(self, directory: str) -> Tuple[List[str], List[str]]:
        """Get supported content of directory.

        Returns:
            images: List of images inside the directory.
            directories: List of directories inside the directory.
        """
        show_hidden = settings.library.show_hidden.value
        paths = files.listdir(directory, show_hidden=show_hidden)
        return files.supported(paths)
예제 #4
0
 def on_text_changed(self, text: str) -> None:
     """Update completion options when text changes."""
     directory = self._get_directory(text)
     # Nothing changed
     if os.path.abspath(directory) == self._last_directory:
         return
     # Prepare
     self._last_directory = os.path.abspath(directory)
     # No completions for non-existent directory
     if not os.path.isdir(os.path.expanduser(directory)):
         return
     # Retrieve supported paths
     images, directories = files.supported(files.listdir(directory))
     # Format data
     self.set_data(
         self._create_row(os.path.join(directory, os.path.basename(path)))
         for path in images + directories)
예제 #5
0
 def on_enter(self, text: str) -> None:
     """Update trash model on enter to include any newly un-/deleted paths."""
     data = []
     for path in files.listdir(trash_manager.files_directory()):
         cmd = f":undelete {os.path.basename(path)}"
         # Get info and format it neatly
         original, date = trash_manager.trash_info(path)
         original = original.replace(os.path.expanduser("~"), "~")
         original = os.path.dirname(original)
         date = "%s-%s-%s %s:%s" % (
             date[2:4],
             date[4:6],
             date[6:8],
             date[9:11],
             date[11:13],
         )
         # Append data in column form
         data.append((cmd, original, date))
     self.set_data(data)
예제 #6
0
 def on_enter(self, text: str) -> None:
     """Update trash model on enter to include any newly un-/deleted paths."""
     data = []
     for path in files.listdir(trash_manager.files_directory()):
         cmd = f":undelete {api.completion.escape(os.path.basename(path))}"
         # Get info and format it neatly
         original, date = trash_manager.trash_info(path)
         original = original.replace(os.path.expanduser("~"), "~")
         original = os.path.dirname(original)
         date_match = self._date_re.match(date)
         if date_match is None:
             # Wrong date formatting that was used up to v0.7.0
             # TODO remove after releasing v1.0.0
             date_match = self._old_date_re.match(date)
         if date_match is not None:
             year, month, day, hour, minute, _ = date_match.groups()
             date = f"{year}-{month}-{day} {hour}:{minute}"
         else:
             date = "date unknown"
         # Append data in column form
         data.append((cmd, original, date))
     self.set_data(data)
def test_listdir_wrapper_remove_hidden(mocker):
    mocker.patch("os.listdir", return_value=[".dotfile.txt", "a.txt"])
    mocker.patch("os.path.abspath", return_value="")
    assert files.listdir("directory") == ["a.txt"]
def test_listdir_wrapper_sort(mocker):
    mocker.patch("os.listdir", return_value=["b.txt", "a.txt"])
    mocker.patch("os.path.abspath", return_value="")
    assert files.listdir("directory") == ["a.txt", "b.txt"]
def test_listdir_wrapper_returns_abspath(mocker):
    dirname, paths = "dir", ["a.txt", "b.txt"]
    mocker.patch("os.listdir", return_value=paths)
    mocker.patch("os.path.abspath", return_value=dirname)
    expected = [os.path.join(dirname, path) for path in paths]
    assert files.listdir("directory") == expected