コード例 #1
0
ファイル: helpers_test.py プロジェクト: sahwar/vimiv
 def test_listdir_wrapper(self):
     """Check the listdir_wrapper (hidden/no_hidden)."""
     no_hidden_files = helpers.listdir_wrapper("tmp_testdir", False)
     hidden_files = helpers.listdir_wrapper("tmp_testdir", True)
     self.assertEqual(len(no_hidden_files), 1)
     self.assertEqual(len(hidden_files), 2)
     self.assertEqual(hidden_files, sorted(hidden_files))
コード例 #2
0
ファイル: library.py プロジェクト: karlch/vimiv
    def filelist_create(self, directory="."):
        """Create a filelist from all files in directory.

        Args:
            directory: Directory of which the filelist is created.
        """
        # Get data from ls -lh and parse it correctly
        files = listdir_wrapper(directory, self.show_hidden)
        self.filesize = {}
        for fil in files:
            # Catch broken symbolic links
            if os.path.islink(fil) and \
                    not os.path.exists(os.path.realpath(fil)):
                continue
            # Number of images in directory as filesize
            if os.path.isdir(fil):
                try:
                    subfiles = listdir_wrapper(fil, self.show_hidden)
                    # Necessary to keep acceptable speed in library
                    many = False
                    if len(subfiles) > self.file_check_amount:
                        many = True
                    subfiles = [subfile
                                for subfile in subfiles[:self.file_check_amount]
                                if is_image(os.path.join(fil, subfile))]
                    amount = str(len(subfiles))
                    if subfiles and many:
                        amount += "+"
                    self.filesize[fil] = amount
                except:
                    self.filesize[fil] = "N/A"
            else:
                self.filesize[fil] = sizeof_fmt(os.path.getsize(fil))

        return files
コード例 #3
0
ファイル: library.py プロジェクト: aszlig/vimiv
    def filelist_create(self, directory="."):
        """Create a filelist from all files in directory.

        Args:
            directory: Directory of which the filelist is created.
        """
        # Get data from ls -lh and parse it correctly
        files = listdir_wrapper(directory, self.show_hidden)
        self.filesize = {}
        for fil in files:
            # Number of images in directory as filesize
            if os.path.isdir(fil):
                try:
                    subfiles = listdir_wrapper(fil, self.show_hidden)
                    # Necessary to keep acceptable speed in library
                    many = False
                    if len(subfiles) > self.file_check_amount:
                        many = True
                    subfiles = [
                        subfile
                        for subfile in subfiles[:self.file_check_amount]
                        if is_image(os.path.join(fil, subfile))
                    ]
                    amount = str(len(subfiles))
                    if subfiles and many:
                        amount += "+"
                    self.filesize[fil] = amount
                except:
                    self.filesize[fil] = "N/A"
            else:
                self.filesize[fil] = sizeof_fmt(os.path.getsize(fil))

        return files
コード例 #4
0
ファイル: helpers_test.py プロジェクト: karlch/vimiv
 def test_listdir_wrapper(self):
     """Check the listdir_wrapper (hidden/no_hidden)."""
     no_hidden_files = helpers.listdir_wrapper("tmp_testdir", False)
     hidden_files = helpers.listdir_wrapper("tmp_testdir", True)
     self.assertEqual(len(no_hidden_files), 1)
     self.assertEqual(len(hidden_files), 2)
     self.assertEqual(hidden_files, sorted(hidden_files))
コード例 #5
0
ファイル: completions.py プロジェクト: woefe/vimiv
    def complete_path(self, path):
        """Complete paths.

        Args:
            path: (Partial) name of the path to run completion on.
        Return:
            List containing formatted matching paths.
        """
        self.liststores["path"][0].clear()
        # Directory of the path, default to .
        directory = os.path.dirname(path) if os.path.dirname(path) else path
        if not os.path.exists(os.path.expanduser(directory)) \
                or not os.path.isdir(os.path.expanduser(directory)):
            directory = "."
        # /dev causes havoc
        if directory == "/dev":
            return
        # Files in that directory
        files = listdir_wrapper(directory, self.app["library"].show_hidden)
        # Format them neatly depending on directory and type
        for fil in files:
            fil = os.path.join(directory, fil)
            # Directory
            if os.path.isdir(os.path.expanduser(fil)):
                self.liststores["path"][0].append([fil + "/", ""])
            # Acceptable file
            elif is_image(fil):
                self.liststores["path"][0].append([fil, ""])
