Removed exportdb requirement from PhotoTemplate

This commit is contained in:
Rhet Turnbull 2022-01-24 06:20:34 -08:00
parent b3b1d8f193
commit 6af124e4d3
2 changed files with 9 additions and 29 deletions

View File

@ -2032,7 +2032,6 @@ def export(
finder_tag_template=finder_tag_template,
strip=strip,
export_dir=dest,
export_db=export_db,
)
results.xattr_written.extend(tags_written)
results.xattr_skipped.extend(tags_skipped)
@ -2044,7 +2043,6 @@ def export(
xattr_template,
strip=strip,
export_dir=dest,
export_db=export_db,
)
results.xattr_written.extend(xattr_written)
results.xattr_skipped.extend(xattr_skipped)
@ -2958,7 +2956,7 @@ def _render_suffix_template(
return ""
try:
options = RenderOptions(filename=True, export_dir=dest, exportdb=export_db)
options = RenderOptions(filename=True, export_dir=dest)
rendered_suffix, unmatched = photo.render_template(suffix_template, options)
except ValueError as e:
raise click.BadOptionUsage(
@ -3074,8 +3072,7 @@ def export_photo_to_directory(
return results
render_options = RenderOptions(
export_dir=export_dir, dest_path=dest_path, exportdb=export_db
)
export_dir=export_dir, dest_path=dest_path)
tries = 0
while tries <= retry:
@ -3214,8 +3211,7 @@ def get_filenames_from_template(
filename=True,
edited_version=edited,
export_dir=export_dir,
dest_path=dest_path,
exportdb=export_db,
dest_path=dest_path
)
filenames, unmatched = photo.render_template(filename_template, options)
except ValueError as e:
@ -3282,8 +3278,7 @@ def get_dirnames_from_template(
# got a directory template, render it and check results are valid
try:
options = RenderOptions(
dirname=True, edited_version=edited, exportdb=export_db
)
dirname=True, edited_version=edited)
dirnames, unmatched = photo.render_template(directory, options)
except ValueError as e:
raise click.BadOptionUsage(
@ -3569,7 +3564,6 @@ def write_finder_tags(
finder_tag_template=None,
strip=False,
export_dir=None,
export_db=None,
):
"""Write Finder tags (extended attributes) to files; only writes attributes if attributes on file differ from what would be written
@ -3583,7 +3577,6 @@ def write_finder_tags(
exiftool_merge_keywords: if True, include any keywords in the exif data of the source image as keywords
finder_tag_template: list of templates to evaluate for determining Finder tags
export_dir: value to use for {export_dir} template
export_db: an ExportDB object
Returns:
(list of file paths that were updated with new Finder tags, list of file paths skipped because Finder tags didn't need updating)
@ -3614,8 +3607,7 @@ def write_finder_tags(
options = RenderOptions(
none_str=_OSXPHOTOS_NONE_SENTINEL,
path_sep="/",
export_dir=export_dir,
exportdb=export_db,
export_dir=export_dir
)
rendered, unmatched = photo.render_template(template_str, options)
except ValueError as e:
@ -3663,7 +3655,6 @@ def write_extended_attributes(
xattr_template,
strip=False,
export_dir=None,
export_db=None,
):
"""Writes extended attributes to exported files
@ -3671,7 +3662,6 @@ def write_extended_attributes(
photo: a PhotoInfo object
strip: xattr_template: list of tuples: (attribute name, attribute template)
export_dir: value to use for {export_dir} template
exportdb: an ExportDB object
Returns:
tuple(list of file paths that were updated with new attributes, list of file paths skipped because attributes didn't need updating)
@ -3683,8 +3673,7 @@ def write_extended_attributes(
options = RenderOptions(
none_str=_OSXPHOTOS_NONE_SENTINEL,
path_sep="/",
export_dir=export_dir,
exportdb=export_db,
export_dir=export_dir
)
rendered, unmatched = photo.render_template(template_str, options)
except ValueError as e:
@ -3752,8 +3741,7 @@ def run_post_command(
if isinstance(f, tuple):
f = f[0]
render_options = RenderOptions(
export_dir=export_dir, filepath=f, exportdb=export_db
)
export_dir=export_dir, filepath=f)
template = PhotoTemplate(photo, exiftool_path=exiftool_path)
command, _ = template.render(command_template, options=render_options)
command = command[0] if command else None

View File

@ -17,7 +17,6 @@ from ._constants import _UNKNOWN_PERSON, TEXT_DETECTION_CONFIDENCE_THRESHOLD
from ._version import __version__
from .datetime_formatter import DateTimeFormatter
from .exiftool import ExifToolCaching
from .export_db import ExportDB_ABC, ExportDBInMemory
from .path_utils import sanitize_dirname, sanitize_filename, sanitize_pathpart
from .text_detection import detect_text
from .utils import expand_and_validate_filepath, load_function
@ -300,7 +299,6 @@ class RenderOptions:
dest_path: set to the destination path of the photo (for use by {function} template), only valid with --filename
filepath: set to value for filepath of the exported photo if you want to evaluate {filepath} template
quote: quote path templates for execution in the shell
exportdb: ExportDB object
"""
none_str: str = "_"
@ -315,7 +313,6 @@ class RenderOptions:
dest_path: Optional[str] = None
filepath: Optional[str] = None
quote: bool = False
exportdb: Optional[ExportDB_ABC] = None
class PhotoTemplateParser:
@ -384,9 +381,6 @@ class PhotoTemplate:
self.filepath = options.filepath
self.quote = options.quote
self.dest_path = options.dest_path
self.exportdb = options.exportdb or ExportDBInMemory(
None, self.export_dir or "."
)
def render(
self,
@ -420,7 +414,6 @@ class PhotoTemplate:
self.filepath = options.filepath
self.quote = options.quote
self.dest_path = options.dest_path
self.exportdb = options.exportdb or self.exportdb
try:
model = self.parser.parse(template)
@ -1216,7 +1209,7 @@ class PhotoTemplate:
else:
values = list(obj)
elif field == "detected_text":
values = _get_detected_text(self.photo, self.exportdb, confidence=subfield)
values = _get_detected_text(self.photo, confidence=subfield)
else:
raise ValueError(f"Unhandled template value: {field}")
@ -1459,7 +1452,7 @@ def _get_album_by_path(photo, folder_album_path):
return None
def _get_detected_text(photo, exportdb, confidence=TEXT_DETECTION_CONFIDENCE_THRESHOLD):
def _get_detected_text(photo, confidence=TEXT_DETECTION_CONFIDENCE_THRESHOLD):
"""Returns the detected text for a photo
{detected_text} uses this instead of PhotoInfo.detected_text() to cache the text for all confidence values
"""
@ -1475,5 +1468,4 @@ def _get_detected_text(photo, exportdb, confidence=TEXT_DETECTION_CONFIDENCE_THR
# _detected_text caches the text detection results in an extended attribute
# so the first time this gets called is slow but repeated accesses are fast
detected_text = photo._detected_text()
exportdb.set_detected_text_for_uuid(photo.uuid, json.dumps(detected_text))
return [text for text, conf in detected_text if conf >= confidence]