def _liststore_create(self): """Create the Gtk.ListStore containing information on supported files. Return: The created liststore containing [count, filename, filesize, markup_string]. """ liststore = Gtk.ListStore(int, str, str, str) self.files, filesize = self._filelist_create() # Remove unsupported files if one isn't in the tags directory if os.getcwd() != self._app["tags"].directory: self.files = [ possible_file for possible_file in self.files if is_image(possible_file) or os.path.isdir(possible_file) ] # Add all supported files for i, fil in enumerate(self.files): markup_string = fil size = filesize[fil] marked_string = "" if os.path.islink(fil): markup_string += " → " + os.path.realpath(fil) if os.path.abspath(fil) in self._app["mark"].marked: marked_string = "[*]" if os.path.isdir(fil): markup_string = "<b>" + markup_string + "</b>" if fil in self._app["commandline"].search.results: # This is a MarkupSetting not a BoolSetting as pylint thinks # pylint: disable=no-member markup_string = settings["markup"].surround(markup_string) liststore.append([i + 1, markup_string, size, marked_string]) return liststore
def liststore_create(self): """Create the Gtk.ListStore containing information on supported files. Return: The created liststore containing [count, filename, filesize, markup_string]. """ liststore = Gtk.ListStore(int, str, str, str) self.files = self.filelist_create() # Remove unsupported files if one isn't in the tags directory if os.getcwd() != self.app["tags"].directory: self.files = [ possible_file for possible_file in self.files if is_image(possible_file) or os.path.isdir(possible_file)] # Add all supported files for i, fil in enumerate(self.files): markup_string = fil size = self.filesize[fil] marked_string = "" if os.path.islink(fil): markup_string = markup_string + " → " + os.path.realpath(fil) if os.path.abspath(fil) in self.app["mark"].marked: marked_string = "[*]" if os.path.isdir(fil): markup_string = "<b>" + markup_string + "</b>" if i in self.app["commandline"].search_positions: markup_string = self.markup + markup_string + '</span>' liststore.append([i + 1, markup_string, size, marked_string]) return liststore
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
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, ""])
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
def datalist_create(self): """Create the list of data for the file_filter model. Return: The created datalist. """ self.datalist = [] self.files = self.filelist_create() # Remove unsupported files if one isn't in the tags directory if os.getcwd() != self.vimiv.tags.directory: self.files = [ possible_file for possible_file in self.files if is_image(possible_file) or os.path.isdir(possible_file) ] # Add all supported files for i, fil in enumerate(self.files): markup_string = fil size = self.filesize[fil] is_marked = "" if os.path.islink(fil): markup_string = markup_string + " → " + os.path.realpath(fil) if os.path.abspath(fil) in self.vimiv.mark.marked: is_marked = "[*]" if os.path.isdir(fil): markup_string = "<b>" + markup_string + "</b>" if i in self.vimiv.commandline.search_positions: markup_string = self.markup + markup_string + '</span>' self.datalist.append([markup_string, size, is_marked]) return self.datalist
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
def liststore_create(self): """Create the Gtk.ListStore containing information on supported files. Return: The created liststore containing [count, filename, filesize, markup_string]. """ liststore = Gtk.ListStore(int, str, str, str) self.files = self.filelist_create() # Remove unsupported files if one isn't in the tags directory if os.getcwd() != self.app["tags"].directory: self.files = [ possible_file for possible_file in self.files if is_image(possible_file) or os.path.isdir(possible_file)] # Add all supported files for i, fil in enumerate(self.files): markup_string = fil size = self.filesize[fil] marked_string = "" if os.path.islink(fil): markup_string += " → " + os.path.realpath(fil) if os.path.abspath(fil) in self.app["mark"].marked: marked_string = "[*]" if os.path.isdir(fil): markup_string = "<b>" + markup_string + "</b>" if i in self.app["commandline"].search_positions: markup_string = self.markup + markup_string + "</span>" liststore.append([i + 1, markup_string, size, marked_string]) return liststore
def complete_trash(self, command): """Complete files in trash directory for :undelete. Args: command: The internal command to complete. """ # Get files in trash directory self.liststores["trash"][0].clear() trash_directory = \ self.app["manipulate"].trash_manager.get_files_directory() trash_files = sorted(os.listdir(trash_directory)) # Add them to completion formatted to 'undelete $FILE' for fil in trash_files: # Ensure we only complete image files as vimiv is not meant as a # general trash tool but provides this for convenience abspath = os.path.join(trash_directory, fil) if is_image(abspath): completion = "undelete %s" % (fil) self.liststores["trash"][0].append([completion, ""])
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
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, ""])
def test_is_image(self): """Check whether file is an image.""" os.chdir("testimages/") self.assertTrue(fileactions.is_image("arch_001.jpg")) self.assertFalse(fileactions.is_image("not_an_image.jpg"))