Fix for accented characters in album names, #561

This commit is contained in:
Rhet Turnbull
2021-12-28 17:25:50 -08:00
parent 0e54a08ae0
commit 03f4e7cc34
3 changed files with 35 additions and 4 deletions

View File

@@ -1,3 +1,3 @@
""" version info """ """ version info """
__version__ = "0.43.8" __version__ = "0.43.9"

View File

@@ -63,7 +63,7 @@ from .phototemplate import PhotoTemplate, RenderOptions
from .pyrepl import embed_repl from .pyrepl import embed_repl
from .queryoptions import QueryOptions from .queryoptions import QueryOptions
from .uti import get_preferred_uti_extension 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 # global variable to control verbose output
# set via --verbose/-V # set via --verbose/-V
@@ -3375,11 +3375,13 @@ def cleanup_files(dest_path, files_to_keep, fileutil):
Returns: Returns:
tuple of (list of files deleted, list of directories deleted) 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 = [] deleted_files = []
for p in pathlib.Path(dest_path).rglob("*"): 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: if p.is_file() and path not in keepers:
verbose_(f"Deleting {p}") verbose_(f"Deleting {p}")
fileutil.unlink(p) fileutil.unlink(p)

View File

@@ -1,6 +1,7 @@
r""" Test the command line interface (CLI) """ r""" Test the command line interface (CLI) """
import os import os
import tempfile
import pytest import pytest
from click.testing import CliRunner from click.testing import CliRunner
@@ -5909,6 +5910,34 @@ def test_export_cleanup_empty_album():
assert "Deleted: 1 file" in result.output 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(): def test_save_load_config():
"""test --save-config, --load-config""" """test --save-config, --load-config"""
import glob import glob