diff --git a/examples/export_template.py b/examples/export_template.py index 6cb82d72..14d41c58 100644 --- a/examples/export_template.py +++ b/examples/export_template.py @@ -77,11 +77,12 @@ def place_folder(photo: osxphotos.PhotoInfo) -> str: return "" -def photos_folders(photo: osxphotos.PhotoInfo, **kwargs) -> Union[List, str]: +def photos_folders(photo: osxphotos.PhotoInfo, options: osxphotos.phototemplate.RenderOptions, **kwargs) -> Union[List, str]: """template function for use with --directory to export photos in a folder structure similar to Photos Args: photo: osxphotos.PhotoInfo object + options: RenderOptions instance **kwargs: not currently used, placeholder to keep functions compatible with possible changes to {function} Returns: list of directories for each photo diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 43718a29..555d237b 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.42.62" +__version__ = "0.42.63" diff --git a/osxphotos/cli.py b/osxphotos/cli.py index 4a069445..1eb9ca7c 100644 --- a/osxphotos/cli.py +++ b/osxphotos/cli.py @@ -2841,7 +2841,7 @@ def export_photo_with_template( results.missing.append(str(pathlib.Path(dest_path) / filename)) continue - render_options = RenderOptions(export_dir=export_dir) + render_options = RenderOptions(export_dir=export_dir, dest_path=dest_path) tries = 0 while tries <= retry: diff --git a/osxphotos/phototemplate.py b/osxphotos/phototemplate.py index 507590a8..f6ec4d67 100644 --- a/osxphotos/phototemplate.py +++ b/osxphotos/phototemplate.py @@ -250,6 +250,7 @@ class RenderOptions: strip: if True, strips leading/trailing whitespace from rendered templates edited_version: set to True if you want {edited_version} to resolve to True (e.g. exporting edited version of photo) export_dir: set to the export directory if you want to evalute {export_dir} template + 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 """ @@ -263,6 +264,7 @@ class RenderOptions: strip: bool = False edited_version: bool = False export_dir: Optional[str] = None + dest_path: Optional[str] = None filepath: Optional[str] = None quote: bool = False @@ -354,8 +356,10 @@ class PhotoTemplate: self.dirname = options.dirname self.strip = options.strip self.export_dir = options.export_dir + self.dest_path = options.dest_path self.filepath = options.filepath self.quote = options.quote + self.options = options try: model = self.parser.parse(template) @@ -1182,7 +1186,7 @@ class PhotoTemplate: raise ValueError(f"'{filename}' does not appear to be a file") template_func = load_function(filename_validated, funcname) - values = template_func(self.photo) + values = template_func(self.photo, options=self.options) if not isinstance(values, (str, list)): raise TypeError(