Fixed unnecessary warning for long keywords, issue #365

This commit is contained in:
Rhet Turnbull 2021-02-07 05:39:20 -08:00
parent addd952aa3
commit f8616acf16
4 changed files with 13 additions and 20 deletions

View File

@ -1,3 +1,3 @@
""" version info """
__version__ = "0.40.8"
__version__ = "0.40.9"

View File

@ -562,11 +562,11 @@ def export2(
if export_db is None:
export_db = ExportDBNoOp()
if verbose is None:
verbose = noop
elif not callable(verbose):
if verbose and not callable(verbose):
raise TypeError("verbose must be callable")
self._verbose = verbose
if verbose is None:
verbose = self._verbose
# suffix to add to edited files
# e.g. name will be filename_edited.jpg
@ -1501,8 +1501,8 @@ def _exiftool_dict(
if len(long_str) > _MAX_IPTC_KEYWORD_LEN
]
if long_keywords:
logging.warning(
f"Some keywords exceed max IPTC Keyword length of {_MAX_IPTC_KEYWORD_LEN}: {long_keywords}"
self._verbose(
f"Warning: some keywords exceed max IPTC Keyword length of {_MAX_IPTC_KEYWORD_LEN} (exiftool will truncate these): {long_keywords}"
)
keyword_list.extend(rendered_keywords)
@ -1781,17 +1781,6 @@ def _xmp_sidecar(
if _OSXPHOTOS_NONE_SENTINEL not in keyword
]
# check to see if any keywords too long
long_keywords = [
long_str
for long_str in rendered_keywords
if len(long_str) > _MAX_IPTC_KEYWORD_LEN
]
if long_keywords:
logging.warning(
f"Some keywords exceed max IPTC Keyword length of {_MAX_IPTC_KEYWORD_LEN}: {long_keywords}"
)
keyword_list.extend(rendered_keywords)
# remove duplicates

View File

@ -70,6 +70,7 @@ class PhotoInfo:
self._uuid = uuid
self._info = info
self._db = db
self._verbose = self._db._verbose
@property
def filename(self):

View File

@ -429,7 +429,7 @@ def test_exiftool_json_sidecar_ignore_date_modified(photosdb):
assert json_got == json_expected
def test_exiftool_json_sidecar_keyword_template_long(caplog, photosdb):
def test_exiftool_json_sidecar_keyword_template_long(capsys, photosdb):
from osxphotos._constants import _MAX_IPTC_KEYWORD_LEN
photos = photosdb.photos(uuid=[EXIF_JSON_UUID])
@ -452,10 +452,13 @@ def test_exiftool_json_sidecar_keyword_template_long(caplog, photosdb):
)[0]
long_str = "x" * (_MAX_IPTC_KEYWORD_LEN + 1)
photos[0]._verbose = print
json_got = photos[0]._exiftool_json_sidecar(keyword_template=[long_str])
json_got = json.loads(json_got)[0]
assert "Some keywords exceed max IPTC Keyword length" in caplog.text
captured = capsys.readouterr()
assert "some keywords exceed max IPTC Keyword length" in captured.out
# some gymnastics to account for different sort order in different pythons
for k, v in json_got.items():
if type(v) in (list, tuple):