Skip to content

Commit

Permalink
Merge 788c67b into 3ad6c0d
Browse files Browse the repository at this point in the history
  • Loading branch information
gti96 committed Sep 27, 2019
2 parents 3ad6c0d + 788c67b commit 2df2e66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions elodie.py
Expand Up @@ -97,8 +97,10 @@ def _batch(debug):
help='Import the file even if it\'s already been imported.')
@click.option('--debug', default=False, is_flag=True,
help='Override the value in constants.py with True.')
@click.option('--exclude', multiple=True,
help='Exclude directory.')
@click.argument('paths', nargs=-1, type=click.Path())
def _import(destination, source, file, album_from_folder, trash, allow_duplicates, debug, paths):
def _import(destination, source, file, album_from_folder, trash, allow_duplicates, debug, paths, exclude):
"""Import files or directories by reading their EXIF and organizing them accordingly.
"""
constants.debug = debug
Expand All @@ -110,6 +112,9 @@ def _import(destination, source, file, album_from_folder, trash, allow_duplicate

files = set()
paths = set(paths)
excludeDir = set()
if exclude:
excludeDir.update(exclude)
if source:
source = _decode(source)
paths.add(source)
Expand All @@ -118,7 +123,7 @@ def _import(destination, source, file, album_from_folder, trash, allow_duplicate
for path in paths:
path = os.path.expanduser(path)
if os.path.isdir(path):
files.update(FILESYSTEM.get_all_files(path, None))
files.update(FILESYSTEM.get_all_files(path, None, excludeDir))
else:
files.add(path)

Expand Down
4 changes: 2 additions & 2 deletions elodie/filesystem.py
Expand Up @@ -85,7 +85,7 @@ def delete_directory_if_empty(self, directory_path):

return False

def get_all_files(self, path, extensions=None):
def get_all_files(self, path, extensions=None, excludeDir=set()):
"""Recursively get all files which match a path and extension.
:param str path string: Path to start recursive file listing
Expand All @@ -98,8 +98,8 @@ def get_all_files(self, path, extensions=None):
subclasses = get_all_subclasses(Base)
for cls in subclasses:
extensions.update(cls.extensions)

for dirname, dirnames, filenames in os.walk(path):
dirnames[:] = [d for d in dirnames if d not in excludeDir]
for filename in filenames:
# If file extension is in `extensions` then append to the list
if os.path.splitext(filename)[1][1:].lower() in extensions:
Expand Down

0 comments on commit 2df2e66

Please sign in to comment.