This commit is contained in:
Rhet Turnbull
2021-09-13 22:14:48 -07:00
parent 4f7642b1d2
commit 93bf0c210c
59 changed files with 227 additions and 73 deletions

View File

@@ -1,3 +1,3 @@
""" version info """
__version__ = "0.42.80"
__version__ = "0.42.81"

View File

@@ -56,7 +56,7 @@ from ..photokit import (
)
from ..phototemplate import RenderOptions
from ..uti import get_preferred_uti_extension
from ..utils import findfiles, lineno, noop
from ..utils import findfiles, lineno, noop, normalize_fs_path
# retry if use_photos_export fails the first time (which sometimes it does)
MAX_PHOTOSCRIPT_RETRIES = 3
@@ -686,9 +686,12 @@ def export2(
count = 0
if not update and increment and not overwrite:
dest_files = findfiles(f"{dest_original.stem}*", str(dest_original.parent))
dest_files = [pathlib.Path(f).stem.lower() for f in dest_files]
# paths need to be normalized for unicode as filesystem returns unicode in NFD form
dest_files = [
normalize_fs_path(pathlib.Path(f).stem.lower()) for f in dest_files
]
dest_new = dest_original.stem
while dest_new.lower() in dest_files:
while normalize_fs_path(dest_new.lower()) in dest_files:
count += 1
dest_new = f"{dest_original.stem} ({count})"
dest_original = dest_original.parent / f"{dest_new}{dest_original.suffix}"
@@ -708,12 +711,15 @@ def export2(
if export_edited:
if not update and increment and not overwrite:
dest_files = findfiles(f"{dest_edited.stem}*", str(dest_edited.parent))
dest_files = [pathlib.Path(f).stem.lower() for f in dest_files]
# paths need to be normalized for unicode as filesystem returns unicode in NFD form
dest_files = [
normalize_fs_path(pathlib.Path(f).stem.lower()) for f in dest_files
]
dest_new = dest_edited.stem
if count:
# incremented above when checking original destination
dest_new = f"{dest_new} ({count})"
while dest_new.lower() in dest_files:
while normalize_fs_path(dest_new.lower()) in dest_files:
count += 1
dest_new = f"{dest.stem} ({count})"
dest_edited = dest_edited.parent / f"{dest_new}{dest_edited.suffix}"

View File

@@ -19,6 +19,8 @@ from plistlib import load as plistload
from typing import Callable
import CoreFoundation
import objc
from Foundation import NSString
from ._constants import UNICODE_FORMAT
@@ -263,6 +265,13 @@ def list_photo_libraries():
return lib_list
def normalize_fs_path(path: str) -> str:
"""Normalize filesystem paths with unicode in them"""
with objc.autorelease_pool():
normalized_path = NSString.fileSystemRepresentation(path)
return normalized_path.decode('utf8')
def findfiles(pattern, path_):
"""Returns list of filenames from path_ matched by pattern
shell pattern. Matching is case-insensitive.
@@ -271,8 +280,11 @@ def findfiles(pattern, path_):
return []
# See: https://gist.github.com/techtonik/5694830
# paths need to be normalized for unicode as filesystem returns unicode in NFD form
pattern = normalize_fs_path(pattern)
rule = re.compile(fnmatch.translate(pattern), re.IGNORECASE)
return [name for name in os.listdir(path_) if rule.match(name)]
files = [normalize_fs_path(p) for p in os.listdir(path_)]
return [name for name in files if rule.match(name)]
def _open_sql_file(dbname):