Simplify is_subdir_of_any_in_list and the test that uses it

Following the comments from sampsyo in #2494
This commit is contained in:
Antonio Larrosa 2017-03-27 00:20:44 +02:00
parent 47cc959127
commit 35810df985

View file

@ -1473,10 +1473,8 @@ def is_subdir_of_any_in_list(path, dirs):
"""Returns True if path os a subdirectory of any directory in dirs
(a list). In other case, returns False.
"""
for d in dirs:
if path.startswith(d + b'/'):
return True
return False
ancestors = ancestry(path)
return any(d in ancestors for d in dirs)
def albums_in_dir(path):
@ -1498,10 +1496,9 @@ def albums_in_dir(path):
# and add the current directory. If so, just add the directory
# and move on to the next directory. If not, stop collapsing.
if collapse_paths:
if (not collapse_pat and collapse_paths[0] in ancestry(root)) or \
if (is_subdir_of_any_in_list(root, collapse_paths)) or \
(collapse_pat and
collapse_pat.match(os.path.basename(root))) or \
is_subdir_of_any_in_list(root, collapse_paths):
collapse_pat.match(os.path.basename(root))):
# Still collapsing.
collapse_paths.append(root)
collapse_items += items