Change get_all_files behaviour
This commit is contained in:
parent
cb8a4cd24e
commit
3af848a162
|
@ -131,7 +131,7 @@ def _import(destination, source, file, album_from_folder, trash,
|
||||||
for path in paths:
|
for path in paths:
|
||||||
path = os.path.expanduser(path)
|
path = os.path.expanduser(path)
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
files.update(FILESYSTEM.get_all_files(path, None, exclude_regex_list))
|
files.update(FILESYSTEM.get_all_files(path, False, exclude_regex_list))
|
||||||
else:
|
else:
|
||||||
if not FILESYSTEM.should_exclude(path, exclude_regex_list, True):
|
if not FILESYSTEM.should_exclude(path, exclude_regex_list, True):
|
||||||
files.add(path)
|
files.add(path)
|
||||||
|
@ -267,7 +267,7 @@ def _update(album, location, time, title, paths, debug):
|
||||||
for path in paths:
|
for path in paths:
|
||||||
path = os.path.expanduser(path)
|
path = os.path.expanduser(path)
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
files.update(FILESYSTEM.get_all_files(path, None))
|
files.update(FILESYSTEM.get_all_files(path, False))
|
||||||
else:
|
else:
|
||||||
files.add(path)
|
files.add(path)
|
||||||
|
|
||||||
|
|
|
@ -84,31 +84,34 @@ class FileSystem(object):
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_all_files(self, path, extensions=None, exclude_regex_list=set()):
|
def get_all_files(self, path, extensions=False, exclude_regex_list=set()):
|
||||||
"""Recursively get all files which match a path and extension.
|
"""Recursively get all files which match a path and extension.
|
||||||
|
|
||||||
:param str path string: Path to start recursive file listing
|
:param str path string: Path to start recursive file listing
|
||||||
:param tuple(str) extensions: File extensions to include (whitelist)
|
:param tuple(str) extensions: File extensions to include (whitelist)
|
||||||
:returns: generator
|
:returns: generator
|
||||||
"""
|
"""
|
||||||
# If extensions is None then we get all supported extensions
|
# If extensions is None then we get all files
|
||||||
if not extensions:
|
# if not extensions:
|
||||||
extensions = set()
|
# extensions = set()
|
||||||
subclasses = media.get_all_subclasses()
|
# subclasses = media.get_all_subclasses()
|
||||||
for cls in subclasses:
|
# for cls in subclasses:
|
||||||
extensions.update(cls.extensions)
|
# extensions.update(cls.extensions)
|
||||||
|
|
||||||
# Create a list of compiled regular expressions to match against the file path
|
# Create a list of compiled regular expressions to match against the file path
|
||||||
compiled_regex_list = [re.compile(regex) for regex in exclude_regex_list]
|
compiled_regex_list = [re.compile(regex) for regex in exclude_regex_list]
|
||||||
for dirname, dirnames, filenames in os.walk(path):
|
for dirname, dirnames, filenames in os.walk(path):
|
||||||
|
if dirname == os.path.join(path, '.elodie'):
|
||||||
|
continue
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
# If file extension is in `extensions`
|
# If file extension is in `extensions`
|
||||||
# And if file path is not in exclude regexes
|
# And if file path is not in exclude regexes
|
||||||
# Then append to the list
|
# Then append to the list
|
||||||
filename_path = os.path.join(dirname, filename)
|
filename_path = os.path.join(dirname, filename)
|
||||||
if (
|
if (
|
||||||
os.path.splitext(filename)[1][1:].lower() in extensions and
|
extensions == False
|
||||||
not self.should_exclude(filename_path, compiled_regex_list, False)
|
or os.path.splitext(filename)[1][1:].lower() in extensions
|
||||||
|
and not self.should_exclude(filename_path, compiled_regex_list, False)
|
||||||
):
|
):
|
||||||
yield filename_path
|
yield filename_path
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ class.
|
||||||
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>
|
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
from .media import Media
|
from .media import Media
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,4 +26,11 @@ class Audio(Media):
|
||||||
super().__init__(source)
|
super().__init__(source)
|
||||||
|
|
||||||
def is_valid(self):
|
def is_valid(self):
|
||||||
return super().is_valid()
|
"""Check the file extension against valid file extensions.
|
||||||
|
|
||||||
|
The list of valid file extensions come from self.extensions.
|
||||||
|
|
||||||
|
:returns: bool
|
||||||
|
"""
|
||||||
|
source = self.source
|
||||||
|
return os.path.splitext(source)[1][1:].lower() in self.extensions
|
||||||
|
|
|
@ -168,14 +168,8 @@ class Media():
|
||||||
|
|
||||||
|
|
||||||
def is_valid(self):
|
def is_valid(self):
|
||||||
"""Check the file extension against valid file extensions.
|
# Disable extension check
|
||||||
|
return True
|
||||||
The list of valid file extensions come from self.extensions.
|
|
||||||
|
|
||||||
:returns: bool
|
|
||||||
"""
|
|
||||||
source = self.source
|
|
||||||
return os.path.splitext(source)[1][1:].lower() in self.extensions
|
|
||||||
|
|
||||||
|
|
||||||
def set_album_from_folder(self, path):
|
def set_album_from_folder(self, path):
|
||||||
|
|
|
@ -33,4 +33,11 @@ class Video(Media):
|
||||||
|
|
||||||
|
|
||||||
def is_valid(self):
|
def is_valid(self):
|
||||||
return super().is_valid()
|
"""Check the file extension against valid file extensions.
|
||||||
|
|
||||||
|
The list of valid file extensions come from self.extensions.
|
||||||
|
|
||||||
|
:returns: bool
|
||||||
|
"""
|
||||||
|
source = self.source
|
||||||
|
return os.path.splitext(source)[1][1:].lower() in self.extensions
|
||||||
|
|
|
@ -25,7 +25,7 @@ def main(argv):
|
||||||
for path in paths:
|
for path in paths:
|
||||||
path = os.path.expanduser(path)
|
path = os.path.expanduser(path)
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
for source in filesystem.get_all_files(path, None):
|
for source in filesystem.get_all_files(path, False):
|
||||||
status = add_original_name(source, subclasses)
|
status = add_original_name(source, subclasses)
|
||||||
result.append((_decode(source), status))
|
result.append((_decode(source), status))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue