remove extra join

This commit is contained in:
Antonio J. Delgado 2022-05-17 09:04:37 +03:00
parent e42d92f231
commit 18c6d8e44b

View file

@ -49,7 +49,7 @@ class CustomFormatter(logging.Formatter):
class image_classifier: class image_classifier:
def __init__(self, debug_level, log_file, faces_directory, directory, no_move, def __init__(self, debug_level, log_file, faces_directory, directory, no_move,
people_folder): people_folder, recursive):
''' Initial function called when object is created ''' ''' Initial function called when object is created '''
self.debug_level = debug_level self.debug_level = debug_level
if log_file is None: if log_file is None:
@ -62,12 +62,34 @@ class image_classifier:
self.known_people = self.load_known_people() self.known_people = self.load_known_people()
self.no_move = no_move self.no_move = no_move
self.people_folder = people_folder self.people_folder = people_folder
self.recursive = recursive
if os.access(directory, os.R_OK): if os.access(directory, os.R_OK):
with os.scandir(directory) as directory_item: if self.recursive:
for entry in directory_item: entries = self.recursive_scandir(directory)
if not entry.name.startswith('.') and entry.is_file(): else:
self.process_file(os.path.join(directory, entry.name)) entries = os.scandir(directory)
for entry in entries:
if not entry.name.startswith('.') and entry.is_file():
self.process_file(entry.path)
def recursive_scandir(path, ignore_hidden_files=True):
files = []
try:
for file in os.scandir(path):
if not file.name.startswith('.'):
if file.is_file():
files.append(file)
elif file.is_dir(follow_symlinks=False):
more_files = recursive_scandir(file.path,
ignore_hidden_files=ignore_hidden_files
)
if more_files:
files = files + more_files
except PermissionError as error:
self._log.warning(f"Permission denied accessing folder '{path}'")
return files
def process_metadata(self, file): def process_metadata(self, file):
self.metadata = pyexiv2.ImageMetadata(file) self.metadata = pyexiv2.ImageMetadata(file)
@ -277,10 +299,12 @@ identify people. Filename would be used as the name for the person. Just one per
@click.option('--people-folder', '-p', help="Define a folder for people's folders and copy \ @click.option('--people-folder', '-p', help="Define a folder for people's folders and copy \
pictures to each person's folder. Be sure to have deduplication in the filesystem to avoid using \ pictures to each person's folder. Be sure to have deduplication in the filesystem to avoid using \
too much storage.") too much storage.")
@click.option('--recursive', '-r', is_flag=True, help='Recursively search for files in the provided --directory')
@click_config_file.configuration_option() @click_config_file.configuration_option()
def __main__(debug_level, log_file, faces_directory, directory, no_move, people_folder): def __main__(debug_level, log_file, faces_directory, directory, no_move,
people_folder, recursive):
return image_classifier(debug_level, log_file, faces_directory, directory, no_move, return image_classifier(debug_level, log_file, faces_directory, directory, no_move,
people_folder) people_folder, recursive)
if __name__ == "__main__": if __name__ == "__main__":