Compare commits

..

19 Commits

Author SHA1 Message Date
Rhet Turnbull
e39776b51e Added --field to dump and query, #777 (#779) 2022-08-27 21:05:57 -07:00
Rhet Turnbull
02d772c921 Updated CHANGELOG.md [skip ci] 2022-08-27 13:48:39 -07:00
allcontributors[bot]
817bdf0604 docs: add tkrunning as a contributor for code, bug (#776)
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2022-08-27 13:47:48 -07:00
allcontributors[bot]
a74520f747 docs: add jmuccigr as a contributor for bug, ideas (#775)
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
2022-08-27 13:46:13 -07:00
Rhet Turnbull
bb480f6991 Release 0.51.4, added --print to dump 2022-08-27 11:25:46 -07:00
Rhet Turnbull
af9311c9c8 Fixed --print to work with {tab} 2022-08-27 11:11:38 -07:00
Rhet Turnbull
b12d112793 Updated CHANGELOG.md [skip ci] 2022-08-27 10:53:42 -07:00
Rhet Turnbull
5eaeb72c3e Added --print to dump, added {tab} 2022-08-27 10:50:25 -07:00
Rhet Turnbull
320fb86559 Added bump2version 2022-08-27 09:47:52 -07:00
Rhet Turnbull
d576ca5494 Release 0.51.3, added --print (#769), --quiet (#770) 2022-08-27 09:31:37 -07:00
Rhet Turnbull
8e986b451e Added --print, --quiet, #769, #770 (#773) 2022-08-26 22:17:12 -07:00
Rhet Turnbull
f0bdfb5eac Updated CHANGELOG.md [skip ci] 2022-08-26 07:03:59 -07:00
Rhet Turnbull
4ca681ee4f Release 0.51.2, added new filter(x) to template filters (#772) 2022-08-26 06:55:45 -07:00
Rhet Turnbull
66f6002a57 Feature filter filter 759 (#771)
* Added filter(x) filter, #759

* Added int, float filters
2022-08-26 06:39:32 -07:00
Rhet Turnbull
d845e9b66e Release 0.51.1, added --report to import (#767) 2022-08-22 09:31:47 -07:00
Rhet Turnbull
991511af07 Added --report to import command (#766) 2022-08-22 07:29:53 -07:00
Rhet Turnbull
3c98906158 Fixed template function to work with import command (#765) 2022-08-21 14:33:18 -07:00
Rhet Turnbull
08b806ff7d Updated CHANGELOG.md [skip ci] 2022-08-21 12:39:28 -07:00
Rhet Turnbull
b5f4c48ec9 Updated README [skip ci] 2022-08-21 12:37:56 -07:00
42 changed files with 1686 additions and 124 deletions

View File

@@ -363,6 +363,26 @@
"contributions": [
"bug"
]
},
{
"login": "jmuccigr",
"name": "John Muccigrosso",
"avatar_url": "https://avatars.githubusercontent.com/u/615115?v=4",
"profile": "http://jmuccigr.github.io/",
"contributions": [
"bug",
"ideas"
]
},
{
"login": "tkrunning",
"name": "Thomas K. Running",
"avatar_url": "https://avatars.githubusercontent.com/u/1646041?v=4",
"profile": "https://nomadgate.com",
"contributions": [
"code",
"bug"
]
}
],
"contributorsPerLine": 7,

8
.bumpversion.cfg Normal file
View File

@@ -0,0 +1,8 @@
[bumpversion]
current_version = 0.51.4
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
serialize = {major}.{minor}.{patch}
[bumpversion:file:osxphotos/_version.py]
parse = __version__\s=\s\"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\"
serialize = {major}.{minor}.{patch}

View File

@@ -1815,6 +1815,9 @@ Valid filters are:
- `remove(x)`: Remove x from list of values, e.g. remove(b): ['a', 'b', 'c'] => ['a', 'c'].
- `slice(start:stop:step)`: Slice list using same semantics as Python's list slicing, e.g. slice(1:3): ['a', 'b', 'c', 'd'] => ['b', 'c']; slice(1:4:2): ['a', 'b', 'c', 'd'] => ['b', 'd']; slice(1:): ['a', 'b', 'c', 'd'] => ['b', 'c', 'd']; slice(:-1): ['a', 'b', 'c', 'd'] => ['a', 'b', 'c']; slice(::-1): ['a', 'b', 'c', 'd'] => ['d', 'c', 'b', 'a']. See also sslice().
- `sslice(start:stop:step)`: [s(tring) slice] Slice values in a list using same semantics as Python's string slicing, e.g. sslice(1:3):'abcd => 'bc'; sslice(1:4:2): 'abcd' => 'bd', etc. See also slice().
- `filter(x)`: Filter list of values using predicate x; for example, `{folder_album|filter(contains Events)}` returns only folders/albums containing the word 'Events' in their path.
- `int`: Convert values in list to integer, e.g. 1.0 => 1. If value cannot be converted to integer, remove value from list. ['1.1', 'x'] => ['1']. See also float.
- `float`: Convert values in list to floating point number, e.g. 1 => 1.0. If value cannot be converted to float, remove value from list. ['1', 'x'] => ['1.0']. See also int.
e.g. if Photo keywords are `["FOO","bar"]`:
@@ -2004,8 +2007,9 @@ cog.out(get_template_field_table())
|{newline}|A newline: '\n'|
|{lf}|A line feed: '\n', alias for {newline}|
|{cr}|A carriage return: '\r'|
|{crlf}|a carriage return + line feed: '\r\n'|
|{osxphotos_version}|The osxphotos version, e.g. '0.51.0'|
|{crlf}|A carriage return + line feed: '\r\n'|
|{tab}|:A tab: '\t'|
|{osxphotos_version}|The osxphotos version, e.g. '0.51.4'|
|{osxphotos_cmd_line}|The full command line used to run osxphotos|
|{album}|Album(s) photo is contained in|
|{folder_album}|Folder path + album photo is contained in. e.g. 'Folder/Subfolder/Album' or just 'Album' if no enclosing folder|

View File

@@ -4,6 +4,49 @@ All notable changes to this project will be documented in this file. Dates are d
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
#### [v0.51.4](https://github.com/RhetTbull/osxphotos/compare/v0.51.3...v0.51.4)
> 27 August 2022
- Release 0.51.4, added --print to dump [`bb480f6`](https://github.com/RhetTbull/osxphotos/commit/bb480f69914ed351b6f4309b0f6aa539add1a9fb)
- Added --print to dump, added {tab} [`5eaeb72`](https://github.com/RhetTbull/osxphotos/commit/5eaeb72c3ee296af6abc6ca6ddf8ad05baf02052)
- Fixed --print to work with {tab} [`af9311c`](https://github.com/RhetTbull/osxphotos/commit/af9311c9c86a3d0a5764ebd1539d40f14e62f2ec)
#### [v0.51.3](https://github.com/RhetTbull/osxphotos/compare/v0.51.2...v0.51.3)
> 27 August 2022
- Added --print, --quiet, #769, #770 [`#773`](https://github.com/RhetTbull/osxphotos/pull/773)
- Release 0.51.3, added --print (#769), --quiet (#770) [`d576ca5`](https://github.com/RhetTbull/osxphotos/commit/d576ca54948c0cbbd16f04231459a294f0333f89)
- Added bump2version [`320fb86`](https://github.com/RhetTbull/osxphotos/commit/320fb8655980882fd75e354d33450f0904babf2a)
#### [v0.51.2](https://github.com/RhetTbull/osxphotos/compare/v0.51.1...v0.51.2)
> 26 August 2022
- Release 0.51.2, added new filter(x) to template filters [`#772`](https://github.com/RhetTbull/osxphotos/pull/772)
- Feature filter filter 759 [`#771`](https://github.com/RhetTbull/osxphotos/pull/771)
#### [v0.51.1](https://github.com/RhetTbull/osxphotos/compare/v0.51.0...v0.51.1)
> 22 August 2022
- Release 0.51.1, added --report to import [`#767`](https://github.com/RhetTbull/osxphotos/pull/767)
- Added --report to import command [`#766`](https://github.com/RhetTbull/osxphotos/pull/766)
- Fixed template function to work with import command [`#765`](https://github.com/RhetTbull/osxphotos/pull/765)
- Updated README [skip ci] [`b5f4c48`](https://github.com/RhetTbull/osxphotos/commit/b5f4c48ec98b344b5d7ed7c2a5e9a445d322df13)
#### [v0.51.0](https://github.com/RhetTbull/osxphotos/compare/v0.50.13...v0.51.0)
> 21 August 2022
- Release 0.51.0 [`#763`](https://github.com/RhetTbull/osxphotos/pull/763)
- Feature add import 754 [`#762`](https://github.com/RhetTbull/osxphotos/pull/762)
- Updated tested versions [`#757`](https://github.com/RhetTbull/osxphotos/pull/757)
- Updated examples [skip ci] [`c7e3a55`](https://github.com/RhetTbull/osxphotos/commit/c7e3a552db60321fc9999153b6b5624bc1bb76dc)
- Updated xmp_rating example [`1e053aa`](https://github.com/RhetTbull/osxphotos/commit/1e053aa7086af44a207d1be045d698c7d10b97f5)
- Updated xmp_rating example [`46738d0`](https://github.com/RhetTbull/osxphotos/commit/46738d05b213d1d8ef390add71142623892385ce)
#### [v0.50.13](https://github.com/RhetTbull/osxphotos/compare/v0.50.12...v0.50.13)
> 13 August 2022

View File

@@ -7,7 +7,7 @@
[![Downloads](https://static.pepy.tech/personalized-badge/osxphotos?period=month&units=international_system&left_color=black&right_color=brightgreen&left_text=downloads/month)](https://pepy.tech/project/osxphotos)
[![subreddit](https://img.shields.io/reddit/subreddit-subscribers/osxphotos?style=social)](https://www.reddit.com/r/osxphotos/)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-38-orange.svg?style=flat)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-40-orange.svg?style=flat)](#contributors)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
OSXPhotos provides the ability to interact with and query Apple's Photos.app library on macOS. You can query the Photos library database — for example, file name, file path, and metadata such as keywords/tags, persons/faces, albums, etc. You can also easily export both the original and edited photos.
@@ -142,12 +142,14 @@ Commands:
export Export photos from the Photos database.
exportdb Utilities for working with the osxphotos export database
help Print help; for help on commands: help <command>.
import Import photos and videos into Photos.
info Print out descriptive info of the Photos library database.
inspect Interactively inspect photos selected in Photos.
install Install Python packages into the same environment as osxphotos
keywords Print out keywords found in the Photos library.
labels Print out image classification labels found in the Photos...
list Print list of Photos libraries found on the system.
orphans Find orphaned photos in a Photos library
persons Print out persons (faces) found in the Photos library.
places Print out places found in the Photos library.
query Query the Photos database using 1 or more search options; if...
@@ -264,6 +266,22 @@ the exported files would be:
/path/to/export/Travel/IMG_1234.JPG
/path/to/export/Vacation/IMG_1234.JPG
If your photos are organized in folders and albums in Photos you can preserve this structure on export by using the `{folder_album}` template field with the `--directory` option. For example, if you have a photo in the album `Vacation` which is in the `Travel` folder, the following command would export the photo to the `Travel/Vacation` directory:
`osxphotos export /path/to/export --directory "{folder_album}"`
Photos can belong to more than one album. In this case, the template field `{folder_album}` will expand to all the album names that the photo belongs to. For example, if a photo belongs to the albums `Vacation` and `Travel`, the template field `{folder_album}` would expand to `Vacation`, `Travel`. If the photo belongs to no albums, the template field `{folder_album}` would expand to "_" (the default value).
All template fields including `{folder_album}` can be further filtered using a number of different filters. To convert all directory names to lower case for example, use the `lower` filter:
`osxphotos export /path/to/export --directory "{folder_album|lower}"`
If all your photos were organized into various albums under a folder named `Events` but some where also included in other top-level albums and you wanted to export only the `Events` folder, you could use the `filter` option to filter out the other top-level albums by selecting only those folder/album paths that start with `Events`:
`osxphotos export /path/to/export --directory "{folder_album|filter(startswith Events)}"`
You can learn more about the other filters using `osxphotos help export`.
#### Specify exported filename
By default, osxphotos will use the original filename of the photo when exporting. That is, the filename the photo had when it was taken or imported into Photos. This is often something like `IMG_1234.JPG` or `DSC05678.dng`. osxphotos allows you to specify a custom filename template using the `--filename` option in the same way as `--directory` allows you to specify a custom directory name. For example, Photos allows you specify a title or caption for a photo and you can use this in place of the original filename:
@@ -443,6 +461,14 @@ You can use the `--report` option to create a report, in comma-separated values
`osxphotos export /path/to/export --report export.csv`
You can also create reports in JSON or SQLite format by changing the extension of the report filename. For example, to create a JSON report:
`osxphotos export /path/to/export --report export.json`
And to create a SQLite report:
`osxphotos export /path/to/export --report export.sqlite`
#### Exporting only certain photos
By default, osxphotos will export your entire Photos library. If you want to export only certain photos, osxphotos provides a rich set of "query options" that allow you to query the Photos database to filter out only certain photos that match your query criteria. The tutorial does not cover all the query options as there are over 50 of them--read the help text (`osxphotos help export`) to better understand the available query options. No matter which subset of photos you would like to export, there is almost certainly a way for osxphotos to filter these. For example, you can filter for only images that contain certain keywords or images without a title, images from a specific time of day or specific date range, images contained in specific albums, etc.
@@ -1315,6 +1341,13 @@ Options:
--config-only If specified, saves the config file but does
not export any files; must be used with
--save-config.
--print TEMPLATE Render TEMPLATE string for each photo being
exported and print to stdout. TEMPLATE is an
osxphotos template string. This may be useful
for creating custom reports, etc. TEMPLATE
will be printed after the photo is exported or
skipped. May be repeated to print multiple
template strings.
--theme THEME Specify the color theme to use for --verbose
output. Valid themes are 'dark', 'light',
'mono', and 'plain'. Defaults to 'dark' or
@@ -1525,6 +1558,15 @@ Valid filters are:
• sslice(start:stop:step): [s(tring) slice] Slice values in a list using same
semantics as Python's string slicing, e.g. sslice(1:3):'abcd => 'bc';
sslice(1:4:2): 'abcd' => 'bd', etc. See also slice().
• filter(x): Filter list of values using predicate x; for example,
{folder_album|filter(contains Events)} returns only folders/albums
containing the word 'Events' in their path.
• int: Convert values in list to integer, e.g. 1.0 => 1. If value cannot be
converted to integer, remove value from list. ['1.1', 'x'] => ['1']. See
also float.
• float: Convert values in list to floating point number, e.g. 1 => 1.0. If
value cannot be converted to float, remove value from list. ['1', 'x'] =>
['1.0']. See also int.
e.g. if Photo keywords are ["FOO","bar"]:
@@ -1952,8 +1994,9 @@ Substitution Description
{newline} A newline: '\n'
{lf} A line feed: '\n', alias for {newline}
{cr} A carriage return: '\r'
{crlf} a carriage return + line feed: '\r\n'
{osxphotos_version} The osxphotos version, e.g. '0.51.0'
{crlf} A carriage return + line feed: '\r\n'
{tab} :A tab: '\t'
{osxphotos_version} The osxphotos version, e.g. '0.51.4'
{osxphotos_cmd_line} The full command line used to run osxphotos
The following substitutions may result in multiple values. Thus if specified
@@ -2243,6 +2286,9 @@ Valid filters are:
- `remove(x)`: Remove x from list of values, e.g. remove(b): ['a', 'b', 'c'] => ['a', 'c'].
- `slice(start:stop:step)`: Slice list using same semantics as Python's list slicing, e.g. slice(1:3): ['a', 'b', 'c', 'd'] => ['b', 'c']; slice(1:4:2): ['a', 'b', 'c', 'd'] => ['b', 'd']; slice(1:): ['a', 'b', 'c', 'd'] => ['b', 'c', 'd']; slice(:-1): ['a', 'b', 'c', 'd'] => ['a', 'b', 'c']; slice(::-1): ['a', 'b', 'c', 'd'] => ['d', 'c', 'b', 'a']. See also sslice().
- `sslice(start:stop:step)`: [s(tring) slice] Slice values in a list using same semantics as Python's string slicing, e.g. sslice(1:3):'abcd => 'bc'; sslice(1:4:2): 'abcd' => 'bd', etc. See also slice().
- `filter(x)`: Filter list of values using predicate x; for example, `{folder_album|filter(contains Events)}` returns only folders/albums containing the word 'Events' in their path.
- `int`: Convert values in list to integer, e.g. 1.0 => 1. If value cannot be converted to integer, remove value from list. ['1.1', 'x'] => ['1']. See also float.
- `float`: Convert values in list to floating point number, e.g. 1 => 1.0. If value cannot be converted to float, remove value from list. ['1', 'x'] => ['1.0']. See also int.
e.g. if Photo keywords are `["FOO","bar"]`:
@@ -2429,8 +2475,9 @@ The following template field substitutions are availabe for use the templating s
|{newline}|A newline: '\n'|
|{lf}|A line feed: '\n', alias for {newline}|
|{cr}|A carriage return: '\r'|
|{crlf}|a carriage return + line feed: '\r\n'|
|{osxphotos_version}|The osxphotos version, e.g. '0.51.0'|
|{crlf}|A carriage return + line feed: '\r\n'|
|{tab}|:A tab: '\t'|
|{osxphotos_version}|The osxphotos version, e.g. '0.51.4'|
|{osxphotos_cmd_line}|The full command line used to run osxphotos|
|{album}|Album(s) photo is contained in|
|{folder_album}|Folder path + album photo is contained in. e.g. 'Folder/Subfolder/Album' or just 'Album' if no enclosing folder|
@@ -2529,6 +2576,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="https://github.com/infused-kim"><img src="https://avatars.githubusercontent.com/u/7404004?v=4?s=75" width="75px;" alt=""/><br /><sub><b>Kim</b></sub></a><br /><a href="#ideas-infused-kim" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/Se7enair"><img src="https://avatars.githubusercontent.com/u/1680106?v=4?s=75" width="75px;" alt=""/><br /><sub><b>Christoph</b></sub></a><br /><a href="#ideas-Se7enair" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="http://www.franzone.com"><img src="https://avatars.githubusercontent.com/u/900684?v=4?s=75" width="75px;" alt=""/><br /><sub><b>franzone</b></sub></a><br /><a href="https://github.com/RhetTbull/osxphotos/issues?q=author%3Afranzone" title="Bug reports">🐛</a></td>
<td align="center"><a href="http://jmuccigr.github.io/"><img src="https://avatars.githubusercontent.com/u/615115?v=4?s=75" width="75px;" alt=""/><br /><sub><b>John Muccigrosso</b></sub></a><br /><a href="https://github.com/RhetTbull/osxphotos/issues?q=author%3Ajmuccigr" title="Bug reports">🐛</a> <a href="#ideas-jmuccigr" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://nomadgate.com"><img src="https://avatars.githubusercontent.com/u/1646041?v=4?s=75" width="75px;" alt=""/><br /><sub><b>Thomas K. Running</b></sub></a><br /><a href="https://github.com/RhetTbull/osxphotos/commits?author=tkrunning" title="Code">💻</a> <a href="https://github.com/RhetTbull/osxphotos/issues?q=author%3Atkrunning" title="Bug reports">🐛</a></td>
</tr>
</table>

View File

@@ -1,4 +1,5 @@
build
bump2version==1.0.1
cogapp>=3.3.0,<4.0.0
furo
m2r2

View File

@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: ec5046c1e0bd94597cfc68b7f262f83c
config: 9c14761ce21d96c98ba51262e03cfe2d
tags: 645f666f9bcd5a90fca523b33c5a78b7

View File

@@ -5,7 +5,7 @@
<meta name="color-scheme" content="light dark"><link rel="index" title="Index" href="../genindex.html" /><link rel="search" title="Search" href="../search.html" />
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/>
<title>Overview: module code - osxphotos 0.51.0 documentation</title>
<title>Overview: module code - osxphotos 0.51.4 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/styles/furo.css?digest=68f4518137b9aefe99b631505a2064c3c42c9852" />
<link rel="stylesheet" type="text/css" href="../_static/copybutton.css" />
@@ -123,7 +123,7 @@
</label>
</div>
<div class="header-center">
<a href="../index.html"><div class="brand">osxphotos 0.51.0 documentation</div></a>
<a href="../index.html"><div class="brand">osxphotos 0.51.4 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
@@ -146,7 +146,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="../index.html">
<span class="sidebar-brand-text">osxphotos 0.51.0 documentation</span>
<span class="sidebar-brand-text">osxphotos 0.51.4 documentation</span>
</a><form class="sidebar-search-container" method="get" action="../search.html" role="search">
<input class="sidebar-search" placeholder=Search name="q" aria-label="Search">

View File

@@ -5,7 +5,7 @@
<meta name="color-scheme" content="light dark"><link rel="index" title="Index" href="../../genindex.html" /><link rel="search" title="Search" href="../../search.html" />
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/>
<title>osxphotos.phototemplate - osxphotos 0.51.0 documentation</title>
<title>osxphotos.phototemplate - osxphotos 0.51.4 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../../_static/styles/furo.css?digest=68f4518137b9aefe99b631505a2064c3c42c9852" />
<link rel="stylesheet" type="text/css" href="../../_static/copybutton.css" />
@@ -123,7 +123,7 @@
</label>
</div>
<div class="header-center">
<a href="../../index.html"><div class="brand">osxphotos 0.51.0 documentation</div></a>
<a href="../../index.html"><div class="brand">osxphotos 0.51.4 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
@@ -146,7 +146,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="../../index.html">
<span class="sidebar-brand-text">osxphotos 0.51.0 documentation</span>
<span class="sidebar-brand-text">osxphotos 0.51.4 documentation</span>
</a><form class="sidebar-search-container" method="get" action="../../search.html" role="search">
<input class="sidebar-search" placeholder=Search name="q" aria-label="Search">
@@ -377,7 +377,8 @@
<span class="s2">"</span><span class="si">{newline}</span><span class="s2">"</span><span class="p">:</span> <span class="sa">r</span><span class="s2">"A newline: '\n'"</span><span class="p">,</span>
<span class="s2">"</span><span class="si">{lf}</span><span class="s2">"</span><span class="p">:</span> <span class="sa">r</span><span class="s2">"A line feed: '\n', alias for </span><span class="si">{newline}</span><span class="s2">"</span><span class="p">,</span>
<span class="s2">"</span><span class="si">{cr}</span><span class="s2">"</span><span class="p">:</span> <span class="sa">r</span><span class="s2">"A carriage return: '\r'"</span><span class="p">,</span>
<span class="s2">"</span><span class="si">{crlf}</span><span class="s2">"</span><span class="p">:</span> <span class="sa">r</span><span class="s2">"a carriage return + line feed: '\r\n'"</span><span class="p">,</span>
<span class="s2">"</span><span class="si">{crlf}</span><span class="s2">"</span><span class="p">:</span> <span class="sa">r</span><span class="s2">"A carriage return + line feed: '\r\n'"</span><span class="p">,</span>
<span class="s2">"</span><span class="si">{tab}</span><span class="s2">"</span><span class="p">:</span> <span class="sa">r</span><span class="s2">":A tab: '\t'"</span><span class="p">,</span>
<span class="s2">"</span><span class="si">{osxphotos_version}</span><span class="s2">"</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"The osxphotos version, e.g. '</span><span class="si">{</span><span class="n">__version__</span><span class="si">}</span><span class="s2">'"</span><span class="p">,</span>
<span class="s2">"</span><span class="si">{osxphotos_cmd_line}</span><span class="s2">"</span><span class="p">:</span> <span class="s2">"The full command line used to run osxphotos"</span><span class="p">,</span>
<span class="p">}</span>
@@ -464,6 +465,11 @@
<span class="o">+</span> <span class="s2">"slice(::-1): ['a', 'b', 'c', 'd'] =&gt; ['d', 'c', 'b', 'a']. See also sslice()."</span><span class="p">,</span>
<span class="s2">"sslice(start:stop:step)"</span><span class="p">:</span> <span class="s2">"[s(tring) slice] Slice values in a list using same semantics as Python's string slicing, "</span>
<span class="o">+</span> <span class="s2">"e.g. sslice(1:3):'abcd =&gt; 'bc'; sslice(1:4:2): 'abcd' =&gt; 'bd', etc. See also slice()."</span><span class="p">,</span>
<span class="s2">"filter(x)"</span><span class="p">:</span> <span class="s2">"Filter list of values using predicate x; for example, `{folder_album|filter(contains Events)}` returns only folders/albums containing the word 'Events' in their path."</span><span class="p">,</span>
<span class="s2">"int"</span><span class="p">:</span> <span class="s2">"Convert values in list to integer, e.g. 1.0 =&gt; 1. If value cannot be converted to integer, remove value from list. "</span>
<span class="o">+</span> <span class="s2">"['1.1', 'x'] =&gt; ['1']. See also float."</span><span class="p">,</span>
<span class="s2">"float"</span><span class="p">:</span> <span class="s2">"Convert values in list to floating point number, e.g. 1 =&gt; 1.0. If value cannot be converted to float, remove value from list. "</span>
<span class="o">+</span> <span class="s2">"['1', 'x'] =&gt; ['1.0']. See also int."</span><span class="p">,</span>
<span class="p">}</span>
<span class="c1"># Just the substitutions without the braces</span>
@@ -503,6 +509,7 @@
<span class="s2">"lf"</span><span class="p">:</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">"</span><span class="p">,</span>
<span class="s2">"cr"</span><span class="p">:</span> <span class="s2">"</span><span class="se">\r</span><span class="s2">"</span><span class="p">,</span>
<span class="s2">"crlf"</span><span class="p">:</span> <span class="s2">"</span><span class="se">\r\n</span><span class="s2">"</span><span class="p">,</span>
<span class="s2">"tab"</span><span class="p">:</span> <span class="s2">"</span><span class="se">\t</span><span class="s2">"</span><span class="p">,</span>
<span class="p">}</span>
@@ -525,6 +532,7 @@
<span class="sd"> dest_path: set to the destination path of the photo (for use by {function} template), only valid with --filename</span>
<span class="sd"> filepath: set to value for filepath of the exported photo if you want to evaluate {filepath} template</span>
<span class="sd"> quote: quote path templates for execution in the shell</span>
<span class="sd"> caller: which command is calling the template (e.g. 'export')</span>
<span class="sd"> """</span>
<span class="n">none_str</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"_"</span>
@@ -539,6 +547,7 @@
<span class="n">dest_path</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">filepath</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">quote</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">caller</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"export"</span>
<span class="k">class</span> <span class="nc">PhotoTemplateParser</span><span class="p">:</span>
@@ -861,16 +870,18 @@
<span class="n">vals</span> <span class="o">=</span> <span class="n">string_test</span><span class="p">(</span><span class="k">lambda</span> <span class="n">v</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span> <span class="n">v</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="n">c</span><span class="p">))</span>
<span class="k">elif</span> <span class="n">operator</span> <span class="o">==</span> <span class="s2">"=="</span><span class="p">:</span>
<span class="n">match</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">vals</span><span class="p">)</span> <span class="o">==</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">conditional_value</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">match</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">negation</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">negation</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">match</span><span class="p">):</span>
<span class="n">vals</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"True"</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">vals</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">vals</span> <span class="o">=</span> <span class="p">(</span>
<span class="p">[</span><span class="s2">"True"</span><span class="p">]</span>
<span class="k">if</span> <span class="p">(</span><span class="n">match</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">negation</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">negation</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">match</span><span class="p">)</span>
<span class="k">else</span> <span class="p">[]</span>
<span class="p">)</span>
<span class="k">elif</span> <span class="n">operator</span> <span class="o">==</span> <span class="s2">"!="</span><span class="p">:</span>
<span class="n">match</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">vals</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">conditional_value</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">match</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">negation</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">negation</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">match</span><span class="p">):</span>
<span class="n">vals</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"True"</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">vals</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">vals</span> <span class="o">=</span> <span class="p">(</span>
<span class="p">[</span><span class="s2">"True"</span><span class="p">]</span>
<span class="k">if</span> <span class="p">(</span><span class="n">match</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">negation</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">negation</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">match</span><span class="p">)</span>
<span class="k">else</span> <span class="p">[]</span>
<span class="p">)</span>
<span class="k">elif</span> <span class="n">operator</span> <span class="o">==</span> <span class="s2">"&lt;"</span><span class="p">:</span>
<span class="n">vals</span> <span class="o">=</span> <span class="n">comparison_test</span><span class="p">(</span><span class="k">lambda</span> <span class="n">v</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span> <span class="n">v</span> <span class="o">&lt;</span> <span class="n">c</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">operator</span> <span class="o">==</span> <span class="s2">"&lt;="</span><span class="p">:</span>
@@ -984,7 +995,9 @@
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
<span class="s2">"SyntaxError: filename and function must not be null with {function::filename.py:function_name}"</span>
<span class="p">)</span>
<span class="n">vals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_template_value_function</span><span class="p">(</span><span class="n">subfield</span><span class="p">,</span> <span class="n">field_arg</span><span class="p">)</span>
<span class="n">vals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_template_value_function</span><span class="p">(</span>
<span class="n">subfield</span><span class="p">,</span> <span class="n">field_arg</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">caller</span>
<span class="p">)</span>
<span class="k">elif</span> <span class="n">field</span> <span class="ow">in</span> <span class="n">MULTI_VALUE_SUBSTITUTIONS</span> <span class="ow">or</span> <span class="n">field</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">"photo"</span><span class="p">):</span>
<span class="n">vals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_template_value_multi</span><span class="p">(</span>
<span class="n">field</span><span class="p">,</span> <span class="n">subfield</span><span class="p">,</span> <span class="n">path_sep</span><span class="o">=</span><span class="n">field_arg</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="n">default</span>
@@ -1374,6 +1387,7 @@
<span class="s2">"remove"</span><span class="p">,</span>
<span class="s2">"slice"</span><span class="p">,</span>
<span class="s2">"sslice"</span><span class="p">,</span>
<span class="s2">"filter"</span><span class="p">,</span>
<span class="p">]</span> <span class="ow">and</span> <span class="p">(</span><span class="n">args</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="ow">not</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)):</span>
<span class="k">raise</span> <span class="ne">SyntaxError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">filter_</span><span class="si">}</span><span class="s2"> requires arguments"</span><span class="p">)</span>
@@ -1462,12 +1476,72 @@
<span class="c1"># slice each value in a list</span>
<span class="n">slice_</span> <span class="o">=</span> <span class="n">create_slice</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
<span class="n">value</span> <span class="o">=</span> <span class="p">[</span><span class="n">v</span><span class="p">[</span><span class="n">slice_</span><span class="p">]</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">values</span><span class="p">]</span>
<span class="k">elif</span> <span class="n">filter_</span> <span class="o">==</span> <span class="s2">"filter"</span><span class="p">:</span>
<span class="c1"># filter values based on a predicate</span>
<span class="n">value</span> <span class="o">=</span> <span class="p">[</span><span class="n">v</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">values</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">filter_predicate</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">args</span><span class="p">)]</span>
<span class="k">elif</span> <span class="n">filter_</span> <span class="o">==</span> <span class="s2">"int"</span><span class="p">:</span>
<span class="c1"># convert value to integer</span>
<span class="n">value</span> <span class="o">=</span> <span class="n">values_to_int</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">filter_</span> <span class="o">==</span> <span class="s2">"float"</span><span class="p">:</span>
<span class="c1"># convert value to float</span>
<span class="n">value</span> <span class="o">=</span> <span class="n">values_to_float</span><span class="p">(</span><span class="n">values</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">filter_</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">"function:"</span><span class="p">):</span>
<span class="n">value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_template_value_filter_function</span><span class="p">(</span><span class="n">filter_</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">value</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">return</span> <span class="n">value</span></div>
<div class="viewcode-block" id="PhotoTemplate.filter_predicate"><a class="viewcode-back" href="../../reference.html#osxphotos.PhotoTemplate.filter_predicate">[docs]</a> <span class="k">def</span> <span class="nf">filter_predicate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">args</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
<span class="sd">"""Return True if value passes predicate"""</span>
<span class="c1"># extract function name and arguments</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">args</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">SyntaxError</span><span class="p">(</span><span class="s2">"Filter predicate requires arguments"</span><span class="p">)</span>
<span class="n">args</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="k">if</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">"not"</span><span class="p">:</span>
<span class="n">args</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
<span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">filter_predicate</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="s2">" "</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">args</span><span class="p">))</span>
<span class="n">predicate</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">conditional_value</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">"|"</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">comparison_test</span><span class="p">(</span><span class="n">test_function</span><span class="p">):</span>
<span class="sd">"""Perform numerical comparisons using test_function"""</span>
<span class="c1"># returns True if any of the values match the condition</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">return</span> <span class="nb">any</span><span class="p">(</span>
<span class="nb">bool</span><span class="p">(</span><span class="n">test_function</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">value</span><span class="p">),</span> <span class="nb">float</span><span class="p">(</span><span class="n">c</span><span class="p">)))</span>
<span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">conditional_value</span>
<span class="p">)</span>
<span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">SyntaxError</span><span class="p">(</span>
<span class="sa">f</span><span class="s2">"comparison operators may only be used with values that can be converted to numbers: </span><span class="si">{</span><span class="n">vals</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="n">conditional_value</span><span class="si">}</span><span class="s2">"</span>
<span class="p">)</span> <span class="kn">from</span> <span class="nn">e</span>
<span class="n">predicate_is_true</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">if</span> <span class="n">predicate</span> <span class="o">==</span> <span class="s2">"contains"</span><span class="p">:</span>
<span class="n">predicate_is_true</span> <span class="o">=</span> <span class="nb">any</span><span class="p">(</span><span class="n">c</span> <span class="ow">in</span> <span class="n">value</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">conditional_value</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">predicate</span> <span class="o">==</span> <span class="s2">"endswith"</span><span class="p">:</span>
<span class="n">predicate_is_true</span> <span class="o">=</span> <span class="nb">any</span><span class="p">(</span><span class="n">value</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">conditional_value</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">predicate</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">"matches"</span><span class="p">,</span> <span class="s2">"=="</span><span class="p">]:</span>
<span class="n">predicate_is_true</span> <span class="o">=</span> <span class="nb">any</span><span class="p">(</span><span class="n">value</span> <span class="o">==</span> <span class="n">c</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">conditional_value</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">predicate</span> <span class="o">==</span> <span class="s2">"startswith"</span><span class="p">:</span>
<span class="n">predicate_is_true</span> <span class="o">=</span> <span class="nb">any</span><span class="p">(</span><span class="n">value</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">conditional_value</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">predicate</span> <span class="o">==</span> <span class="s2">"!="</span><span class="p">:</span>
<span class="n">predicate_is_true</span> <span class="o">=</span> <span class="nb">any</span><span class="p">(</span><span class="n">value</span> <span class="o">!=</span> <span class="n">c</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">conditional_value</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">predicate</span> <span class="o">==</span> <span class="s2">"&lt;"</span><span class="p">:</span>
<span class="n">predicate_is_true</span> <span class="o">=</span> <span class="n">comparison_test</span><span class="p">(</span><span class="k">lambda</span> <span class="n">v</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span> <span class="n">v</span> <span class="o">&lt;</span> <span class="n">c</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">predicate</span> <span class="o">==</span> <span class="s2">"&lt;="</span><span class="p">:</span>
<span class="n">predicate_is_true</span> <span class="o">=</span> <span class="n">comparison_test</span><span class="p">(</span><span class="k">lambda</span> <span class="n">v</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span> <span class="n">v</span> <span class="o">&lt;=</span> <span class="n">c</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">predicate</span> <span class="o">==</span> <span class="s2">"&gt;"</span><span class="p">:</span>
<span class="n">predicate_is_true</span> <span class="o">=</span> <span class="n">comparison_test</span><span class="p">(</span><span class="k">lambda</span> <span class="n">v</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span> <span class="n">v</span> <span class="o">&gt;</span> <span class="n">c</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">predicate</span> <span class="o">==</span> <span class="s2">"&gt;="</span><span class="p">:</span>
<span class="n">predicate_is_true</span> <span class="o">=</span> <span class="n">comparison_test</span><span class="p">(</span><span class="k">lambda</span> <span class="n">v</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span> <span class="n">v</span> <span class="o">&gt;=</span> <span class="n">c</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">SyntaxError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid predicate: </span><span class="si">{</span><span class="n">predicate</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
<span class="k">return</span> <span class="n">predicate_is_true</span></div>
<div class="viewcode-block" id="PhotoTemplate.get_template_value_multi"><a class="viewcode-back" href="../../reference.html#osxphotos.PhotoTemplate.get_template_value_multi">[docs]</a> <span class="k">def</span> <span class="nf">get_template_value_multi</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">field</span><span class="p">,</span> <span class="n">subfield</span><span class="p">,</span> <span class="n">path_sep</span><span class="p">,</span> <span class="n">default</span><span class="p">):</span>
<span class="sd">"""lookup value for template field (multi-value template substitutions)</span>
@@ -1655,10 +1729,17 @@
<div class="viewcode-block" id="PhotoTemplate.get_template_value_function"><a class="viewcode-back" href="../../reference.html#osxphotos.PhotoTemplate.get_template_value_function">[docs]</a> <span class="k">def</span> <span class="nf">get_template_value_function</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
<span class="n">subfield</span><span class="p">,</span>
<span class="n">field_arg</span><span class="p">,</span>
<span class="n">subfield</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="n">field_arg</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">],</span>
<span class="n">caller</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="p">):</span>
<span class="sd">"""Get template value from external function"""</span>
<span class="sd">"""Get template value from external function</span>
<span class="sd"> Args:</span>
<span class="sd"> subfield: the filename and function name in for filename.py::function</span>
<span class="sd"> field_arg: the argument to pass to the function</span>
<span class="sd"> caller: the calling source of the template ('export' or 'import')</span>
<span class="sd"> """</span>
<span class="k">if</span> <span class="s2">"::"</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">subfield</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
@@ -1677,8 +1758,17 @@
<span class="c1"># if no uuid, then template is being validated but not actually run</span>
<span class="c1"># so don't run the function</span>
<span class="n">values</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">elif</span> <span class="n">caller</span> <span class="o">==</span> <span class="s2">"export"</span><span class="p">:</span>
<span class="c1"># function signature is:</span>
<span class="c1"># def example(photo: PhotoInfo, options: ExportOptions, args: Optional[str] = None, **kwargs) -&gt; Union[List, str]:</span>
<span class="n">values</span> <span class="o">=</span> <span class="n">template_func</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">photo</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="n">field_arg</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">caller</span> <span class="o">==</span> <span class="s2">"import"</span><span class="p">:</span>
<span class="c1"># function signature is:</span>
<span class="c1"># def example(filepath: pathlib.Path, args: Optional[str] = None, **kwargs) -&gt; Union[List, str]:</span>
<span class="c1"># the PhotoInfoFromFile class used by import sets `path` to the path of the file being imported</span>
<span class="n">values</span> <span class="o">=</span> <span class="n">template_func</span><span class="p">(</span><span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">photo</span><span class="o">.</span><span class="n">path</span><span class="p">),</span> <span class="n">args</span><span class="o">=</span><span class="n">field_arg</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unhandled caller: </span><span class="si">{</span><span class="n">caller</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">values</span><span class="p">,</span> <span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="nb">list</span><span class="p">)):</span>
<span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
@@ -1906,6 +1996,24 @@
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">SyntaxError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid slice: </span><span class="si">{</span><span class="n">args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
<span class="k">return</span> <span class="nb">slice</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">step</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">values_to_int</span><span class="p">(</span><span class="n">values</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span>
<span class="sd">"""Convert a list of strings to str representation of ints, if possible, otherwise strip values from list"""</span>
<span class="n">int_values</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">values</span><span class="p">:</span>
<span class="k">with</span> <span class="n">suppress</span><span class="p">(</span><span class="ne">ValueError</span><span class="p">):</span>
<span class="n">int_values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">v</span><span class="p">))))</span>
<span class="k">return</span> <span class="n">int_values</span>
<span class="k">def</span> <span class="nf">values_to_float</span><span class="p">(</span><span class="n">values</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span>
<span class="sd">"""Convert a list of strings to str representation of float, if possible, otherwise strip values from list"""</span>
<span class="n">float_values</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">values</span><span class="p">:</span>
<span class="k">with</span> <span class="n">suppress</span><span class="p">(</span><span class="ne">ValueError</span><span class="p">):</span>
<span class="n">float_values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">v</span><span class="p">)))</span>
<span class="k">return</span> <span class="n">float_values</span>
</pre></div>
</article>
</div>

View File

@@ -61,6 +61,9 @@ Valid filters are:
* `remove(x)`: Remove x from list of values, e.g. remove(b): ['a', 'b', 'c'] => ['a', 'c'].
* `slice(start:stop:step)`: Slice list using same semantics as Python's list slicing, e.g. slice(1:3): ['a', 'b', 'c', 'd'] => ['b', 'c']; slice(1:4:2): ['a', 'b', 'c', 'd'] => ['b', 'd']; slice(1:): ['a', 'b', 'c', 'd'] => ['b', 'c', 'd']; slice(:-1): ['a', 'b', 'c', 'd'] => ['a', 'b', 'c']; slice(::-1): ['a', 'b', 'c', 'd'] => ['d', 'c', 'b', 'a']. See also sslice().
* `sslice(start:stop:step)`: [s(tring) slice] Slice values in a list using same semantics as Python's string slicing, e.g. sslice(1:3):'abcd => 'bc'; sslice(1:4:2): 'abcd' => 'bd', etc. See also slice().
* ``filter(x)``\ : Filter list of values using predicate x; for example, ``{folder_album|filter(contains Events)}`` returns only folders/albums containing the word 'Events' in their path.
* ``int``\ : Convert values in list to integer, e.g. 1.0 => 1. If value cannot be converted to integer, remove value from list. ['1.1', 'x'] => ['1']. See also float.
* ``float``\ : Convert values in list to floating point number, e.g. 1 => 1.0. If value cannot be converted to float, remove value from list. ['1', 'x'] => ['1.0']. See also int.
e.g. if Photo keywords are ``["FOO","bar"]``\ :
@@ -344,9 +347,11 @@ Template Substitutions
* - {cr}
- A carriage return: '\r'
* - {crlf}
- a carriage return + line feed: '\r\n'
- A carriage return + line feed: '\r\n'
* - {tab}
- :A tab: '\t'
* - {osxphotos_version}
- The osxphotos version, e.g. '0.51.0'
- The osxphotos version, e.g. '0.51.4'
* - {osxphotos_cmd_line}
- The full command line used to run osxphotos
* - {album}

View File

@@ -73,6 +73,22 @@ the exported files would be:
/path/to/export/Vacation/IMG_1234.JPG
If your photos are organized in folders and albums in Photos you can preserve this structure on export by using the ``{folder_album}`` template field with the ``--directory`` option. For example, if you have a photo in the album ``Vacation`` which is in the ``Travel`` folder, the following command would export the photo to the ``Travel/Vacation`` directory:
``osxphotos export /path/to/export --directory "{folder_album}"``
Photos can belong to more than one album. In this case, the template field ``{folder_album}`` will expand to all the album names that the photo belongs to. For example, if a photo belongs to the albums ``Vacation`` and ``Travel``\ , the template field ``{folder_album}`` would expand to ``Vacation``\ , ``Travel``. If the photo belongs to no albums, the template field ``{folder_album}`` would expand to "_" (the default value).
All template fields including ``{folder_album}`` can be further filtered using a number of different filters. To convert all directory names to lower case for example, use the ``lower`` filter:
``osxphotos export /path/to/export --directory "{folder_album|lower}"``
If all your photos were organized into various albums under a folder named ``Events`` but some where also included in other top-level albums and you wanted to export only the ``Events`` folder, you could use the ``filter`` option to filter out the other top-level albums by selecting only those folder/album paths that start with ``Events``\ :
``osxphotos export /path/to/export --directory "{folder_album|filter(startswith Events)}"``
You can learn more about the other filters using ``osxphotos help export``.
Specify exported filename
-------------------------
@@ -275,6 +291,14 @@ You can use the ``--report`` option to create a report, in comma-separated value
``osxphotos export /path/to/export --report export.csv``
You can also create reports in JSON or SQLite format by changing the extension of the report filename. For example, to create a JSON report:
``osxphotos export /path/to/export --report export.json``
And to create a SQLite report:
``osxphotos export /path/to/export --report export.sqlite``
Exporting only certain photos
-----------------------------

View File

@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
VERSION: '0.51.0',
VERSION: '0.51.4',
LANGUAGE: 'None',
COLLAPSE_INDEX: false,
BUILDER: 'html',

View File

@@ -6,7 +6,7 @@
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="OSXPhotos Template System" href="template_help.html" /><link rel="prev" title="OSXPhotos Tutorial" href="tutorial.html" />
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/>
<title>OSXPhotos Command Line Interface (CLI) - osxphotos 0.51.0 documentation</title>
<title>OSXPhotos Command Line Interface (CLI) - osxphotos 0.51.4 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=68f4518137b9aefe99b631505a2064c3c42c9852" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
@@ -124,7 +124,7 @@
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">osxphotos 0.51.0 documentation</div></a>
<a href="index.html"><div class="brand">osxphotos 0.51.4 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
@@ -147,7 +147,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="index.html">
<span class="sidebar-brand-text">osxphotos 0.51.0 documentation</span>
<span class="sidebar-brand-text">osxphotos 0.51.4 documentation</span>
</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder=Search name="q" aria-label="Search">
@@ -336,6 +336,11 @@ library specified by db to the database specified by DB2</p>
<span class="sig-name descname"><span class="pre">--deleted-only</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-osxphotos-dump-deleted-only" title="Permalink to this definition">#</a></dt>
<dd><p>Include only photos from the Recently Deleted folder.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-osxphotos-dump-print">
<span class="sig-name descname"><span class="pre">--print</span></span><span class="sig-prename descclassname"> <span class="pre">&lt;TEMPLATE&gt;</span></span><a class="headerlink" href="#cmdoption-osxphotos-dump-print" title="Permalink to this definition">#</a></dt>
<dd><p>Render TEMPLATE string for each photo queried and print to stdout. TEMPLATE is an osxphotos template string. This may be useful for creating custom reports, etc. If print TEMPLATE is provided, regular output is suppressed and only the rendered TEMPLATE values are printed. May be repeated to print multiple template strings.</p>
</dd></dl>
<p class="rubric">Arguments</p>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-osxphotos-dump-arg-PHOTOS_LIBRARY">
@@ -1224,6 +1229,11 @@ to modify this behavior.</p>
<dd><p>If specified, saves the config file but does not export any files; must be used with save-config.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-osxphotos-export-print">
<span class="sig-name descname"><span class="pre">--print</span></span><span class="sig-prename descclassname"> <span class="pre">&lt;TEMPLATE&gt;</span></span><a class="headerlink" href="#cmdoption-osxphotos-export-print" title="Permalink to this definition">#</a></dt>
<dd><p>Render TEMPLATE string for each photo being exported and print to stdout. TEMPLATE is an osxphotos template string. This may be useful for creating custom reports, etc. TEMPLATE will be printed after the photo is exported or skipped. May be repeated to print multiple template strings.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-osxphotos-export-theme">
<span class="sig-name descname"><span class="pre">--theme</span></span><span class="sig-prename descclassname"> <span class="pre">&lt;THEME&gt;</span></span><a class="headerlink" href="#cmdoption-osxphotos-export-theme" title="Permalink to this definition">#</a></dt>
<dd><p>Specify the color theme to use for verbose output. Valid themes are dark, light, mono, and plain. Defaults to dark or light depending on system dark mode setting.</p>
@@ -1455,6 +1465,16 @@ to modify this behavior.</p>
<dd><p>Only import files matching GLOB. GLOB is a Unix shell-style glob pattern, for example: glob “<a href="#id1"><span class="problematic" id="id2">*</span></a>.jpg”. GLOB may be repeated to import multiple patterns.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-osxphotos-import-report">
<span class="sig-name descname"><span class="pre">--report</span></span><span class="sig-prename descclassname"> <span class="pre">&lt;REPORT_FILE&gt;</span></span><a class="headerlink" href="#cmdoption-osxphotos-import-report" title="Permalink to this definition">#</a></dt>
<dd><p>Write a report of all files that were imported. The extension of the report filename will be used to determine the format. Valid extensions are: .csv (CSV file), .json (JSON), .db and .sqlite (SQLite database). REPORT_FILE may be a template string (see Template System), for example, report export_{today.date}.csv will write a CSV report file named with todays date. See also append.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-osxphotos-import-append">
<span class="sig-name descname"><span class="pre">--append</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-osxphotos-import-append" title="Permalink to this definition">#</a></dt>
<dd><p>If used with report, add data to existing report file instead of overwriting it. See also report.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-osxphotos-import-V">
<span id="cmdoption-osxphotos-import-v"></span><span id="cmdoption-osxphotos-import-verbose"></span><span class="sig-name descname"><span class="pre">-V</span></span><span class="sig-prename descclassname"></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">--verbose</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-osxphotos-import-V" title="Permalink to this definition">#</a></dt>
<dd><p>Print verbose output.</p>
@@ -2142,6 +2162,16 @@ if more than one option is provided, they are treated as “AND”
<span class="sig-name descname"><span class="pre">--add-to-album</span></span><span class="sig-prename descclassname"> <span class="pre">&lt;ALBUM&gt;</span></span><a class="headerlink" href="#cmdoption-osxphotos-query-add-to-album" title="Permalink to this definition">#</a></dt>
<dd><p>Add all photos from query to album ALBUM in Photos. Album ALBUM will be created if it doesnt exist. All photos in the query results will be added to this album. This only works if the Photos library being queried is the last-opened (default) library in Photos. This feature is currently experimental. I dont know how well it will work on large query sets.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-osxphotos-query-quiet">
<span class="sig-name descname"><span class="pre">--quiet</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-osxphotos-query-quiet" title="Permalink to this definition">#</a></dt>
<dd><p>Quiet output; doesnt actually print query results. Useful with print and add-to-album if you dont want to see the actual query results.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-osxphotos-query-print">
<span class="sig-name descname"><span class="pre">--print</span></span><span class="sig-prename descclassname"> <span class="pre">&lt;TEMPLATE&gt;</span></span><a class="headerlink" href="#cmdoption-osxphotos-query-print" title="Permalink to this definition">#</a></dt>
<dd><p>Render TEMPLATE string for each photo queried and print to stdout. TEMPLATE is an osxphotos template string. This may be useful for creating custom reports, etc. Most useful with quiet. May be repeated to print multiple template strings.</p>
</dd></dl>
<p class="rubric">Arguments</p>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-osxphotos-query-arg-PHOTOS_LIBRARY">

View File

@@ -4,7 +4,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="color-scheme" content="light dark"><link rel="index" title="Index" href="#" /><link rel="search" title="Search" href="search.html" />
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/><title>Index - osxphotos 0.51.0 documentation</title>
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/><title>Index - osxphotos 0.51.4 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=68f4518137b9aefe99b631505a2064c3c42c9852" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
@@ -122,7 +122,7 @@
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">osxphotos 0.51.0 documentation</div></a>
<a href="index.html"><div class="brand">osxphotos 0.51.4 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
@@ -145,7 +145,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="index.html">
<span class="sidebar-brand-text">osxphotos 0.51.0 documentation</span>
<span class="sidebar-brand-text">osxphotos 0.51.4 documentation</span>
</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder=Search name="q" aria-label="Search">
@@ -295,6 +295,8 @@
<li><a href="cli.html#cmdoption-osxphotos-export-append">osxphotos-export command line option</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-exportdb-append">osxphotos-exportdb command line option</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-import-append">osxphotos-import command line option</a>
</li>
</ul></li>
<li>
@@ -1265,8 +1267,6 @@
<li><a href="cli.html#cmdoption-osxphotos-repl-not-cloudasset">osxphotos-repl command line option</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li>
--not-favorite
@@ -1278,6 +1278,8 @@
<li><a href="cli.html#cmdoption-osxphotos-repl-not-favorite">osxphotos-repl command line option</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li>
--not-hdr
@@ -1573,6 +1575,17 @@
<ul>
<li><a href="cli.html#cmdoption-osxphotos-export-preview-suffix">osxphotos-export command line option</a>
</li>
</ul></li>
<li>
--print
<ul>
<li><a href="cli.html#cmdoption-osxphotos-dump-print">osxphotos-dump command line option</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-export-print">osxphotos-export command line option</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-print">osxphotos-query command line option</a>
</li>
</ul></li>
<li>
@@ -1609,6 +1622,13 @@
<li><a href="cli.html#cmdoption-osxphotos-query-query-function">osxphotos-query command line option</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-repl-query-function">osxphotos-repl command line option</a>
</li>
</ul></li>
<li>
--quiet
<ul>
<li><a href="cli.html#cmdoption-osxphotos-query-quiet">osxphotos-query command line option</a>
</li>
</ul></li>
<li>
@@ -1661,6 +1681,8 @@
<li><a href="cli.html#cmdoption-osxphotos-export-report">osxphotos-export command line option</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-exportdb-report">osxphotos-exportdb command line option</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-import-report">osxphotos-import command line option</a>
</li>
</ul></li>
<li>
@@ -2687,6 +2709,8 @@
<li><a href="reference.html#osxphotos.ExportOptions.fileutil">fileutil (osxphotos.ExportOptions attribute)</a>
</li>
<li><a href="reference.html#osxphotos.FileUtilNoOp">FileUtilNoOp (class in osxphotos)</a>
</li>
<li><a href="reference.html#osxphotos.PhotoTemplate.filter_predicate">filter_predicate() (osxphotos.PhotoTemplate method)</a>
</li>
<li><a href="reference.html#osxphotos.QueryOptions.folder">folder (osxphotos.QueryOptions attribute)</a>
</li>
@@ -3140,6 +3164,8 @@
<li><a href="cli.html#cmdoption-osxphotos-dump-deleted-only">--deleted-only</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-dump-json">--json</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-dump-print">--print</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-dump-arg-PHOTOS_LIBRARY">PHOTOS_LIBRARY</a>
</li>
@@ -3408,6 +3434,8 @@
<li><a href="cli.html#cmdoption-osxphotos-export-preview-if-missing">--preview-if-missing</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-export-preview-suffix">--preview-suffix</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-export-print">--print</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-export-query-eval">--query-eval</a>
</li>
@@ -3559,6 +3587,8 @@
<ul>
<li><a href="cli.html#cmdoption-osxphotos-import-a">--album</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-import-append">--append</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-import-check-templates">--check-templates</a>
</li>
@@ -3585,6 +3615,8 @@
<li><a href="cli.html#cmdoption-osxphotos-import-no-progress">--no-progress</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-import-r">--relative-to</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-import-report">--report</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-import-f">--split-folder</a>
</li>
@@ -3881,10 +3913,14 @@
<li><a href="cli.html#cmdoption-osxphotos-query-place">--place</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-portrait">--portrait</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-print">--print</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-query-eval">--query-eval</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-query-function">--query-function</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-quiet">--quiet</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-regex">--regex</a>
</li>

View File

@@ -6,7 +6,7 @@
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="OSXPhotos" href="overview.html" />
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/>
<title>osxphotos 0.51.0 documentation</title>
<title>osxphotos 0.51.4 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=68f4518137b9aefe99b631505a2064c3c42c9852" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
@@ -124,7 +124,7 @@
</label>
</div>
<div class="header-center">
<a href="#"><div class="brand">osxphotos 0.51.0 documentation</div></a>
<a href="#"><div class="brand">osxphotos 0.51.4 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
@@ -147,7 +147,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="#">
<span class="sidebar-brand-text">osxphotos 0.51.0 documentation</span>
<span class="sidebar-brand-text">osxphotos 0.51.4 documentation</span>
</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder=Search name="q" aria-label="Search">

Binary file not shown.

View File

@@ -6,7 +6,7 @@
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="OSXPhotos Tutorial" href="tutorial.html" /><link rel="prev" title="Welcome to OSXPhotoss documentation!" href="index.html" />
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/>
<title>OSXPhotos - osxphotos 0.51.0 documentation</title>
<title>OSXPhotos - osxphotos 0.51.4 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=68f4518137b9aefe99b631505a2064c3c42c9852" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
@@ -124,7 +124,7 @@
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">osxphotos 0.51.0 documentation</div></a>
<a href="index.html"><div class="brand">osxphotos 0.51.4 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
@@ -147,7 +147,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="index.html">
<span class="sidebar-brand-text">osxphotos 0.51.0 documentation</span>
<span class="sidebar-brand-text">osxphotos 0.51.4 documentation</span>
</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder=Search name="q" aria-label="Search">

View File

@@ -6,7 +6,7 @@
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="OSXPhotos python API" href="reference.html" /><link rel="prev" title="OSXPhotos Template System" href="template_help.html" />
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/>
<title>OSXPhotos Python Package Overview - osxphotos 0.51.0 documentation</title>
<title>OSXPhotos Python Package Overview - osxphotos 0.51.4 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=68f4518137b9aefe99b631505a2064c3c42c9852" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
@@ -124,7 +124,7 @@
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">osxphotos 0.51.0 documentation</div></a>
<a href="index.html"><div class="brand">osxphotos 0.51.4 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
@@ -147,7 +147,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="index.html">
<span class="sidebar-brand-text">osxphotos 0.51.0 documentation</span>
<span class="sidebar-brand-text">osxphotos 0.51.4 documentation</span>
</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder=Search name="q" aria-label="Search">

View File

@@ -4,7 +4,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="color-scheme" content="light dark"><link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" />
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/><title>Python Module Index - osxphotos 0.51.0 documentation</title>
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/><title>Python Module Index - osxphotos 0.51.4 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=68f4518137b9aefe99b631505a2064c3c42c9852" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
@@ -122,7 +122,7 @@
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">osxphotos 0.51.0 documentation</div></a>
<a href="index.html"><div class="brand">osxphotos 0.51.4 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
@@ -145,7 +145,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="index.html">
<span class="sidebar-brand-text">osxphotos 0.51.0 documentation</span>
<span class="sidebar-brand-text">osxphotos 0.51.4 documentation</span>
</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder=Search name="q" aria-label="Search">

View File

@@ -6,7 +6,7 @@
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="prev" title="OSXPhotos Python Package Overview" href="package_overview.html" />
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/>
<title>OSXPhotos python API - osxphotos 0.51.0 documentation</title>
<title>OSXPhotos python API - osxphotos 0.51.4 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=68f4518137b9aefe99b631505a2064c3c42c9852" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
@@ -124,7 +124,7 @@
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">osxphotos 0.51.0 documentation</div></a>
<a href="index.html"><div class="brand">osxphotos 0.51.4 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
@@ -147,7 +147,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="index.html">
<span class="sidebar-brand-text">osxphotos 0.51.0 documentation</span>
<span class="sidebar-brand-text">osxphotos 0.51.4 documentation</span>
</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder=Search name="q" aria-label="Search">
@@ -1844,6 +1844,11 @@ Enforce that the expanded value is a single value, raises ValueError if not.</p>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="osxphotos.PhotoTemplate.filter_predicate">
<span class="sig-name descname"><span class="pre">filter_predicate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon"></span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="reference internal" href="_modules/osxphotos/phototemplate.html#PhotoTemplate.filter_predicate"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#osxphotos.PhotoTemplate.filter_predicate" title="Permalink to this definition">#</a></dt>
<dd><p>Return True if value passes predicate</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="osxphotos.PhotoTemplate.get_field_values">
<span class="sig-name descname"><span class="pre">get_field_values</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">field</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">subfield</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">field_arg</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">List</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon"></span> <span class="sig-return-typehint"><span class="pre">Tuple</span><span class="p"><span class="pre">[</span></span><span class="pre">List</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">List</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span></span><a class="reference internal" href="_modules/osxphotos/phototemplate.html#PhotoTemplate.get_field_values"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#osxphotos.PhotoTemplate.get_field_values" title="Permalink to this definition">#</a></dt>
<dd><p>Get the values for a field</p>
@@ -1908,8 +1913,17 @@ Enforce that the expanded value is a single value, raises ValueError if not.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="osxphotos.PhotoTemplate.get_template_value_function">
<span class="sig-name descname"><span class="pre">get_template_value_function</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">subfield</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">field_arg</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/osxphotos/phototemplate.html#PhotoTemplate.get_template_value_function"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#osxphotos.PhotoTemplate.get_template_value_function" title="Permalink to this definition">#</a></dt>
<span class="sig-name descname"><span class="pre">get_template_value_function</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">subfield</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">field_arg</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">caller</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/osxphotos/phototemplate.html#PhotoTemplate.get_template_value_function"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#osxphotos.PhotoTemplate.get_template_value_function" title="Permalink to this definition">#</a></dt>
<dd><p>Get template value from external function</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>subfield</strong> the filename and function name in for filename.py::function</p></li>
<li><p><strong>field_arg</strong> the argument to pass to the function</p></li>
<li><p><strong>caller</strong> the calling source of the template (export or import)</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="osxphotos.PhotoTemplate.get_template_value_multi">

View File

@@ -4,7 +4,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="color-scheme" content="light dark"><link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="#" />
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/><title>Search - osxphotos 0.51.0 documentation</title><link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/><title>Search - osxphotos 0.51.4 documentation</title><link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=68f4518137b9aefe99b631505a2064c3c42c9852" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo-extensions.css?digest=30d1aed668e5c3a91c3e3bf6a60b675221979f0e" />
@@ -121,7 +121,7 @@
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">osxphotos 0.51.0 documentation</div></a>
<a href="index.html"><div class="brand">osxphotos 0.51.4 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
@@ -144,7 +144,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="index.html">
<span class="sidebar-brand-text">osxphotos 0.51.0 documentation</span>
<span class="sidebar-brand-text">osxphotos 0.51.4 documentation</span>
</a><form class="sidebar-search-container" method="get" action="#" role="search">
<input class="sidebar-search" placeholder=Search name="q" aria-label="Search">

File diff suppressed because one or more lines are too long

View File

@@ -6,7 +6,7 @@
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="OSXPhotos Python Package Overview" href="package_overview.html" /><link rel="prev" title="OSXPhotos Command Line Interface (CLI)" href="cli.html" />
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/>
<title>OSXPhotos Template System - osxphotos 0.51.0 documentation</title>
<title>OSXPhotos Template System - osxphotos 0.51.4 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=68f4518137b9aefe99b631505a2064c3c42c9852" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
@@ -124,7 +124,7 @@
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">osxphotos 0.51.0 documentation</div></a>
<a href="index.html"><div class="brand">osxphotos 0.51.4 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
@@ -147,7 +147,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="index.html">
<span class="sidebar-brand-text">osxphotos 0.51.0 documentation</span>
<span class="sidebar-brand-text">osxphotos 0.51.4 documentation</span>
</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder=Search name="q" aria-label="Search">
@@ -241,6 +241,9 @@
<li><p><cite>remove(x)</cite>: Remove x from list of values, e.g. remove(b): [a, b, c] =&gt; [a, c].</p></li>
<li><p><cite>slice(start:stop:step)</cite>: Slice list using same semantics as Pythons list slicing, e.g. slice(1:3): [a, b, c, d] =&gt; [b, c]; slice(1:4:2): [a, b, c, d] =&gt; [b, d]; slice(1:): [a, b, c, d] =&gt; [b, c, d]; slice(:-1): [a, b, c, d] =&gt; [a, b, c]; slice(::-1): [a, b, c, d] =&gt; [d, c, b, a]. See also sslice().</p></li>
<li><p><cite>sslice(start:stop:step)</cite>: [s(tring) slice] Slice values in a list using same semantics as Pythons string slicing, e.g. sslice(1:3):abcd =&gt; bc; sslice(1:4:2): abcd =&gt; bd, etc. See also slice().</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">filter(x)</span></code>: Filter list of values using predicate x; for example, <code class="docutils literal notranslate"><span class="pre">{folder_album|filter(contains</span> <span class="pre">Events)}</span></code> returns only folders/albums containing the word Events in their path.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">int</span></code>: Convert values in list to integer, e.g. 1.0 =&gt; 1. If value cannot be converted to integer, remove value from list. [1.1, x] =&gt; [1]. See also float.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">float</span></code>: Convert values in list to floating point number, e.g. 1 =&gt; 1.0. If value cannot be converted to float, remove value from list. [1, x] =&gt; [1.0]. See also int.</p></li>
</ul>
<p>e.g. if Photo keywords are <code class="docutils literal notranslate"><span class="pre">["FOO","bar"]</span></code>:</p>
<ul class="simple">
@@ -586,75 +589,83 @@
<td><p>A carriage return: r</p></td>
</tr>
<tr class="row-odd"><td><p>{crlf}</p></td>
<td><p>a carriage return + line feed: rn</p></td>
<td><p>A carriage return + line feed: rn</p></td>
</tr>
<tr class="row-even"><td><p>{osxphotos_version}</p></td>
<td><p>The osxphotos version, e.g. 0.51.0</p></td>
<tr class="row-even"><td><p>{tab}</p></td>
<td><dl class="field-list simple">
<dt class="field-odd">A tab</dt>
<dd class="field-odd"><p>t</p>
</dd>
</dl>
</td>
</tr>
<tr class="row-odd"><td><p>{osxphotos_cmd_line}</p></td>
<tr class="row-odd"><td><p>{osxphotos_version}</p></td>
<td><p>The osxphotos version, e.g. 0.51.4</p></td>
</tr>
<tr class="row-even"><td><p>{osxphotos_cmd_line}</p></td>
<td><p>The full command line used to run osxphotos</p></td>
</tr>
<tr class="row-even"><td><p>{album}</p></td>
<tr class="row-odd"><td><p>{album}</p></td>
<td><p>Album(s) photo is contained in</p></td>
</tr>
<tr class="row-odd"><td><p>{folder_album}</p></td>
<tr class="row-even"><td><p>{folder_album}</p></td>
<td><p>Folder path + album photo is contained in. e.g. Folder/Subfolder/Album or just Album if no enclosing folder</p></td>
</tr>
<tr class="row-even"><td><p>{project}</p></td>
<tr class="row-odd"><td><p>{project}</p></td>
<td><p>Project(s) photo is contained in (such as greeting cards, calendars, slideshows)</p></td>
</tr>
<tr class="row-odd"><td><p>{album_project}</p></td>
<tr class="row-even"><td><p>{album_project}</p></td>
<td><p>Album(s) and project(s) photo is contained in; treats projects as regular albums</p></td>
</tr>
<tr class="row-even"><td><p>{folder_album_project}</p></td>
<tr class="row-odd"><td><p>{folder_album_project}</p></td>
<td><p>Folder path + album (includes projects as albums) photo is contained in. e.g. Folder/Subfolder/Album or just Album if no enclosing folder</p></td>
</tr>
<tr class="row-odd"><td><p>{keyword}</p></td>
<tr class="row-even"><td><p>{keyword}</p></td>
<td><p>Keyword(s) assigned to photo</p></td>
</tr>
<tr class="row-even"><td><p>{person}</p></td>
<tr class="row-odd"><td><p>{person}</p></td>
<td><p>Person(s) / face(s) in a photo</p></td>
</tr>
<tr class="row-odd"><td><p>{label}</p></td>
<tr class="row-even"><td><p>{label}</p></td>
<td><p>Image categorization label associated with a photo (Photos 5+ only). Labels are added automatically by Photos using machine learning algorithms to categorize images. These are not the same as {keyword} which refers to the user-defined keywords/tags applied in Photos.</p></td>
</tr>
<tr class="row-even"><td><p>{label_normalized}</p></td>
<tr class="row-odd"><td><p>{label_normalized}</p></td>
<td><p>All lower case version of label (Photos 5+ only)</p></td>
</tr>
<tr class="row-odd"><td><p>{comment}</p></td>
<tr class="row-even"><td><p>{comment}</p></td>
<td><p>Comment(s) on shared Photos; format is Person name: comment text (Photos 5+ only)</p></td>
</tr>
<tr class="row-even"><td><p>{exiftool}</p></td>
<tr class="row-odd"><td><p>{exiftool}</p></td>
<td><p>Format: {exiftool:GROUP:TAGNAME}; use exiftool (https://exiftool.org) to extract metadata, in form GROUP:TAGNAME, from image. E.g. {exiftool:EXIF:Make} to get camera make, or {exiftool:IPTC:Keywords} to extract keywords. See https://exiftool.org/TagNames/ for list of valid tag names. You must specify group (e.g. EXIF, IPTC, etc) as used in <code class="docutils literal notranslate"><span class="pre">exiftool</span> <span class="pre">-G</span></code>. exiftool must be installed in the path to use this template.</p></td>
</tr>
<tr class="row-odd"><td><p>{searchinfo.holiday}</p></td>
<tr class="row-even"><td><p>{searchinfo.holiday}</p></td>
<td><p>Holiday names associated with a photo, e.g. Christmas Day; (Photos 5+ only, applied automatically by Photos image categorization algorithms).</p></td>
</tr>
<tr class="row-even"><td><p>{searchinfo.activity}</p></td>
<tr class="row-odd"><td><p>{searchinfo.activity}</p></td>
<td><p>Activities associated with a photo, e.g. Sporting Event; (Photos 5+ only, applied automatically by Photos image categorization algorithms).</p></td>
</tr>
<tr class="row-odd"><td><p>{searchinfo.venue}</p></td>
<tr class="row-even"><td><p>{searchinfo.venue}</p></td>
<td><p>Venues associated with a photo, e.g. name of restaurant; (Photos 5+ only, applied automatically by Photos image categorization algorithms).</p></td>
</tr>
<tr class="row-even"><td><p>{searchinfo.venue_type}</p></td>
<tr class="row-odd"><td><p>{searchinfo.venue_type}</p></td>
<td><p>Venue types associated with a photo, e.g. Restaurant; (Photos 5+ only, applied automatically by Photos image categorization algorithms).</p></td>
</tr>
<tr class="row-odd"><td><p>{photo}</p></td>
<tr class="row-even"><td><p>{photo}</p></td>
<td><p>Provides direct access to the PhotoInfo object for the photo. Must be used in format {photo.property} where property represents a PhotoInfo property. For example: {photo.favorite} is the same as {favorite} and {photo.place.name} is the same as {place.name}. {photo} provides access to properties that are not available as separate template fields but it assumes some knowledge of the underlying PhotoInfo class. See <a class="reference external" href="https://rhettbull.github.io/osxphotos/">https://rhettbull.github.io/osxphotos/</a> for additional documentation on the PhotoInfo class.</p></td>
</tr>
<tr class="row-even"><td><p>{detected_text}</p></td>
<tr class="row-odd"><td><p>{detected_text}</p></td>
<td><p>List of text strings found in the image after performing text detection. Using {detected_text} will cause osxphotos to perform text detection on your photos using the built-in macOS text detection algorithms which will slow down your export. The results for each photo will be cached in the export database so that future exports with update do not need to reprocess each photo. You may pass a confidence threshold value between 0.0 and 1.0 after a colon as in {detected_text:0.5}; The default confidence threshold is 0.75. {detected_text} works only on macOS Catalina (10.15) or later. Note: this feature is not the same thing as Live Text in macOS Monterey, which osxphotos does not yet support.</p></td>
</tr>
<tr class="row-odd"><td><p>{shell_quote}</p></td>
<tr class="row-even"><td><p>{shell_quote}</p></td>
<td><p>Use in form {shell_quote,TEMPLATE}; quotes the rendered TEMPLATE value(s) for safe usage in the shell, e.g. My file.jpeg =&gt; My file.jpeg; only adds quotes if needed.</p></td>
</tr>
<tr class="row-even"><td><p>{strip}</p></td>
<tr class="row-odd"><td><p>{strip}</p></td>
<td><p>Use in form {strip,TEMPLATE}; strips whitespace from begining and end of rendered TEMPLATE value(s).</p></td>
</tr>
<tr class="row-odd"><td><p>{format}</p></td>
<tr class="row-even"><td><p>{format}</p></td>
<td><p>Use in form, {format:TYPE:FORMAT,TEMPLATE}; converts TEMPLATE value to TYPE then formats the value using Python string formatting codes specified by FORMAT; TYPE is one of: int, float, or str. For example, {format:float:.1f,{exiftool:EXIF:FocalLength}} will format focal length to 1 decimal place (e.g. 100.0).</p></td>
</tr>
<tr class="row-even"><td><p>{function}</p></td>
<tr class="row-odd"><td><p>{function}</p></td>
<td><p>Execute a python function from an external file and use return value as template substitution. Use in format: {function:file.py::function_name} where file.py is the name of the python file and function_name is the name of the function to call. The function will be passed the PhotoInfo object for the photo. See https://github.com/RhetTbull/osxphotos/blob/master/examples/template_function.py for an example of how to implement a template function.</p></td>
</tr>
</tbody>

View File

@@ -6,7 +6,7 @@
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="OSXPhotos Command Line Interface (CLI)" href="cli.html" /><link rel="prev" title="OSXPhotos" href="overview.html" />
<meta name="generator" content="sphinx-4.4.0, furo 2022.04.07"/>
<title>OSXPhotos Tutorial - osxphotos 0.51.0 documentation</title>
<title>OSXPhotos Tutorial - osxphotos 0.51.4 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=68f4518137b9aefe99b631505a2064c3c42c9852" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
@@ -124,7 +124,7 @@
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">osxphotos 0.51.0 documentation</div></a>
<a href="index.html"><div class="brand">osxphotos 0.51.4 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
@@ -147,7 +147,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="index.html">
<span class="sidebar-brand-text">osxphotos 0.51.0 documentation</span>
<span class="sidebar-brand-text">osxphotos 0.51.4 documentation</span>
</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder=Search name="q" aria-label="Search">
@@ -229,6 +229,14 @@
<span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">export</span><span class="o">/</span><span class="n">Vacation</span><span class="o">/</span><span class="n">IMG_1234</span><span class="o">.</span><span class="n">JPG</span>
</pre></div>
</div>
<p>If your photos are organized in folders and albums in Photos you can preserve this structure on export by using the <code class="docutils literal notranslate"><span class="pre">{folder_album}</span></code> template field with the <code class="docutils literal notranslate"><span class="pre">--directory</span></code> option. For example, if you have a photo in the album <code class="docutils literal notranslate"><span class="pre">Vacation</span></code> which is in the <code class="docutils literal notranslate"><span class="pre">Travel</span></code> folder, the following command would export the photo to the <code class="docutils literal notranslate"><span class="pre">Travel/Vacation</span></code> directory:</p>
<p><code class="docutils literal notranslate"><span class="pre">osxphotos</span> <span class="pre">export</span> <span class="pre">/path/to/export</span> <span class="pre">--directory</span> <span class="pre">"{folder_album}"</span></code></p>
<p>Photos can belong to more than one album. In this case, the template field <code class="docutils literal notranslate"><span class="pre">{folder_album}</span></code> will expand to all the album names that the photo belongs to. For example, if a photo belongs to the albums <code class="docutils literal notranslate"><span class="pre">Vacation</span></code> and <code class="docutils literal notranslate"><span class="pre">Travel</span></code>, the template field <code class="docutils literal notranslate"><span class="pre">{folder_album}</span></code> would expand to <code class="docutils literal notranslate"><span class="pre">Vacation</span></code>, <code class="docutils literal notranslate"><span class="pre">Travel</span></code>. If the photo belongs to no albums, the template field <code class="docutils literal notranslate"><span class="pre">{folder_album}</span></code> would expand to “_” (the default value).</p>
<p>All template fields including <code class="docutils literal notranslate"><span class="pre">{folder_album}</span></code> can be further filtered using a number of different filters. To convert all directory names to lower case for example, use the <code class="docutils literal notranslate"><span class="pre">lower</span></code> filter:</p>
<p><code class="docutils literal notranslate"><span class="pre">osxphotos</span> <span class="pre">export</span> <span class="pre">/path/to/export</span> <span class="pre">--directory</span> <span class="pre">"{folder_album|lower}"</span></code></p>
<p>If all your photos were organized into various albums under a folder named <code class="docutils literal notranslate"><span class="pre">Events</span></code> but some where also included in other top-level albums and you wanted to export only the <code class="docutils literal notranslate"><span class="pre">Events</span></code> folder, you could use the <code class="docutils literal notranslate"><span class="pre">filter</span></code> option to filter out the other top-level albums by selecting only those folder/album paths that start with <code class="docutils literal notranslate"><span class="pre">Events</span></code>:</p>
<p><code class="docutils literal notranslate"><span class="pre">osxphotos</span> <span class="pre">export</span> <span class="pre">/path/to/export</span> <span class="pre">--directory</span> <span class="pre">"{folder_album|filter(startswith</span> <span class="pre">Events)}"</span></code></p>
<p>You can learn more about the other filters using <code class="docutils literal notranslate"><span class="pre">osxphotos</span> <span class="pre">help</span> <span class="pre">export</span></code>.</p>
</section>
<section id="specify-exported-filename">
<h2>Specify exported filename<a class="headerlink" href="#specify-exported-filename" title="Permalink to this headline">#</a></h2>
@@ -367,6 +375,10 @@
<h2>Creating a report of all exported files<a class="headerlink" href="#creating-a-report-of-all-exported-files" title="Permalink to this headline">#</a></h2>
<p>You can use the <code class="docutils literal notranslate"><span class="pre">--report</span></code> option to create a report, in comma-separated values (CSV) format that will list the details of all files that were exported, skipped, missing, etc. This file format is compatible with programs such as Microsoft Excel. Provide the name of the report after the <code class="docutils literal notranslate"><span class="pre">--report</span></code> option:</p>
<p><code class="docutils literal notranslate"><span class="pre">osxphotos</span> <span class="pre">export</span> <span class="pre">/path/to/export</span> <span class="pre">--report</span> <span class="pre">export.csv</span></code></p>
<p>You can also create reports in JSON or SQLite format by changing the extension of the report filename. For example, to create a JSON report:</p>
<p><code class="docutils literal notranslate"><span class="pre">osxphotos</span> <span class="pre">export</span> <span class="pre">/path/to/export</span> <span class="pre">--report</span> <span class="pre">export.json</span></code></p>
<p>And to create a SQLite report:</p>
<p><code class="docutils literal notranslate"><span class="pre">osxphotos</span> <span class="pre">export</span> <span class="pre">/path/to/export</span> <span class="pre">--report</span> <span class="pre">export.sqlite</span></code></p>
</section>
<section id="exporting-only-certain-photos">
<h2>Exporting only certain photos<a class="headerlink" href="#exporting-only-certain-photos" title="Permalink to this headline">#</a></h2>

View File

@@ -61,6 +61,9 @@ Valid filters are:
* `remove(x)`: Remove x from list of values, e.g. remove(b): ['a', 'b', 'c'] => ['a', 'c'].
* `slice(start:stop:step)`: Slice list using same semantics as Python's list slicing, e.g. slice(1:3): ['a', 'b', 'c', 'd'] => ['b', 'c']; slice(1:4:2): ['a', 'b', 'c', 'd'] => ['b', 'd']; slice(1:): ['a', 'b', 'c', 'd'] => ['b', 'c', 'd']; slice(:-1): ['a', 'b', 'c', 'd'] => ['a', 'b', 'c']; slice(::-1): ['a', 'b', 'c', 'd'] => ['d', 'c', 'b', 'a']. See also sslice().
* `sslice(start:stop:step)`: [s(tring) slice] Slice values in a list using same semantics as Python's string slicing, e.g. sslice(1:3):'abcd => 'bc'; sslice(1:4:2): 'abcd' => 'bd', etc. See also slice().
* ``filter(x)``\ : Filter list of values using predicate x; for example, ``{folder_album|filter(contains Events)}`` returns only folders/albums containing the word 'Events' in their path.
* ``int``\ : Convert values in list to integer, e.g. 1.0 => 1. If value cannot be converted to integer, remove value from list. ['1.1', 'x'] => ['1']. See also float.
* ``float``\ : Convert values in list to floating point number, e.g. 1 => 1.0. If value cannot be converted to float, remove value from list. ['1', 'x'] => ['1.0']. See also int.
e.g. if Photo keywords are ``["FOO","bar"]``\ :
@@ -344,9 +347,11 @@ Template Substitutions
* - {cr}
- A carriage return: '\r'
* - {crlf}
- a carriage return + line feed: '\r\n'
- A carriage return + line feed: '\r\n'
* - {tab}
- :A tab: '\t'
* - {osxphotos_version}
- The osxphotos version, e.g. '0.51.0'
- The osxphotos version, e.g. '0.51.4'
* - {osxphotos_cmd_line}
- The full command line used to run osxphotos
* - {album}

View File

@@ -73,6 +73,22 @@ the exported files would be:
/path/to/export/Vacation/IMG_1234.JPG
If your photos are organized in folders and albums in Photos you can preserve this structure on export by using the ``{folder_album}`` template field with the ``--directory`` option. For example, if you have a photo in the album ``Vacation`` which is in the ``Travel`` folder, the following command would export the photo to the ``Travel/Vacation`` directory:
``osxphotos export /path/to/export --directory "{folder_album}"``
Photos can belong to more than one album. In this case, the template field ``{folder_album}`` will expand to all the album names that the photo belongs to. For example, if a photo belongs to the albums ``Vacation`` and ``Travel``\ , the template field ``{folder_album}`` would expand to ``Vacation``\ , ``Travel``. If the photo belongs to no albums, the template field ``{folder_album}`` would expand to "_" (the default value).
All template fields including ``{folder_album}`` can be further filtered using a number of different filters. To convert all directory names to lower case for example, use the ``lower`` filter:
``osxphotos export /path/to/export --directory "{folder_album|lower}"``
If all your photos were organized into various albums under a folder named ``Events`` but some where also included in other top-level albums and you wanted to export only the ``Events`` folder, you could use the ``filter`` option to filter out the other top-level albums by selecting only those folder/album paths that start with ``Events``\ :
``osxphotos export /path/to/export --directory "{folder_album|filter(startswith Events)}"``
You can learn more about the other filters using ``osxphotos help export``.
Specify exported filename
-------------------------
@@ -275,6 +291,14 @@ You can use the ``--report`` option to create a report, in comma-separated value
``osxphotos export /path/to/export --report export.csv``
You can also create reports in JSON or SQLite format by changing the extension of the report filename. For example, to create a JSON report:
``osxphotos export /path/to/export --report export.json``
And to create a SQLite report:
``osxphotos export /path/to/export --report export.sqlite``
Exporting only certain photos
-----------------------------

View File

@@ -0,0 +1,27 @@
""" Example showing how to use a custom function for osxphotos {function} template with the `osxphotos import` command
Use: osxphotos import /path/to/import/*.jpg --album "{function:/path/to/template_function_import.py::example}"
You may place more than one template function in a single file as each is called by name using the {function:file.py::function_name} format
"""
import pathlib
from typing import List, Optional, Union
def example(
filepath: pathlib.Path, args: Optional[str] = None, **kwargs
) -> Union[List, str]:
"""example function for {function} template for use with `osxphotos import`
This example parses filenames in format album_img_123.jpg and returns the album name
Args:
filepath: pathlib.Path object of file being imported
args: optional str of arguments passed to template function
**kwargs: not currently used, placeholder to keep functions compatible with possible changes to {function}
Returns:
str or list of str of values that should be substituted for the {function} template
"""
filename = filepath.stem
fields = filename.split("_")
return fields[0] if len(fields) > 1 else ""

View File

@@ -1,3 +1,3 @@
""" version info """
__version__ = "0.51.0"
__version__ = "0.51.4"

View File

@@ -35,6 +35,7 @@ __all__ = [
"DB_OPTION",
"DEBUG_OPTIONS",
"DELETED_OPTIONS",
"FIELD_OPTION",
"JSON_OPTION",
"QUERY_OPTIONS",
"THEME_OPTION",
@@ -116,6 +117,19 @@ JSON_OPTION = click.option(
help="Print output in JSON format.",
)
FIELD_OPTION = click.option(
"--field",
"-f",
metavar="FIELD TEMPLATE",
multiple=True,
nargs=2,
help="Output only specified custom fields. "
"FIELD is the name of the field and TEMPLATE is the template to use as the field value. "
"May be repeated to output multiple fields. "
"For example, to output photo uuid, name, and title: "
'`--field uuid "{uuid}" --field name "{original_name}" --field title "{title}"`.',
)
def DELETED_OPTIONS(f):
o = click.option

View File

@@ -3,24 +3,66 @@
import click
import osxphotos
from osxphotos.cli.click_rich_echo import (
rich_click_echo,
set_rich_console,
set_rich_theme,
)
from osxphotos.phototemplate import RenderOptions
from osxphotos.queryoptions import QueryOptions
from .common import DB_ARGUMENT, DB_OPTION, DELETED_OPTIONS, JSON_OPTION, get_photos_db
from .color_themes import get_default_theme
from .common import (
DB_ARGUMENT,
DB_OPTION,
DELETED_OPTIONS,
FIELD_OPTION,
JSON_OPTION,
get_photos_db,
)
from .list import _list_libraries
from .print_photo_info import print_photo_info
from .print_photo_info import print_photo_fields, print_photo_info
from .verbose import get_verbose_console
@click.command()
@DB_OPTION
@JSON_OPTION
@DELETED_OPTIONS
@FIELD_OPTION
@click.option(
"--print",
"print_template",
metavar="TEMPLATE",
multiple=True,
help="Render TEMPLATE string for each photo queried and print to stdout. "
"TEMPLATE is an osxphotos template string. "
"This may be useful for creating custom reports, etc. "
"If --print TEMPLATE is provided, regular output is suppressed "
"and only the rendered TEMPLATE values are printed. "
"May be repeated to print multiple template strings. ",
)
@DB_ARGUMENT
@click.pass_obj
@click.pass_context
def dump(ctx, cli_obj, db, json_, deleted, deleted_only, photos_library):
def dump(
ctx,
cli_obj,
db,
deleted,
deleted_only,
field,
json_,
photos_library,
print_template,
):
"""Print list of all photos & associated info from the Photos library."""
db = get_photos_db(*photos_library, db, cli_obj.db)
# below needed for to make CliRunner work for testing
cli_db = cli_obj.db if cli_obj is not None else None
cli_json = cli_obj.json if cli_obj is not None else None
db = get_photos_db(*photos_library, db, cli_db)
if db is None:
click.echo(ctx.obj.group.commands["dump"].get_help(ctx), err=True)
click.echo("\n\nLocated the following Photos library databases: ", err=True)
@@ -33,6 +75,10 @@ def dump(ctx, cli_obj, db, json_, deleted, deleted_only, photos_library):
click.echo(ctx.obj.group.commands["dump"].get_help(ctx), err=True)
return
# set console for rich_echo to be same as for verbose_
set_rich_console(get_verbose_console())
set_rich_theme(get_default_theme())
photosdb = osxphotos.PhotosDB(dbfile=db)
if deleted or deleted_only:
photos = photosdb.photos(movies=True, intrash=True)
@@ -41,4 +87,28 @@ def dump(ctx, cli_obj, db, json_, deleted, deleted_only, photos_library):
if not deleted_only:
photos += photosdb.photos(movies=True)
print_photo_info(photos, json_ or cli_obj.json)
if not print_template and not field:
# just dump and be done
print_photo_info(photos, cli_json or json_)
return
if field:
print_photo_fields(photos, field, cli_json or json_)
if print_template:
# have print template(s)
options = RenderOptions()
for p in photos:
for template in print_template:
rendered_templates, unmatched = p.render_template(
template,
options,
)
if unmatched:
rich_click_echo(
f"[warning]Unmatched template field: {unmatched}[/]"
)
for rendered_template in rendered_templates:
if not rendered_template:
continue
print(rendered_template)

View File

@@ -674,6 +674,17 @@ from .verbose import get_verbose_console, time_stamp, verbose_print
is_flag=True,
help="If specified, saves the config file but does not export any files; must be used with --save-config.",
)
@click.option(
"--print",
"print_template",
metavar="TEMPLATE",
multiple=True,
help="Render TEMPLATE string for each photo being exported and print to stdout. "
"TEMPLATE is an osxphotos template string. "
"This may be useful for creating custom reports, etc. "
"TEMPLATE will be printed after the photo is exported or skipped. "
"May be repeated to print multiple template strings. ",
)
@click.option(
"--beta",
is_flag=True,
@@ -826,6 +837,7 @@ def export(
preview_if_missing,
preview_suffix,
preview,
print_template,
profile_sort,
profile,
query_eval,
@@ -1048,6 +1060,7 @@ def export(
preview = cfg.preview
preview_if_missing = cfg.preview_if_missing
preview_suffix = cfg.preview_suffix
print_template = cfg.print_template
query_eval = cfg.query_eval
query_function = cfg.query_function
ramdb = cfg.ramdb
@@ -1652,6 +1665,22 @@ def export(
report_writer.write(export_results)
if print_template:
options = RenderOptions(export_dir=dest)
for template in print_template:
rendered_templates, unmatched = p.render_template(
template,
options,
)
if unmatched:
rich_click_echo(
f"[warning]Unmatched template field: {unmatched}[/]"
)
for rendered_template in rendered_templates:
if not rendered_template:
continue
rich_click_echo(rendered_template)
progress.advance(task)
# handle limit

View File

@@ -1,16 +1,26 @@
"""import command for osxphotos CLI to import photos into Photos"""
# Note: the style in this module is a bit different than much of the other osxphotos code
# As an experiment, I've used mostly functions instead of classes (e.g. the report writer
# functions vs ReportWriter class used by export) and I've kept everything for import
# self-contained in this one file
import csv
import datetime
import fnmatch
import json
import logging
import os
import os.path
import sqlite3
import sys
import uuid
from collections import namedtuple
from pathlib import Path
from contextlib import suppress
from dataclasses import asdict, dataclass, field
from pathlib import Path, PosixPath
from textwrap import dedent
from typing import Callable, List, Optional, Tuple, Union
from typing import Callable, Dict, List, Optional, Tuple, Union
import click
from photoscript import Photo, PhotosLibrary
@@ -18,13 +28,15 @@ from rich.console import Console
from rich.markdown import Markdown
from osxphotos._constants import _OSXPHOTOS_NONE_SENTINEL
from osxphotos._version import __version__
from osxphotos.cli.help import HELP_WIDTH
from osxphotos.cli.param_types import TemplateString
from osxphotos.datetime_utils import datetime_naive_to_local
from osxphotos.exiftool import ExifToolCaching, get_exiftool_path
from osxphotos.photoinfo import PhotoInfoNone
from osxphotos.photosalbum import PhotosAlbumPhotoScript
from osxphotos.phototemplate import PhotoTemplate, RenderOptions
from osxphotos.utils import pluralize
from osxphotos.cli.param_types import TemplateString
from .click_rich_echo import (
rich_click_echo,
@@ -39,6 +51,8 @@ from .verbose import get_verbose_console, verbose_print
MetaData = namedtuple("MetaData", ["title", "description", "keywords", "location"])
OSXPHOTOS_ABOUT_STRING = f"Created by osxphotos version {__version__} (https://github.com/RhetTbull/osxphotos) on {datetime.datetime.now()}"
def echo(message, emoji=True, **kwargs):
"""Echo text with rich"""
@@ -119,7 +133,7 @@ class PhotoInfoFromFile:
Returns:
([rendered_strings], [unmatched]): tuple of list of rendered strings and list of unmatched template values
"""
options = options or RenderOptions()
options = options or RenderOptions(caller="import")
template = PhotoTemplate(self, exiftool_path=self._exiftool_path)
return template.render(template_str, options)
@@ -163,7 +177,7 @@ def render_photo_template(
photoinfo = PhotoInfoFromFile(filepath, exiftool=exiftool_path)
options = RenderOptions(
none_str=_OSXPHOTOS_NONE_SENTINEL, filepath=relative_filepath
none_str=_OSXPHOTOS_NONE_SENTINEL, filepath=relative_filepath, caller="import"
)
template_values, _ = photoinfo.render_template(template, options=options)
# filter out empty strings
@@ -478,7 +492,6 @@ def check_templates_and_exit(
description: Optional[str],
keyword: Tuple[str],
album: Tuple[str],
split_folder: Optional[str],
exiftool_path: Optional[str],
exiftool: bool,
):
@@ -524,6 +537,240 @@ def check_templates_and_exit(
sys.exit(0)
@dataclass
class ReportRecord:
albums: List[str] = field(default_factory=list)
description: str = ""
error: bool = False
filename: str = ""
filepath: Path = field(default_factory=Path)
import_datetime: datetime.datetime = datetime.datetime.now()
imported: bool = False
keywords: List[str] = field(default_factory=list)
location: Tuple[float, float] = field(default_factory=tuple)
title: str = ""
uuid: str = ""
def asdict(self):
return asdict(self)
def asjsondict(self):
"""Return a JSON serializable dict"""
dict_data = self.asdict()
dict_data["filepath"] = str(dict_data["filepath"])
dict_data["import_datetime"] = dict_data["import_datetime"].isoformat()
return dict_data
def update_report_record(report_record: ReportRecord, photo: Photo, filepath: Path):
"""Update a ReportRecord with data from a Photo"""
report_record.albums = [a.title for a in photo.albums]
report_record.description = photo.description
report_record.filename = filepath.name
report_record.filepath = filepath
report_record.imported = True
report_record.keywords = photo.keywords
report_record.location = photo.location
report_record.title = photo.title
report_record.uuid = photo.uuid
return report_record
def write_report(report_file: str, report_data: Dict[Path, ReportRecord], append: bool):
"""Write report to file"""
report_type = os.path.splitext(report_file)[1][1:].lower()
if report_type == "csv":
write_csv_report(report_file, report_data, append)
elif report_type == "json":
write_json_report(report_file, report_data, append)
elif report_type in ["db", "sqlite"]:
write_sqlite_report(report_file, report_data, append)
else:
echo(f"Unknown report type: {report_type}", err=True)
raise click.Abort()
def write_csv_report(
report_file: str, report_data: Dict[Path, ReportRecord], append: bool
):
"""Write report to csv file"""
with open(report_file, "a" if append else "w") as f:
writer = csv.writer(f)
if not append:
writer.writerow(
[
"filepath",
"filename",
"datetime",
"uuid",
"imported",
"error",
"title",
"description",
"keywords",
"albums",
"location",
]
)
for report_record in report_data.values():
writer.writerow(
[
report_record.filepath,
report_record.filename,
report_record.import_datetime,
report_record.uuid,
report_record.imported,
report_record.error,
report_record.title,
report_record.description,
",".join(report_record.keywords),
",".join(report_record.albums),
report_record.location,
]
)
def write_json_report(
report_file: str, report_data: Dict[Path, ReportRecord], append: bool
):
"""Write report to JSON file"""
records = [v.asjsondict() for v in report_data.values()]
if append:
with open(report_file, "r") as f:
existing_records = json.load(f)
records.extend(existing_records)
with open(report_file, "w") as f:
json.dump(records, f, indent=4)
def write_sqlite_report(
report_file: str, report_data: Dict[Path, ReportRecord], append: bool
):
"""Write report to SQLite file"""
if not append:
with suppress(FileNotFoundError):
os.unlink(report_file)
file_exists = os.path.isfile(report_file)
conn = sqlite3.connect(report_file)
c = conn.cursor()
if not append or not file_exists:
# Create the tables
c.execute(
"""CREATE TABLE IF NOT EXISTS report (
report_id INTEGER,
filepath TEXT,
filename TEXT,
datetime TEXT,
uuid TEXT,
imported INTEGER,
error INTEGER,
title TEXT,
description TEXT,
keywords TEXT,
albums TEXT,
location TEXT
)"""
)
c.execute(
"""
CREATE TABLE IF NOT EXISTS about (
id INTEGER PRIMARY KEY,
about TEXT
);"""
)
c.execute(
"INSERT INTO about(about) VALUES (?);",
(f"OSXPhotos Import Report. {OSXPHOTOS_ABOUT_STRING}",),
)
c.execute(
"""
CREATE TABLE IF NOT EXISTS report_id (
report_id INTEGER PRIMARY KEY,
datetime TEXT
);"""
)
# Insert report_id
c.execute(
"INSERT INTO report_id(datetime) VALUES (?);",
(datetime.datetime.now().isoformat(),),
)
report_id = c.lastrowid
for report_record in report_data.values():
c.execute(
"""INSERT INTO report (
report_id,
filepath,
filename,
datetime,
uuid,
imported,
error,
title,
description,
keywords,
albums,
location
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);""",
(
report_id,
str(report_record.filepath),
report_record.filename,
report_record.import_datetime,
report_record.uuid,
report_record.imported,
report_record.error,
report_record.title,
report_record.description,
",".join(report_record.keywords),
",".join(report_record.albums),
f"{report_record.location[0]},{report_record.location[1]}",
),
)
conn.commit()
conn.close()
def render_and_validate_report(report: str) -> str:
"""Render a report file template and validate the filename
Args:
report: the template string
Returns:
the rendered report filename
Note:
Exits with error if the report filename is invalid
"""
# render report template and validate the filename
template = PhotoTemplate(PhotoInfoNone())
render_options = RenderOptions(caller="import")
report_file, _ = template.render(report, options=render_options)
report = report_file[0]
if os.path.isdir(report):
rich_click_echo(
f"[error]Report '{report}' is a directory, must be file name",
err=True,
)
sys.exit(1)
extension = os.path.splitext(report)[1]
if extension.lower() not in [".csv", ".json", ".db", ".sqlite"]:
rich_click_echo(
f"[error]Report '{report}' has invalid extension, must be .csv, .json, .db, or .sqlite",
err=True,
)
sys.exit(1)
return report
def filename_matches_patterns(filename: str, patterns: Tuple[str]) -> bool:
"""Return True if filename matches any pattern in patterns"""
return any(fnmatch.fnmatch(filename, pattern) for pattern in patterns)
@@ -911,6 +1158,24 @@ class ImportCommand(click.Command):
"GLOB is a Unix shell-style glob pattern, for example: '--glob \"*.jpg\"'. "
"GLOB may be repeated to import multiple patterns.",
)
@click.option(
"--report",
metavar="REPORT_FILE",
help="Write a report of all files that were imported. "
"The extension of the report filename will be used to determine the format. "
"Valid extensions are: "
".csv (CSV file), .json (JSON), .db and .sqlite (SQLite database). "
"REPORT_FILE may be a template string (see Template System), for example, "
"--report 'export_{today.date}.csv' will write a CSV report file named with today's date. "
"See also --append.",
type=TemplateString(),
)
@click.option(
"--append",
is_flag=True,
help="If used with --report, add data to existing report file instead of overwriting it. "
"See also --report.",
)
@click.option("--verbose", "-V", "verbose_", is_flag=True, help="Print verbose output.")
@click.option(
"--timestamp", "-T", is_flag=True, help="Add time stamp to verbose output"
@@ -932,6 +1197,7 @@ def import_cli(
ctx,
cli_obj,
album,
append,
check_templates,
clear_location,
clear_metadata,
@@ -946,6 +1212,7 @@ def import_cli(
merge_keywords,
no_progress,
relative_to,
report,
split_folder,
theme,
timestamp,
@@ -977,6 +1244,7 @@ def import_cli(
# _list_libraries()
# return
report_file = render_and_validate_report(report) if report else None
relative_to = Path(relative_to) if relative_to else None
imported_count = 0
@@ -990,11 +1258,14 @@ def import_cli(
description,
keyword,
album,
split_folder,
exiftool_path,
exiftool,
)
# initialize report data
# report data is set even if no report is generated
report_data: Dict[Path, ReportRecord] = {}
filecount = len(files)
with rich_progress(console=get_verbose_console(), mock=no_progress) as progress:
task = progress.add_task(
@@ -1006,9 +1277,13 @@ def import_cli(
relative_filepath = get_relative_filepath(filepath, relative_to)
verbose(f"Importing [filepath]{filepath}[/]")
report_data[filepath] = ReportRecord(
filepath=filepath, filename=filepath.name
)
photo, error = import_photo(filepath, dup_check, verbose)
if error:
error_count += 1
report_data[filepath].error = True
continue
imported_count += 1
@@ -1063,8 +1338,13 @@ def import_cli(
verbose,
)
update_report_record(report_data[filepath], photo, filepath)
progress.advance(task)
if report:
write_report(report_file, report_data, append)
verbose(f"Wrote import report to [filepath]{report_file}[/]")
echo(
f"Done: imported [num]{imported_count}[/] {pluralize(imported_count, 'file', 'files')}, "
f"[num]{error_count}[/] {pluralize(error_count, 'error', 'errors')}",

View File

@@ -1,8 +1,9 @@
"""print_photo_info function to print PhotoInfo objects"""
import csv
import json
import sys
from typing import Callable, List
from typing import Callable, List, Tuple
from osxphotos.photoinfo import PhotoInfo
@@ -110,3 +111,44 @@ def print_photo_info(
)
for row in dump:
csv_writer.writerow(row)
def print_photo_fields(
photos: List[PhotoInfo], fields: Tuple[Tuple[str]], json_format: bool
):
"""Output custom field templates from PhotoInfo objects
Args:
photos: List of PhotoInfo objects
fields: Tuple of Tuple of field names/field templates to output"""
keys = [f[0] for f in fields]
data = []
for p in photos:
record = {}
for field in fields:
rendered_value, unmatched = p.render_template(field[1])
if unmatched:
raise ValueError(
f"Unmatched template variables in field {field[0]}: {field[1]}"
)
field_value = (
rendered_value[0]
if len(rendered_value) == 1
else ",".join(rendered_value)
if not json_format
else rendered_value
)
record[field[0]] = field_value
data.append(record)
if json_format:
print(json.dumps(data, indent=4))
else:
# dump as CSV
csv_writer = csv.writer(
sys.stdout, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL
)
# add headers
csv_writer.writerow(keys)
for record in data:
csv_writer.writerow(record.values())

View File

@@ -3,16 +3,24 @@
import click
import osxphotos
from osxphotos.cli.click_rich_echo import (
rich_click_echo,
set_rich_console,
set_rich_theme,
)
from osxphotos.debug import set_debug
from osxphotos.photosalbum import PhotosAlbum
from osxphotos.phototemplate import RenderOptions
from osxphotos.queryoptions import QueryOptions
from .color_themes import get_default_theme
from .common import (
CLI_COLOR_ERROR,
CLI_COLOR_WARNING,
DB_ARGUMENT,
DB_OPTION,
DELETED_OPTIONS,
FIELD_OPTION,
JSON_OPTION,
OSXPHOTOS_HIDDEN,
QUERY_OPTIONS,
@@ -20,7 +28,8 @@ from .common import (
load_uuid_from_file,
)
from .list import _list_libraries
from .print_photo_info import print_photo_info
from .print_photo_info import print_photo_fields, print_photo_info
from .verbose import get_verbose_console
@click.command()
@@ -62,6 +71,24 @@ from .print_photo_info import print_photo_info
"This only works if the Photos library being queried is the last-opened (default) library in Photos. "
"This feature is currently experimental. I don't know how well it will work on large query sets.",
)
@click.option(
"--quiet",
is_flag=True,
help="Quiet output; doesn't actually print query results. "
"Useful with --print and --add-to-album if you don't want to see the actual query results.",
)
@FIELD_OPTION
@click.option(
"--print",
"print_template",
metavar="TEMPLATE",
multiple=True,
help="Render TEMPLATE string for each photo queried and print to stdout. "
"TEMPLATE is an osxphotos template string. "
"This may be useful for creating custom reports, etc. "
"Most useful with --quiet. "
"May be repeated to print multiple template strings. ",
)
@click.option(
"--debug", required=False, is_flag=True, default=False, hidden=OSXPHOTOS_HIDDEN
)
@@ -88,6 +115,7 @@ def query(
exif,
external_edit,
favorite,
field,
folder,
from_date,
from_time,
@@ -139,8 +167,10 @@ def query(
person,
place,
portrait,
print_template,
query_eval,
query_function,
quiet,
regex,
screenshot,
selected,
@@ -230,6 +260,10 @@ def query(
click.echo(ctx.obj.group.commands["query"].get_help(ctx), err=True)
return
# set console for rich_echo to be same as for verbose_
set_rich_console(get_verbose_console())
set_rich_theme(get_default_theme())
# actually have something to query
# default searches for everything
photos = True
@@ -368,4 +402,25 @@ def query(
err=True,
)
print_photo_info(photos, cli_json or json_, print_func=click.echo)
if field:
print_photo_fields(photos, field, cli_json or json_)
if print_template:
options = RenderOptions()
for p in photos:
for template in print_template:
rendered_templates, unmatched = p.render_template(
template,
options,
)
if unmatched:
rich_click_echo(
f"[warning]Unmatched template field: {unmatched}[/]"
)
for rendered_template in rendered_templates:
if not rendered_template:
continue
print(rendered_template)
if not quiet and not field:
print_photo_info(photos, cli_json or json_, print_func=click.echo)

Binary file not shown.

View File

@@ -57,6 +57,9 @@ Valid filters are:
- `remove(x)`: Remove x from list of values, e.g. remove(b): ['a', 'b', 'c'] => ['a', 'c'].
- `slice(start:stop:step)`: Slice list using same semantics as Python's list slicing, e.g. slice(1:3): ['a', 'b', 'c', 'd'] => ['b', 'c']; slice(1:4:2): ['a', 'b', 'c', 'd'] => ['b', 'd']; slice(1:): ['a', 'b', 'c', 'd'] => ['b', 'c', 'd']; slice(:-1): ['a', 'b', 'c', 'd'] => ['a', 'b', 'c']; slice(::-1): ['a', 'b', 'c', 'd'] => ['d', 'c', 'b', 'a']. See also sslice().
- `sslice(start:stop:step)`: [s(tring) slice] Slice values in a list using same semantics as Python's string slicing, e.g. sslice(1:3):'abcd => 'bc'; sslice(1:4:2): 'abcd' => 'bd', etc. See also slice().
- `filter(x)`: Filter list of values using predicate x; for example, `{folder_album|filter(contains Events)}` returns only folders/albums containing the word 'Events' in their path.
- `int`: Convert values in list to integer, e.g. 1.0 => 1. If value cannot be converted to integer, remove value from list. ['1.1', 'x'] => ['1']. See also float.
- `float`: Convert values in list to floating point number, e.g. 1 => 1.0. If value cannot be converted to float, remove value from list. ['1', 'x'] => ['1.0']. See also int.
e.g. if Photo keywords are `["FOO","bar"]`:

View File

@@ -181,7 +181,8 @@ TEMPLATE_SUBSTITUTIONS = {
"{newline}": r"A newline: '\n'",
"{lf}": r"A line feed: '\n', alias for {newline}",
"{cr}": r"A carriage return: '\r'",
"{crlf}": r"a carriage return + line feed: '\r\n'",
"{crlf}": r"A carriage return + line feed: '\r\n'",
"{tab}": r":A tab: '\t'",
"{osxphotos_version}": f"The osxphotos version, e.g. '{__version__}'",
"{osxphotos_cmd_line}": "The full command line used to run osxphotos",
}
@@ -268,6 +269,11 @@ FILTER_VALUES = {
+ "slice(::-1): ['a', 'b', 'c', 'd'] => ['d', 'c', 'b', 'a']. See also sslice().",
"sslice(start:stop:step)": "[s(tring) slice] Slice values in a list using same semantics as Python's string slicing, "
+ "e.g. sslice(1:3):'abcd => 'bc'; sslice(1:4:2): 'abcd' => 'bd', etc. See also slice().",
"filter(x)": "Filter list of values using predicate x; for example, `{folder_album|filter(contains Events)}` returns only folders/albums containing the word 'Events' in their path.",
"int": "Convert values in list to integer, e.g. 1.0 => 1. If value cannot be converted to integer, remove value from list. "
+ "['1.1', 'x'] => ['1']. See also float.",
"float": "Convert values in list to floating point number, e.g. 1 => 1.0. If value cannot be converted to float, remove value from list. "
+ "['1', 'x'] => ['1.0']. See also int.",
}
# Just the substitutions without the braces
@@ -307,6 +313,7 @@ PUNCTUATION = {
"lf": "\n",
"cr": "\r",
"crlf": "\r\n",
"tab": "\t",
}
@@ -329,6 +336,7 @@ 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
caller: which command is calling the template (e.g. 'export')
"""
none_str: str = "_"
@@ -343,6 +351,7 @@ class RenderOptions:
dest_path: Optional[str] = None
filepath: Optional[str] = None
quote: bool = False
caller: str = "export"
class PhotoTemplateParser:
@@ -665,16 +674,18 @@ class PhotoTemplate:
vals = string_test(lambda v, c: v.endswith(c))
elif operator == "==":
match = sorted(vals) == sorted(conditional_value)
if (match and not negation) or (negation and not match):
vals = ["True"]
else:
vals = []
vals = (
["True"]
if (match and not negation) or (negation and not match)
else []
)
elif operator == "!=":
match = sorted(vals) != sorted(conditional_value)
if (match and not negation) or (negation and not match):
vals = ["True"]
else:
vals = []
vals = (
["True"]
if (match and not negation) or (negation and not match)
else []
)
elif operator == "<":
vals = comparison_test(lambda v, c: v < c)
elif operator == "<=":
@@ -788,7 +799,9 @@ class PhotoTemplate:
raise ValueError(
"SyntaxError: filename and function must not be null with {function::filename.py:function_name}"
)
vals = self.get_template_value_function(subfield, field_arg)
vals = self.get_template_value_function(
subfield, field_arg, self.options.caller
)
elif field in MULTI_VALUE_SUBSTITUTIONS or field.startswith("photo"):
vals = self.get_template_value_multi(
field, subfield, path_sep=field_arg, default=default
@@ -1178,6 +1191,7 @@ class PhotoTemplate:
"remove",
"slice",
"sslice",
"filter",
] and (args is None or not len(args)):
raise SyntaxError(f"{filter_} requires arguments")
@@ -1266,12 +1280,72 @@ class PhotoTemplate:
# slice each value in a list
slice_ = create_slice(args)
value = [v[slice_] for v in values]
elif filter_ == "filter":
# filter values based on a predicate
value = [v for v in values if self.filter_predicate(v, args)]
elif filter_ == "int":
# convert value to integer
value = values_to_int(values)
elif filter_ == "float":
# convert value to float
value = values_to_float(values)
elif filter_.startswith("function:"):
value = self.get_template_value_filter_function(filter_, args, values)
else:
value = []
return value
def filter_predicate(self, value: str, args: str) -> bool:
"""Return True if value passes predicate"""
# extract function name and arguments
if not args:
raise SyntaxError("Filter predicate requires arguments")
args = args.split(None, 1)
if args[0] == "not":
args = args[1:]
return not self.filter_predicate(value, " ".join(args))
predicate = args[0]
conditional_value = args[1].split("|")
def comparison_test(test_function):
"""Perform numerical comparisons using test_function"""
# returns True if any of the values match the condition
try:
return any(
bool(test_function(float(value), float(c)))
for c in conditional_value
)
except ValueError as e:
raise SyntaxError(
f"comparison operators may only be used with values that can be converted to numbers: {vals} {conditional_value}"
) from e
predicate_is_true = False
if predicate == "contains":
predicate_is_true = any(c in value for c in conditional_value)
elif predicate == "endswith":
predicate_is_true = any(value.endswith(c) for c in conditional_value)
elif predicate in ["matches", "=="]:
predicate_is_true = any(value == c for c in conditional_value)
elif predicate == "startswith":
predicate_is_true = any(value.startswith(c) for c in conditional_value)
elif predicate == "!=":
predicate_is_true = any(value != c for c in conditional_value)
elif predicate == "<":
predicate_is_true = comparison_test(lambda v, c: v < c)
elif predicate == "<=":
predicate_is_true = comparison_test(lambda v, c: v <= c)
elif predicate == ">":
predicate_is_true = comparison_test(lambda v, c: v > c)
elif predicate == ">=":
predicate_is_true = comparison_test(lambda v, c: v >= c)
else:
raise SyntaxError(f"Invalid predicate: {predicate}")
return predicate_is_true
def get_template_value_multi(self, field, subfield, path_sep, default):
"""lookup value for template field (multi-value template substitutions)
@@ -1459,10 +1533,17 @@ class PhotoTemplate:
def get_template_value_function(
self,
subfield,
field_arg,
subfield: str,
field_arg: Optional[str],
caller: str,
):
"""Get template value from external function"""
"""Get template value from external function
Args:
subfield: the filename and function name in for filename.py::function
field_arg: the argument to pass to the function
caller: the calling source of the template ('export' or 'import')
"""
if "::" not in subfield:
raise ValueError(
@@ -1481,8 +1562,17 @@ class PhotoTemplate:
# if no uuid, then template is being validated but not actually run
# so don't run the function
values = []
else:
elif caller == "export":
# function signature is:
# def example(photo: PhotoInfo, options: ExportOptions, args: Optional[str] = None, **kwargs) -> Union[List, str]:
values = template_func(self.photo, options=self.options, args=field_arg)
elif caller == "import":
# function signature is:
# def example(filepath: pathlib.Path, args: Optional[str] = None, **kwargs) -> Union[List, str]:
# the PhotoInfoFromFile class used by import sets `path` to the path of the file being imported
values = template_func(pathlib.Path(self.photo.path), args=field_arg)
else:
raise ValueError(f"Unhandled caller: {caller}")
if not isinstance(values, (str, list)):
raise TypeError(
@@ -1710,3 +1800,21 @@ def create_slice(args):
else:
raise SyntaxError(f"Invalid slice: {args}")
return slice(start, end, step)
def values_to_int(values: List[str]) -> List[str]:
"""Convert a list of strings to str representation of ints, if possible, otherwise strip values from list"""
int_values = []
for v in values:
with suppress(ValueError):
int_values.append(str(int(float(v))))
return int_values
def values_to_float(values: List[str]) -> List[str]:
"""Convert a list of strings to str representation of float, if possible, otherwise strip values from list"""
float_values = []
for v in values:
with suppress(ValueError):
float_values.append(str(float(v)))
return float_values

View File

@@ -51,6 +51,22 @@ the exported files would be:
/path/to/export/Travel/IMG_1234.JPG
/path/to/export/Vacation/IMG_1234.JPG
If your photos are organized in folders and albums in Photos you can preserve this structure on export by using the `{folder_album}` template field with the `--directory` option. For example, if you have a photo in the album `Vacation` which is in the `Travel` folder, the following command would export the photo to the `Travel/Vacation` directory:
`osxphotos export /path/to/export --directory "{folder_album}"`
Photos can belong to more than one album. In this case, the template field `{folder_album}` will expand to all the album names that the photo belongs to. For example, if a photo belongs to the albums `Vacation` and `Travel`, the template field `{folder_album}` would expand to `Vacation`, `Travel`. If the photo belongs to no albums, the template field `{folder_album}` would expand to "_" (the default value).
All template fields including `{folder_album}` can be further filtered using a number of different filters. To convert all directory names to lower case for example, use the `lower` filter:
`osxphotos export /path/to/export --directory "{folder_album|lower}"`
If all your photos were organized into various albums under a folder named `Events` but some where also included in other top-level albums and you wanted to export only the `Events` folder, you could use the `filter` option to filter out the other top-level albums by selecting only those folder/album paths that start with `Events`:
`osxphotos export /path/to/export --directory "{folder_album|filter(startswith Events)}"`
You can learn more about the other filters using `osxphotos help export`.
## Specify exported filename
By default, osxphotos will use the original filename of the photo when exporting. That is, the filename the photo had when it was taken or imported into Photos. This is often something like `IMG_1234.JPG` or `DSC05678.dng`. osxphotos allows you to specify a custom filename template using the `--filename` option in the same way as `--directory` allows you to specify a custom directory name. For example, Photos allows you specify a title or caption for a photo and you can use this in place of the original filename:
@@ -230,6 +246,14 @@ You can use the `--report` option to create a report, in comma-separated values
`osxphotos export /path/to/export --report export.csv`
You can also create reports in JSON or SQLite format by changing the extension of the report filename. For example, to create a JSON report:
`osxphotos export /path/to/export --report export.json`
And to create a SQLite report:
`osxphotos export /path/to/export --report export.sqlite`
## Exporting only certain photos
By default, osxphotos will export your entire Photos library. If you want to export only certain photos, osxphotos provides a rich set of "query options" that allow you to query the Photos database to filter out only certain photos that match your query criteria. The tutorial does not cover all the query options as there are over 50 of them--read the help text (`osxphotos help export`) to better understand the available query options. No matter which subset of photos you would like to export, there is almost certainly a way for osxphotos to filter these. For example, you can filter for only images that contain certain keywords or images without a title, images from a specific time of day or specific date range, images contained in specific albums, etc.

View File

@@ -8319,3 +8319,100 @@ def test_export_no_keyword():
)
assert result.exit_code == 0
assert "Exporting 11" in result.output
def test_export_print():
"""test export --print"""
runner = CliRunner()
cwd = os.getcwd()
with runner.isolated_filesystem():
result = runner.invoke(
export,
[
".",
"--db",
os.path.join(cwd, PHOTOS_DB_15_7),
"--print",
"uuid: {uuid}",
"--uuid",
UUID_FAVORITE,
],
)
assert result.exit_code == 0
assert f"uuid: {UUID_FAVORITE}" in result.output
def test_query_print_quiet():
"""test query --print"""
runner = CliRunner()
cwd = os.getcwd()
with runner.isolated_filesystem():
result = runner.invoke(
query,
[
"--db",
os.path.join(cwd, PHOTOS_DB_15_7),
"--print",
"uuid: {uuid}",
"--uuid",
UUID_FAVORITE,
"--quiet",
],
)
assert result.exit_code == 0
assert result.output.strip() == f"uuid: {UUID_FAVORITE}"
def test_query_field():
"""test query --field"""
runner = CliRunner()
cwd = os.getcwd()
with runner.isolated_filesystem():
result = runner.invoke(
query,
[
"--db",
os.path.join(cwd, PHOTOS_DB_15_7),
"--field",
"uuid",
"{uuid}",
"--field",
"name",
"{photo.original_filename}",
"--uuid",
UUID_FAVORITE,
],
)
assert result.exit_code == 0
assert result.output.strip() == f"uuid,name\n{UUID_FAVORITE},{FILE_FAVORITE}"
def test_query_field_json():
"""test query --field --json"""
runner = CliRunner()
cwd = os.getcwd()
with runner.isolated_filesystem():
result = runner.invoke(
query,
[
"--db",
os.path.join(cwd, PHOTOS_DB_15_7),
"--field",
"uuid",
"{uuid}",
"--field",
"name",
"{photo.original_filename}",
"--uuid",
UUID_FAVORITE,
"--json",
],
)
assert result.exit_code == 0
json_results = json.loads(result.output)
assert json_results[0]["uuid"] == UUID_FAVORITE
assert json_results[0]["name"] == FILE_FAVORITE

125
tests/test_cli_dump.py Normal file
View File

@@ -0,0 +1,125 @@
"""Test osxphotos dump command."""
import json
import os
import os.path
import pytest
from click.testing import CliRunner
from osxphotos.cli import dump
from osxphotos.photosdb import PhotosDB
from .test_cli import CLI_PHOTOS_DB
@pytest.fixture
def photos():
"""Return photos from CLI_PHOTOS_DB"""
cwd = os.getcwd()
db_path = os.path.join(cwd, CLI_PHOTOS_DB)
return PhotosDB(db_path).photos(intrash=True)
def test_dump_basic(photos):
"""Test osxphotos dump"""
runner = CliRunner()
cwd = os.getcwd()
db_path = os.path.join(cwd, CLI_PHOTOS_DB)
# pylint: disable=not-context-manager
with runner.isolated_filesystem():
result = runner.invoke(dump, ["--db", db_path, "--deleted"])
assert result.exit_code == 0
assert result.output.startswith("uuid,filename")
for photo in photos:
assert photo.uuid in result.output
def test_dump_json(photos):
"""Test osxphotos dump --json"""
runner = CliRunner()
cwd = os.getcwd()
db_path = os.path.join(cwd, CLI_PHOTOS_DB)
# pylint: disable=not-context-manager
with runner.isolated_filesystem():
result = runner.invoke(dump, ["--db", db_path, "--deleted", "--json"])
assert result.exit_code == 0
json_data = {record["uuid"]: record for record in json.loads(result.output)}
for photo in photos:
assert photo.uuid in json_data
def test_dump_print(photos):
"""Test osxphotos dump --print"""
runner = CliRunner()
cwd = os.getcwd()
db_path = os.path.join(cwd, CLI_PHOTOS_DB)
# pylint: disable=not-context-manager
with runner.isolated_filesystem():
result = runner.invoke(
dump,
[
"--db",
db_path,
"--deleted",
"--print",
"{uuid}{tab}{photo.original_filename}",
],
)
assert result.exit_code == 0
for photo in photos:
assert f"{photo.uuid}\t{photo.original_filename}" in result.output
def test_dump_field(photos):
"""Test osxphotos dump --field"""
runner = CliRunner()
cwd = os.getcwd()
db_path = os.path.join(cwd, CLI_PHOTOS_DB)
# pylint: disable=not-context-manager
with runner.isolated_filesystem():
result = runner.invoke(
dump,
[
"--db",
db_path,
"--deleted",
"--field",
"uuid",
"{uuid}",
"--field",
"name",
"{photo.original_filename}",
],
)
assert result.exit_code == 0
for photo in photos:
assert f"{photo.uuid},{photo.original_filename}" in result.output
def test_dump_field_json(photos):
"""Test osxphotos dump --field --jso"""
runner = CliRunner()
cwd = os.getcwd()
db_path = os.path.join(cwd, CLI_PHOTOS_DB)
# pylint: disable=not-context-manager
with runner.isolated_filesystem():
result = runner.invoke(
dump,
[
"--db",
db_path,
"--deleted",
"--field",
"uuid",
"{uuid}",
"--field",
"name",
"{photo.original_filename}",
"--json",
],
)
assert result.exit_code == 0
json_data = {record["uuid"]: record for record in json.loads(result.output)}
for photo in photos:
assert photo.uuid in json_data
assert json_data[photo.uuid]["name"] == photo.original_filename

View File

@@ -1,10 +1,15 @@
""" Tests which require user interaction to run for osxphotos import command; run with pytest --test-import """
import csv
import json
import os
import os.path
import pathlib
import re
import shutil
import sqlite3
import time
from tempfile import TemporaryDirectory
from typing import Dict
import pytest
@@ -13,7 +18,7 @@ from photoscript import Photo
from pytest import approx
from osxphotos.cli.import_cli import import_cli
from osxphotos.exiftool import ExifTool, get_exiftool_path
from osxphotos.exiftool import get_exiftool_path
from tests.conftest import get_os_version
TERMINAL_WIDTH = 250
@@ -644,3 +649,262 @@ def test_import_check_templates():
for idx, line in enumerate(output):
assert line == TEST_DATA[TEST_IMAGE_1]["check_templates"][idx]
@pytest.mark.test_import
def test_import_function_template():
"""Test import with a function template"""
cwd = os.getcwd()
test_image_1 = os.path.join(cwd, TEST_IMAGE_1)
function = os.path.join(cwd, "examples/template_function_import.py")
with TemporaryDirectory() as tempdir:
test_image = shutil.copy(
test_image_1, os.path.join(tempdir, "MyAlbum_IMG_0001.jpg")
)
runner = CliRunner()
result = runner.invoke(
import_cli,
[
"--verbose",
"--album",
"{function:" + function + "::example}",
test_image,
],
terminal_width=TERMINAL_WIDTH,
)
assert result.exit_code == 0
import_data = parse_import_output(result.output)
file_1 = pathlib.Path(test_image).name
uuid_1 = import_data[file_1]
photo_1 = Photo(uuid_1)
assert photo_1.filename == file_1
albums = [a.title for a in photo_1.albums]
assert albums == ["MyAlbum"]
@pytest.mark.test_import
def test_import_report():
"""test import with --report option"""
runner = CliRunner()
cwd = os.getcwd()
test_image_1 = os.path.join(cwd, TEST_IMAGE_1)
with runner.isolated_filesystem():
result = runner.invoke(
import_cli,
[
test_image_1,
"--report",
"report.csv",
"--verbose",
],
)
assert result.exit_code == 0
assert "Wrote import report" in result.output
assert os.path.exists("report.csv")
with open("report.csv", "r") as f:
reader = csv.DictReader(f)
rows = list(reader)
filenames = [str(pathlib.Path(row["filename"]).name) for row in rows]
assert filenames == [pathlib.Path(TEST_IMAGE_1).name]
# test report gets overwritten
result = runner.invoke(
import_cli,
[
test_image_1,
"--report",
"report.csv",
"--verbose",
],
)
assert result.exit_code == 0
with open("report.csv", "r") as f:
reader = csv.DictReader(f)
rows = list(reader)
filenames = [str(pathlib.Path(row["filename"]).name) for row in rows]
assert filenames == [pathlib.Path(TEST_IMAGE_1).name]
# test report with --append
result = runner.invoke(
import_cli,
[
test_image_1,
"--report",
"report.csv",
"--append",
"--verbose",
],
)
assert result.exit_code == 0
with open("report.csv", "r") as f:
reader = csv.DictReader(f)
rows = list(reader)
filenames = [str(pathlib.Path(row["filename"]).name) for row in rows]
assert filenames == [
pathlib.Path(TEST_IMAGE_1).name,
pathlib.Path(TEST_IMAGE_1).name,
]
@pytest.mark.test_import
def test_import_report_json():
"""test import with --report option with json output"""
runner = CliRunner()
cwd = os.getcwd()
test_image_1 = os.path.join(cwd, TEST_IMAGE_1)
with runner.isolated_filesystem():
result = runner.invoke(
import_cli,
[
test_image_1,
"--report",
"report.json",
"--verbose",
],
)
assert result.exit_code == 0
assert "Wrote import report" in result.output
assert os.path.exists("report.json")
with open("report.json", "r") as f:
rows = json.load(f)
filenames = [str(pathlib.Path(row["filename"]).name) for row in rows]
assert filenames == [pathlib.Path(TEST_IMAGE_1).name]
# test report gets overwritten
result = runner.invoke(
import_cli,
[
test_image_1,
"--report",
"report.json",
"--verbose",
],
)
assert result.exit_code == 0
assert "Wrote import report" in result.output
assert os.path.exists("report.json")
with open("report.json", "r") as f:
rows = json.load(f)
filenames = [str(pathlib.Path(row["filename"]).name) for row in rows]
assert filenames == [pathlib.Path(TEST_IMAGE_1).name]
# test report with --append
result = runner.invoke(
import_cli,
[
test_image_1,
"--report",
"report.json",
"--append",
"--verbose",
],
)
assert result.exit_code == 0
assert "Wrote import report" in result.output
assert os.path.exists("report.json")
with open("report.json", "r") as f:
rows = json.load(f)
filenames = [str(pathlib.Path(row["filename"]).name) for row in rows]
assert filenames == [
pathlib.Path(TEST_IMAGE_1).name,
pathlib.Path(TEST_IMAGE_1).name,
]
@pytest.mark.test_import
@pytest.mark.parametrize("report_file", ["report.db", "report.sqlite"])
def test_import_report_sqlite(report_file):
"""test import with --report option with sqlite output"""
runner = CliRunner()
cwd = os.getcwd()
test_image_1 = os.path.join(cwd, TEST_IMAGE_1)
with runner.isolated_filesystem():
result = runner.invoke(
import_cli,
[
test_image_1,
"--report",
report_file,
"--verbose",
],
)
assert result.exit_code == 0
assert "Wrote import report" in result.output
assert os.path.exists(report_file)
conn = sqlite3.connect(report_file)
c = conn.cursor()
c.execute("SELECT filename FROM report")
filenames = [str(pathlib.Path(row[0]).name) for row in c.fetchall()]
assert filenames == [pathlib.Path(TEST_IMAGE_1).name]
# test report gets overwritten
result = runner.invoke(
import_cli,
[
test_image_1,
"--report",
report_file,
"--verbose",
],
)
assert result.exit_code == 0
assert "Wrote import report" in result.output
assert os.path.exists(report_file)
conn = sqlite3.connect(report_file)
c = conn.cursor()
c.execute("SELECT filename FROM report")
filenames = [str(pathlib.Path(row[0]).name) for row in c.fetchall()]
assert filenames == [pathlib.Path(TEST_IMAGE_1).name]
# test report with --append
result = runner.invoke(
import_cli,
[
test_image_1,
"--report",
report_file,
"--append",
"--verbose",
],
)
assert result.exit_code == 0
assert "Wrote import report" in result.output
assert os.path.exists(report_file)
conn = sqlite3.connect(report_file)
c = conn.cursor()
c.execute("SELECT filename FROM report")
filenames = [str(pathlib.Path(row[0]).name) for row in c.fetchall()]
assert filenames == [
pathlib.Path(TEST_IMAGE_1).name,
pathlib.Path(TEST_IMAGE_1).name,
]
@pytest.mark.test_import
def test_import_report_invalid_name():
"""test import with --report option with invalid report"""
runner = CliRunner()
cwd = os.getcwd()
test_image_1 = os.path.join(cwd, TEST_IMAGE_1)
with runner.isolated_filesystem():
result = runner.invoke(
import_cli,
[
test_image_1,
"--report",
"report", # invalid filename, no extension
"--verbose",
],
)
assert result.exit_code != 0

View File

@@ -8,12 +8,13 @@ import osxphotos
from osxphotos.exiftool import get_exiftool_path
from osxphotos.export_db import ExportDBInMemory
from osxphotos.phototemplate import (
PUNCTUATION,
TEMPLATE_SUBSTITUTIONS,
TEMPLATE_SUBSTITUTIONS_MULTI_VALUED,
PhotoTemplate,
RenderOptions,
)
from osxphotos.photoinfo import PhotoInfoNone
from .photoinfo_mock import PhotoInfoMock
try:
@@ -238,6 +239,21 @@ TEMPLATE_VALUES = {
"{descr|autosplit|slice(:2)|join()}": "JackRose",
"{descr|autosplit|slice(:-1)|join()}": "JackRoseDining",
"{descr|autosplit|slice(::2)|join()}": "JackDining",
"{descr|filter(startswith Jack)}": "Jack Rose Dining Saloon",
"{descr|filter(startswith Rose)}": "_",
"{descr|filter(endswith Saloon)}": "Jack Rose Dining Saloon",
"{descr|filter(endswith Rose)}": "_",
"{descr|filter(contains Rose)}": "Jack Rose Dining Saloon",
"{descr|filter(not contains Rose)}": "_",
"{descr|filter(matches Jack Rose Dining Saloon)}": "Jack Rose Dining Saloon",
"{created.mm|filter(== 02)}": "02",
"{created.mm|filter(<= 2)}": "02",
"{created.mm|filter(>= 2)}": "02",
"{created.mm|filter(> 3)}": "_",
"{created.mm|filter(< 1)}": "_",
"{created.mm|filter(!= 02)}": "_",
"{created.mm|int|filter(== 2)}": "2",
"{created.mm|float|filter(== 2.0)}": "2.0",
}
@@ -437,6 +453,7 @@ UUID_ALBUM_SEQ = {
"{folder_album_seq(1)}": "2",
"{folder_album_seq(0)}": "1",
"{folder_album_seq:03d(1)}": "002",
"{folder_album|filter(startswith Folder1)}": "Folder1/SubFolder2/AlbumInFolder",
},
},
}
@@ -1329,3 +1346,16 @@ def test_bad_sslice(photosdb):
# bad function raises ValueError
with pytest.raises((SyntaxError, ValueError)):
rendered, _ = photo.render_template("{photo.original_filename|sslice(1:2:3:4)}")
def test_punctuation():
"""Test punctuation template fields"""
template_string = ""
expected_string = ""
for field, value in PUNCTUATION.items():
template_string += "{" + field + "}"
expected_string += f"{value}"
template = PhotoTemplate(PhotoInfoNone())
options = RenderOptions()
rendered, _ = template.render(template_string, options)
assert rendered == [expected_string]