コード例 #6
0
 def _on_paths_changed(self, app, transform):
     """Reload paths image and/or thumbnail when paths have changed."""
     if self._app.get_paths():
         # Get all files in directory again
         focused_path = self._app.get_pos(True)
         decremented_index = max(0, self._app.get_pos() - 1)
         directory = os.path.dirname(focused_path)
         files = [
             os.path.join(directory, fil)
             for fil in listdir_wrapper(directory)
         ]
         self._app.populate(files)
         # Reload thumbnail
         if self.thumbnail.toggled:
             self.thumbnail.on_paths_changed()
         # Refocus the path
         if focused_path in self._app.get_paths():
             index = self._app.get_paths().index(focused_path)
         # Stay as close as possible
         else:
             index = min(decremented_index, len(self._app.get_paths()) - 1)
         if self.thumbnail.toggled:
             self.thumbnail.move_to_pos(index)
         else:
             self._app["eventhandler"].set_num_str(index + 1)
             self.image.move_pos()
         self._app["statusbar"].update_info()
     # We need to check again as populate was called
     if not self._app.get_paths():
         self.hide()
コード例 #7
0
    def complete_path(self, path, external_command=False):
        """Complete paths.

        Args:
            path: (Partial) name of the path to run completion on.
            external_command: If True, path comes from an external command.
        Return: List containing formatted matching paths.
        """
        # Directory of the path, default to .
        directory = os.path.dirname(path) if os.path.dirname(path) else path
        if not os.path.exists(os.path.expanduser(directory)):
            directory = "."
        # Files in that directory
        files = listdir_wrapper(directory, self.show_hidden)
        # Format them neatly depending on directory and type
        filelist = []
        for fil in files:
            if directory != "." or not external_command:
                fil = os.path.join(directory, fil)
            # Directory
            if os.path.isdir(os.path.expanduser(fil)):
                filelist.append(fil + "/")
            # Acceptable file
            elif is_image(fil) or external_command:
                filelist.append(fil)
        return filelist
コード例 #8
0
def populate_single(arg, recursive):
    """Populate a complete filelist if only one path is given.

    Args:
        arg: Single path given.
        recursive: If True search path recursively for images.
    """
    if os.path.isfile(arg):
        # Use parent directory
        directory = os.path.dirname(os.path.abspath(arg))
        basename = os.path.basename(os.path.abspath(arg))
        args = listdir_wrapper(directory)
        # Set the argument to the beginning of the list
        pos = args.index(basename)
        args = args[pos:] + args[:pos]
        for i, arg in enumerate(args):
            args[i] = os.path.join(directory, arg)

        return 0, args  # Success and the created filelist

    elif os.path.isdir(arg):
        if recursive:
            args = sorted(recursive_search(arg))
            return 0, args
        else:
            return 1, arg  # Failure and the directory

    else:
        return 1, "."  # Does not exist, use current directory
コード例 #9
0
 def complete_tag(self):
     """Append the available tag names to an internal tag command."""
     tags = listdir_wrapper(os.path.expanduser("~/.vimiv/Tags"),
                            self.show_hidden)
     completions = []
     for tag in tags:
         completions.append(self.command.split()[0] + " " + tag)
     return completions
コード例 #10
0
ファイル: completions.py プロジェクト: karlch/vimiv
    def complete_tag(self, command):
        """Append the available tag names to an internal tag command.

        Args:
            command: The internal command to complete.
        """
        self.liststores["tag"][0].clear()
        tags = listdir_wrapper(self.app["tags"].directory,
                               self.app["library"].show_hidden)
        for tag in tags:
            self.liststores["tag"][0].append([command.split()[0] + " " + tag,
                                              ""])
コード例 #11
0
ファイル: completions.py プロジェクト: woefe/vimiv
    def complete_tag(self, command):
        """Append the available tag names to an internal tag command.

        Args:
            command: The internal command to complete.
        """
        self.liststores["tag"][0].clear()
        tags = listdir_wrapper(self.app["tags"].directory,
                               self.app["library"].show_hidden)
        for tag in tags:
            self.liststores["tag"][0].append(
                [command.split()[0] + " " + tag, ""])
