mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-18 08:43:37 +00:00
Merge branch 'feature/ChangeIgnoreFolders' into dev
This commit is contained in:
commit
39099d91c6
2 changed files with 10 additions and 2 deletions
|
@ -1071,7 +1071,8 @@ def scantree(path, # type: AnyStr
|
|||
include=None, # type: Optional[AnyStr, List[AnyStr]]
|
||||
follow_symlinks=False, # type: bool
|
||||
filter_kind=None, # type: Optional[bool]
|
||||
recurse=True # type: bool
|
||||
recurse=True, # type: bool
|
||||
exclude_folders_with_files=None # type: Optional[List[AnyStr]]
|
||||
):
|
||||
# type: (...) -> Generator[DirEntry, None, None]
|
||||
"""Yield DirEntry objects for given path. Returns without yield if path fails sanity check
|
||||
|
@ -1082,6 +1083,7 @@ def scantree(path, # type: AnyStr
|
|||
:param follow_symlinks: Follow symlinks
|
||||
:param filter_kind: None to yield everything, True yields directories, False yields files
|
||||
:param recurse: Recursively scan the tree
|
||||
:param exclude_folders_with_files: exclude folder that contain the listed file(s)
|
||||
"""
|
||||
if isinstance(path, string_types) and path and os.path.isdir(path):
|
||||
rc_exc, rc_inc = [re.compile(rx % '|'.join(
|
||||
|
@ -1093,6 +1095,11 @@ def scantree(path, # type: AnyStr
|
|||
no_filter = any([None is filter_kind, filter_kind and is_dir, not filter_kind and is_file])
|
||||
if (rc_exc.search(entry.name), True)[not exclude] and (rc_inc.search(entry.name), True)[not include] \
|
||||
and (no_filter or (not filter_kind and is_dir and recurse)):
|
||||
if is_dir and exclude_folders_with_files and any(os.path.isfile(os.path.join(entry.path, e_f))
|
||||
for e_f in exclude_folders_with_files):
|
||||
logger.debug(f'Ignoring Folder: "{entry.path}", because it contains a exclude file'
|
||||
f' "{", ".join(exclude_folders_with_files)}"')
|
||||
continue
|
||||
if recurse and is_dir:
|
||||
for subentry in scantree(entry.path, exclude, include, follow_symlinks, filter_kind, recurse):
|
||||
yield subentry
|
||||
|
|
|
@ -352,7 +352,8 @@ def list_media_files(path):
|
|||
if [direntry for direntry in scantree(path, include=[r'\.sickgearignore'], filter_kind=False, recurse=False)]:
|
||||
logger.debug('Skipping folder "%s" because it contains ".sickgearignore"' % path)
|
||||
else:
|
||||
result = [direntry.path for direntry in scantree(path, exclude=['Extras'], filter_kind=False)
|
||||
result = [direntry.path for direntry in scantree(path, exclude=['Extras'], filter_kind=False,
|
||||
exclude_folders_with_files=['.sickgearignore'])
|
||||
if has_media_ext(direntry.name)]
|
||||
return result
|
||||
|
||||
|
|
Loading…
Reference in a new issue