From 03f4e7cc3473c276dfd7c7e6ad64e4dfe5b32011 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Tue, 28 Dec 2021 17:25:50 -0800 Subject: [PATCH] Fix for accented characters in album names, #561 --- osxphotos/_version.py | 2 +- osxphotos/cli.py | 8 +++++--- tests/test_cli.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 7a288a7e..aa90a84a 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.43.8" +__version__ = "0.43.9" diff --git a/osxphotos/cli.py b/osxphotos/cli.py index a7557987..02a6b7b7 100644 --- a/osxphotos/cli.py +++ b/osxphotos/cli.py @@ -63,7 +63,7 @@ from .phototemplate import PhotoTemplate, RenderOptions from .pyrepl import embed_repl from .queryoptions import QueryOptions from .uti import get_preferred_uti_extension -from .utils import expand_and_validate_filepath, load_function +from .utils import expand_and_validate_filepath, load_function, normalize_fs_path # global variable to control verbose output # set via --verbose/-V @@ -3375,11 +3375,13 @@ def cleanup_files(dest_path, files_to_keep, fileutil): Returns: tuple of (list of files deleted, list of directories deleted) """ - keepers = {str(filename).lower(): 1 for filename in files_to_keep} + keepers = { + normalize_fs_path(str(filename).lower()): 1 for filename in files_to_keep + } deleted_files = [] for p in pathlib.Path(dest_path).rglob("*"): - path = str(p).lower() + path = normalize_fs_path(str(p).lower()) if p.is_file() and path not in keepers: verbose_(f"Deleting {p}") fileutil.unlink(p) diff --git a/tests/test_cli.py b/tests/test_cli.py index 49f40f1f..03581dfa 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,6 +1,7 @@ r""" Test the command line interface (CLI) """ import os +import tempfile import pytest from click.testing import CliRunner @@ -5909,6 +5910,34 @@ def test_export_cleanup_empty_album(): assert "Deleted: 1 file" in result.output +def test_export_cleanup_accented_album_name(): + """test export with --cleanup flag and photos in album with accented unicode characters (#561)""" + import pathlib + + from osxphotos.cli import export + + runner = CliRunner() + cwd = os.getcwd() + # pylint: disable=not-context-manager + with tempfile.TemporaryDirectory() as tempdir: + result = runner.invoke(export, [os.path.join(cwd, CLI_PHOTOS_DB), ".", "-V"]) + assert result.exit_code == 0 + + result = runner.invoke( + export, + [ + os.path.join(cwd, CLI_PHOTOS_DB), + tempdir, + "-V", + "--update", + "--cleanup", + "--directory", + "{folder_album}", + ], + ) + assert "Deleted: 0 files, 0 directories" in result.output + + def test_save_load_config(): """test --save-config, --load-config""" import glob