From 8d2d5a8a33e64b19793baf41ddeaa3ca700f51eb Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sat, 30 May 2020 11:27:44 -0700 Subject: [PATCH] refactored render_template, closes #149 --- osxphotos/photoinfo/photoinfo.py | 98 +++++++++++++++++--------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/osxphotos/photoinfo/photoinfo.py b/osxphotos/photoinfo/photoinfo.py index 2eb52b01..090da80c 100644 --- a/osxphotos/photoinfo/photoinfo.py +++ b/osxphotos/photoinfo/photoinfo.py @@ -641,7 +641,6 @@ class PhotoInfo: template: str template none_str: str to use default for None values, default is '_' path_sep: optional character to use as path separator, default is os.path.sep """ - if path_sep is None: path_sep = os.path.sep elif path_sep is not None and len(path_sep) != 1: @@ -722,36 +721,6 @@ class PhotoInfo: rendered_strings = set([rendered]) for field in MULTI_VALUE_SUBSTITUTIONS: - if field == "album": - values = self.albums - elif field == "keyword": - values = self.keywords - elif field == "person": - values = self.persons - # remove any _UNKNOWN_PERSON values - values = [val for val in values if val != _UNKNOWN_PERSON] - elif field == "label": - values = self.labels - elif field == "label_normalized": - values = self.labels_normalized - elif field == "folder_album": - values = [] - # photos must be in an album to be in a folder - for album in self.album_info: - if album.folder_names: - # album in folder - folder = path_sep.join(album.folder_names) - folder += path_sep + album.title - values.append(folder) - else: - # album not in folder - values.append(album.title) - else: - raise ValueError(f"Unhandleded template value: {field}") - - # If no values, insert None so code below will substite none_str for None - values = values or [None] - # Build a regex that matches only the field being processed re_str = r"(?