Added osxphotos related template fields, partial fix for #444

This commit is contained in:
Rhet Turnbull
2021-05-15 14:46:35 -07:00
parent e8f9cda0c6
commit df167c00eb
3 changed files with 13 additions and 4 deletions

View File

@@ -1,3 +1,3 @@
""" version info """ """ version info """
__version__ = "0.42.20" __version__ = "0.42.21"

View File

@@ -4,10 +4,12 @@ import datetime
import locale import locale
import os import os
import pathlib import pathlib
import sys
from textx import TextXSyntaxError, metamodel_from_file from textx import TextXSyntaxError, metamodel_from_file
from ._constants import _UNKNOWN_PERSON from ._constants import _UNKNOWN_PERSON
from ._version import __version__
from .datetime_formatter import DateTimeFormatter from .datetime_formatter import DateTimeFormatter
from .exiftool import ExifToolCaching from .exiftool import ExifToolCaching
from .path_utils import sanitize_dirname, sanitize_filename, sanitize_pathpart from .path_utils import sanitize_dirname, sanitize_filename, sanitize_pathpart
@@ -134,6 +136,8 @@ TEMPLATE_SUBSTITUTIONS = {
"{lf}": r"A line feed: '\n', alias for {newline}", "{lf}": r"A line feed: '\n', alias for {newline}",
"{cr}": r"A carriage return: '\r'", "{cr}": r"A carriage return: '\r'",
"{crlf}": r"a carriage return + line feed: '\r\n'", "{crlf}": r"a carriage return + line feed: '\r\n'",
"{osxphotos_version}": f"The osxphotos version, e.g. '{__version__}'",
"{osxphotos_cmd_line}": "The full command line used to run osxphotos"
} }
# Permitted multi-value substitutions (each of these returns None or 1 or more values) # Permitted multi-value substitutions (each of these returns None or 1 or more values)
@@ -908,6 +912,10 @@ class PhotoTemplate:
value = self.photo.uuid value = self.photo.uuid
elif field in PUNCTUATION: elif field in PUNCTUATION:
value = PUNCTUATION[field] value = PUNCTUATION[field]
elif field == "osxphotos_version":
value = __version__
elif field == "osxphotos_cmd_line":
value = " ".join(sys.argv)
else: else:
# if here, didn't get a match # if here, didn't get a match
raise ValueError(f"Unhandled template value: {field}") raise ValueError(f"Unhandled template value: {field}")

View File

@@ -34,7 +34,7 @@ if OS_VER == "15":
TEST_LIBRARY = "tests/Test-10.15.7.photoslibrary" TEST_LIBRARY = "tests/Test-10.15.7.photoslibrary"
else: else:
TEST_LIBRARY = None TEST_LIBRARY = None
pytest.exit("This test suite currently only runs on MacOS Catalina ") # pytest.exit("This test suite currently only runs on MacOS Catalina ")
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
@@ -59,10 +59,11 @@ def pytest_configure(config):
def pytest_collection_modifyitems(config, items): def pytest_collection_modifyitems(config, items):
if config.getoption("--addalbum"): if config.getoption("--addalbum") and TEST_LIBRARY is not None:
# --addalbum given in cli: do not skip addalbum tests (these require interactive test) # --addalbum given in cli: do not skip addalbum tests (these require interactive test)
return return
skip_addalbum = pytest.mark.skip(reason="need --addalbum option to run")
skip_addalbum = pytest.mark.skip(reason="need --addalbum option and MacOS Catalina to run")
for item in items: for item in items:
if "addalbum" in item.keywords: if "addalbum" in item.keywords:
item.add_marker(skip_addalbum) item.add_marker(skip_addalbum)