mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-03-09 21:24:36 +00:00
[#168 state:fixed] Made the file collection phase cancellable.
This commit is contained in:
parent
577cee1a38
commit
99e3c34060
@ -371,9 +371,9 @@ class DupeGuru(RegistrableApplication, Broadcaster):
|
||||
def do(j):
|
||||
j.set_progress(0, tr("Collecting files to scan"))
|
||||
if self.scanner.scan_type == scanner.ScanType.Folders:
|
||||
files = list(self.directories.get_folders())
|
||||
files = list(self.directories.get_folders(j))
|
||||
else:
|
||||
files = list(self.directories.get_files())
|
||||
files = list(self.directories.get_files(j))
|
||||
if self.options['ignore_hardlink_matches']:
|
||||
files = self._remove_hardlink_dupes(files)
|
||||
logging.info('Scanning %d files' % len(files))
|
||||
|
@ -9,6 +9,7 @@
|
||||
from xml.etree import ElementTree as ET
|
||||
import logging
|
||||
|
||||
from jobprogress import job
|
||||
from hscommon import io
|
||||
from hscommon.path import Path
|
||||
from hscommon.util import FileOrPath
|
||||
@ -54,7 +55,8 @@ class Directories:
|
||||
if path[-1].startswith('.'): # hidden
|
||||
return DirectoryState.Excluded
|
||||
|
||||
def _get_files(self, from_path):
|
||||
def _get_files(self, from_path, j):
|
||||
j.check_if_cancelled()
|
||||
state = self.get_state(from_path)
|
||||
if state == DirectoryState.Excluded:
|
||||
# Recursively get files from folders with lots of subfolder is expensive. However, there
|
||||
@ -75,15 +77,16 @@ class Directories:
|
||||
# it's possible that a folder (bundle) gets into the file list. in that case, we don't want to recurse into it
|
||||
subfolders = [p for p in subpaths if not io.islink(p) and io.isdir(p) and p not in filepaths]
|
||||
for subfolder in subfolders:
|
||||
for file in self._get_files(subfolder):
|
||||
for file in self._get_files(subfolder, j):
|
||||
yield file
|
||||
except (EnvironmentError, fs.InvalidPath):
|
||||
pass
|
||||
|
||||
def _get_folders(self, from_folder):
|
||||
def _get_folders(self, from_folder, j):
|
||||
j.check_if_cancelled()
|
||||
try:
|
||||
for subfolder in from_folder.subfolders:
|
||||
for folder in self._get_folders(subfolder):
|
||||
for folder in self._get_folders(subfolder, j):
|
||||
yield folder
|
||||
state = self.get_state(from_folder.path)
|
||||
if state != DirectoryState.Excluded:
|
||||
@ -118,23 +121,23 @@ class Directories:
|
||||
except EnvironmentError:
|
||||
return []
|
||||
|
||||
def get_files(self):
|
||||
def get_files(self, j=job.nulljob):
|
||||
"""Returns a list of all files that are not excluded.
|
||||
|
||||
Returned files also have their 'is_ref' attr set.
|
||||
"""
|
||||
for path in self._dirs:
|
||||
for file in self._get_files(path):
|
||||
for file in self._get_files(path, j):
|
||||
yield file
|
||||
|
||||
def get_folders(self):
|
||||
def get_folders(self, j=job.nulljob):
|
||||
"""Returns a list of all folders that are not excluded.
|
||||
|
||||
Returned folders also have their 'is_ref' attr set.
|
||||
"""
|
||||
for path in self._dirs:
|
||||
from_folder = fs.Folder(path)
|
||||
for folder in self._get_folders(from_folder):
|
||||
for folder in self._get_folders(from_folder, j):
|
||||
yield folder
|
||||
|
||||
def get_state(self, path):
|
||||
|
@ -1,4 +1,4 @@
|
||||
jobprogress>=1.0.1
|
||||
jobprogress>=1.0.2
|
||||
Send2Trash3k>=1.2.0
|
||||
hsaudiotag3k>=1.1.1
|
||||
pytest>=2.0.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user