コード例 #12
0
    def _complete_tag(self, command):
        """Append the available tag names to an internal tag command.

        Args:
            command: The internal command to complete.
        """
        self._liststores["tag"][0].clear()
        tags = listdir_wrapper(self._app["tags"].directory,
                               settings["show_hidden"].get_value())
        for tag in tags:
            self._liststores["tag"][0].append([command.split()[0] + " " + tag,
                                               ""])
コード例 #13
0
    def _filelist_create(self, directory="."):
        """Create a filelist from all files in directory.

        Args:
            directory: Directory of which the filelist is created.
        Return:
            filelist, filesize: List of files, dictionary with filesize info
        """
        # Get data from ls -lh and parse it correctly
        files = listdir_wrapper(directory, settings["show_hidden"].get_value())
        filesize = {}
        file_check_amount = settings["file_check_amount"].get_value()
        for fil in files:
            # Catch broken symbolic links
            if os.path.islink(fil) and \
                    not os.path.exists(os.path.realpath(fil)):
                continue
            # Number of images in directory as filesize
            if os.path.isdir(fil):
                try:
                    subfiles = listdir_wrapper(
                        fil, settings["show_hidden"].get_value())
                    # Necessary to keep acceptable speed in library
                    many = False
                    if len(subfiles) > file_check_amount:
                        many = True
                    subfiles = [
                        sub for sub in subfiles[:file_check_amount]
                        if is_image(os.path.join(fil, sub))
                    ]
                    amount = str(len(subfiles))
                    if subfiles and many:
                        amount += "+"
                    filesize[fil] = amount
                except PermissionError:
                    filesize[fil] = "N/A"
            else:
                filesize[fil] = sizeof_fmt(os.path.getsize(fil))

        return files, filesize
コード例 #14
0
ファイル: completions.py プロジェクト: karlch/vimiv
    def complete_path(self, path):
        """Complete paths.

        Args:
            path: (Partial) name of the path to run completion on.
        Return:
            List containing formatted matching paths.
        """
        self.liststores["path"][0].clear()
        # Directory of the path, default to .
        directory = os.path.dirname(path) if os.path.dirname(path) else path
        if not os.path.exists(os.path.expanduser(directory)):
            directory = "."
        # Files in that directory
        files = listdir_wrapper(directory, self.app["library"].show_hidden)
        # Format them neatly depending on directory and type
        for fil in files:
            fil = os.path.join(directory, fil)
            # Directory
            if os.path.isdir(os.path.expanduser(fil)):
                self.liststores["path"][0].append([fil + "/", ""])
            # Acceptable file
            elif is_image(fil):
                self.liststores["path"][0].append([fil, ""])
コード例 #15
0
ファイル: fileactions.py プロジェクト: woefe/vimiv
def populate_single(arg, recursive):
    """Populate a complete filelist if only one path is given.

    Args:
        arg: Single path given.
        recursive: If True search path recursively for images.
    Return:
        Generated list of paths.
    """
    paths = []
    if os.path.isfile(arg):
        # Use parent directory
        directory = os.path.dirname(arg)
        if not directory:  # Default to current directory
            directory = "./"
        basename = os.path.basename(arg)
        paths = listdir_wrapper(directory)
        # Set the argument to the beginning of the list
        pos = paths.index(basename)
        paths = [os.path.join(directory, path)
                 for path in paths[pos:] + paths[:pos]]
    elif os.path.isdir(arg) and recursive:
        paths = sorted(recursive_search(arg))
    return paths
コード例 #16
0
ファイル: fileactions.py プロジェクト: karlch/vimiv
def populate_single(arg, recursive):
    """Populate a complete filelist if only one path is given.

    Args:
        arg: Single path given.
        recursive: If True search path recursively for images.
    Return:
        Generated list of paths.
    """
    paths = []
    if os.path.isfile(arg):
        # Use parent directory
        directory = os.path.dirname(arg)
        if not directory:  # Default to current directory
            directory = "./"
        basename = os.path.basename(arg)
        paths = listdir_wrapper(directory)
        # Set the argument to the beginning of the list
        pos = paths.index(basename)
        paths = [os.path.join(directory, path)
                 for path in paths[pos:] + paths[:pos]]
    elif os.path.isdir(arg) and recursive:
        paths = sorted(recursive_search(arg))
    return paths