From b455bd4c4a4a55014af368fb22d5c2ed44188c6d Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Fri, 15 May 2020 13:57:12 -0700 Subject: [PATCH] Added label and label_normalized to template system, closes #130 --- osxphotos/__main__.py | 6 +++--- osxphotos/photoinfo/photoinfo.py | 23 +++++++++++------------ osxphotos/photoinfo/template.py | 2 ++ tests/test_template.py | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/osxphotos/__main__.py b/osxphotos/__main__.py index a16c94dc..240b9988 100644 --- a/osxphotos/__main__.py +++ b/osxphotos/__main__.py @@ -21,7 +21,7 @@ import osxphotos from ._constants import _EXIF_TOOL_URL, _PHOTOS_4_VERSION, _UNKNOWN_PLACE from ._version import __version__ from .exiftool import get_exiftool_path -from .template import TEMPLATE_SUBSTITUTIONS, TEMPLATE_SUBSTITUTIONS_MULTI_VALUED +from .photoinfo.template import TEMPLATE_SUBSTITUTIONS, TEMPLATE_SUBSTITUTIONS_MULTI_VALUED from .utils import _copy_file, create_path_by_date @@ -1695,9 +1695,9 @@ def export_photo( dest_paths = [] for dirname in dirnames: dirname = sanitize_filepath(dirname, platform="auto") - if not is_valid_filepath(dirname, platform="auto"): - raise ValueError(f"Invalid file path: {dirname}") dest_path = os.path.join(dest, dirname) + if not is_valid_filepath(dest_path, platform="auto"): + raise ValueError(f"Invalid file path: '{dest_path}'") if not os.path.isdir(dest_path): os.makedirs(dest_path) dest_paths.append(dest_path) diff --git a/osxphotos/photoinfo/photoinfo.py b/osxphotos/photoinfo/photoinfo.py index a2b84343..aaa94edd 100644 --- a/osxphotos/photoinfo/photoinfo.py +++ b/osxphotos/photoinfo/photoinfo.py @@ -18,8 +18,6 @@ from pprint import pformat import yaml from mako.template import Template - - from .._constants import ( _MAX_IPTC_KEYWORD_LEN, _MOVIE_TYPE, @@ -35,20 +33,20 @@ from ..albuminfo import AlbumInfo from ..datetime_formatter import DateTimeFormatter from ..exiftool import ExifTool from ..placeinfo import PlaceInfo4, PlaceInfo5 -from ..template import ( - MULTI_VALUE_SUBSTITUTIONS, - TEMPLATE_SUBSTITUTIONS, - TEMPLATE_SUBSTITUTIONS_MULTI_VALUED, -) from ..utils import ( - _hardlink_file, _copy_file, _export_photo_uuid_applescript, _get_resource_loc, + _hardlink_file, dd_to_dms_str, findfiles, get_preferred_uti_extension, ) +from .template import ( + MULTI_VALUE_SUBSTITUTIONS, + TEMPLATE_SUBSTITUTIONS, + TEMPLATE_SUBSTITUTIONS_MULTI_VALUED, +) class PhotoInfo: @@ -964,13 +962,11 @@ class PhotoInfo: # for explanation of regex see https://regex101.com/r/4JJg42/1 # pylint: disable=anomalous-backslash-in-string regex = r"(?