mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-03-10 05:34: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):
|
def do(j):
|
||||||
j.set_progress(0, tr("Collecting files to scan"))
|
j.set_progress(0, tr("Collecting files to scan"))
|
||||||
if self.scanner.scan_type == scanner.ScanType.Folders:
|
if self.scanner.scan_type == scanner.ScanType.Folders:
|
||||||
files = list(self.directories.get_folders())
|
files = list(self.directories.get_folders(j))
|
||||||
else:
|
else:
|
||||||
files = list(self.directories.get_files())
|
files = list(self.directories.get_files(j))
|
||||||
if self.options['ignore_hardlink_matches']:
|
if self.options['ignore_hardlink_matches']:
|
||||||
files = self._remove_hardlink_dupes(files)
|
files = self._remove_hardlink_dupes(files)
|
||||||
logging.info('Scanning %d files' % len(files))
|
logging.info('Scanning %d files' % len(files))
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
from xml.etree import ElementTree as ET
|
from xml.etree import ElementTree as ET
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from jobprogress import job
|
||||||
from hscommon import io
|
from hscommon import io
|
||||||
from hscommon.path import Path
|
from hscommon.path import Path
|
||||||
from hscommon.util import FileOrPath
|
from hscommon.util import FileOrPath
|
||||||
@ -54,7 +55,8 @@ class Directories:
|
|||||||
if path[-1].startswith('.'): # hidden
|
if path[-1].startswith('.'): # hidden
|
||||||
return DirectoryState.Excluded
|
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)
|
state = self.get_state(from_path)
|
||||||
if state == DirectoryState.Excluded:
|
if state == DirectoryState.Excluded:
|
||||||
# Recursively get files from folders with lots of subfolder is expensive. However, there
|
# 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
|
# 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]
|
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 subfolder in subfolders:
|
||||||
for file in self._get_files(subfolder):
|
for file in self._get_files(subfolder, j):
|
||||||
yield file
|
yield file
|
||||||
except (EnvironmentError, fs.InvalidPath):
|
except (EnvironmentError, fs.InvalidPath):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _get_folders(self, from_folder):
|
def _get_folders(self, from_folder, j):
|
||||||
|
j.check_if_cancelled()
|
||||||
try:
|
try:
|
||||||
for subfolder in from_folder.subfolders:
|
for subfolder in from_folder.subfolders:
|
||||||
for folder in self._get_folders(subfolder):
|
for folder in self._get_folders(subfolder, j):
|
||||||
yield folder
|
yield folder
|
||||||
state = self.get_state(from_folder.path)
|
state = self.get_state(from_folder.path)
|
||||||
if state != DirectoryState.Excluded:
|
if state != DirectoryState.Excluded:
|
||||||
@ -118,23 +121,23 @@ class Directories:
|
|||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_files(self):
|
def get_files(self, j=job.nulljob):
|
||||||
"""Returns a list of all files that are not excluded.
|
"""Returns a list of all files that are not excluded.
|
||||||
|
|
||||||
Returned files also have their 'is_ref' attr set.
|
Returned files also have their 'is_ref' attr set.
|
||||||
"""
|
"""
|
||||||
for path in self._dirs:
|
for path in self._dirs:
|
||||||
for file in self._get_files(path):
|
for file in self._get_files(path, j):
|
||||||
yield file
|
yield file
|
||||||
|
|
||||||
def get_folders(self):
|
def get_folders(self, j=job.nulljob):
|
||||||
"""Returns a list of all folders that are not excluded.
|
"""Returns a list of all folders that are not excluded.
|
||||||
|
|
||||||
Returned folders also have their 'is_ref' attr set.
|
Returned folders also have their 'is_ref' attr set.
|
||||||
"""
|
"""
|
||||||
for path in self._dirs:
|
for path in self._dirs:
|
||||||
from_folder = fs.Folder(path)
|
from_folder = fs.Folder(path)
|
||||||
for folder in self._get_folders(from_folder):
|
for folder in self._get_folders(from_folder, j):
|
||||||
yield folder
|
yield folder
|
||||||
|
|
||||||
def get_state(self, path):
|
def get_state(self, path):
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
jobprogress>=1.0.1
|
jobprogress>=1.0.2
|
||||||
Send2Trash3k>=1.2.0
|
Send2Trash3k>=1.2.0
|
||||||
hsaudiotag3k>=1.1.1
|
hsaudiotag3k>=1.1.1
|
||||||
pytest>=2.0.0
|
pytest>=2.0.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user