Implemented --in-album, --not-in-album, issue #364

This commit is contained in:
Rhet Turnbull
2021-02-04 06:40:49 -08:00
parent 773b619e24
commit addd952aa3
22 changed files with 162 additions and 17 deletions

View File

@@ -273,6 +273,9 @@ Options:
--is-reference Search for photos that were imported as
referenced files (not copied into Photos
library).
--in-album Search for photos that are in one or more
albums.
--not-in-album Search for photos that are not in any albums.
--missing Export only photos missing from the Photos
library; must be used with --download-missing.
--deleted Include photos from the 'Recently Deleted'

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: 2c0d5eb59f2ded9afd3687aa247a1287
config: 17bac89a05164f8fa737ad20fcd95f80
tags: 645f666f9bcd5a90fca523b33c5a78b7

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Overview: module code &#8212; osxphotos 0.40.7 documentation</title>
<title>Overview: module code &#8212; osxphotos 0.40.8 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>osxphotos.photoinfo._photoinfo_exifinfo &#8212; osxphotos 0.40.7 documentation</title>
<title>osxphotos.photoinfo._photoinfo_exifinfo &#8212; osxphotos 0.40.8 documentation</title>
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/alabaster.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>osxphotos.photoinfo._photoinfo_export &#8212; osxphotos 0.40.7 documentation</title>
<title>osxphotos.photoinfo._photoinfo_export &#8212; osxphotos 0.40.8 documentation</title>
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/alabaster.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>osxphotos.photoinfo._photoinfo_scoreinfo &#8212; osxphotos 0.40.7 documentation</title>
<title>osxphotos.photoinfo._photoinfo_scoreinfo &#8212; osxphotos 0.40.8 documentation</title>
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/alabaster.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>osxphotos.photoinfo._photoinfo_searchinfo &#8212; osxphotos 0.40.7 documentation</title>
<title>osxphotos.photoinfo._photoinfo_searchinfo &#8212; osxphotos 0.40.8 documentation</title>
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/alabaster.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>osxphotos.photoinfo.photoinfo &#8212; osxphotos 0.40.7 documentation</title>
<title>osxphotos.photoinfo.photoinfo &#8212; osxphotos 0.40.8 documentation</title>
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/alabaster.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>osxphotos.photosdb.photosdb &#8212; osxphotos 0.40.7 documentation</title>
<title>osxphotos.photosdb.photosdb &#8212; osxphotos 0.40.8 documentation</title>
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/alabaster.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>

View File

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

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>osxphotos command line interface (CLI) &#8212; osxphotos 0.40.7 documentation</title>
<title>osxphotos command line interface (CLI) &#8212; osxphotos 0.40.8 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
@@ -465,6 +465,18 @@ to modify this behavior.</p>
<dd><p>Search for photos that were imported as referenced files (not copied into Photos library).</p>
</dd></dl>
<dl class="std option">
<dt id="cmdoption-osxphotos-export-in-album">
<code class="sig-name descname">--in-album</code><code class="sig-prename descclassname"></code><a class="headerlink" href="#cmdoption-osxphotos-export-in-album" title="Permalink to this definition"></a></dt>
<dd><p>Search for photos that are in one or more albums.</p>
</dd></dl>
<dl class="std option">
<dt id="cmdoption-osxphotos-export-not-in-album">
<code class="sig-name descname">--not-in-album</code><code class="sig-prename descclassname"></code><a class="headerlink" href="#cmdoption-osxphotos-export-not-in-album" title="Permalink to this definition"></a></dt>
<dd><p>Search for photos that are not in any albums.</p>
</dd></dl>
<dl class="std option">
<dt id="cmdoption-osxphotos-export-missing">
<code class="sig-name descname">--missing</code><code class="sig-prename descclassname"></code><a class="headerlink" href="#cmdoption-osxphotos-export-missing" title="Permalink to this definition"></a></dt>
@@ -1269,6 +1281,18 @@ if more than one option is provided, they are treated as “AND”
<dd><p>Search for photos that were imported as referenced files (not copied into Photos library).</p>
</dd></dl>
<dl class="std option">
<dt id="cmdoption-osxphotos-query-in-album">
<code class="sig-name descname">--in-album</code><code class="sig-prename descclassname"></code><a class="headerlink" href="#cmdoption-osxphotos-query-in-album" title="Permalink to this definition"></a></dt>
<dd><p>Search for photos that are in one or more albums.</p>
</dd></dl>
<dl class="std option">
<dt id="cmdoption-osxphotos-query-not-in-album">
<code class="sig-name descname">--not-in-album</code><code class="sig-prename descclassname"></code><a class="headerlink" href="#cmdoption-osxphotos-query-not-in-album" title="Permalink to this definition"></a></dt>
<dd><p>Search for photos that are not in any albums.</p>
</dd></dl>
<dl class="std option">
<dt id="cmdoption-osxphotos-query-deleted">
<code class="sig-name descname">--deleted</code><code class="sig-prename descclassname"></code><a class="headerlink" href="#cmdoption-osxphotos-query-deleted" title="Permalink to this definition"></a></dt>

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Index &#8212; osxphotos 0.40.7 documentation</title>
<title>Index &#8212; osxphotos 0.40.8 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
@@ -395,6 +395,15 @@
<ul>
<li><a href="cli.html#cmdoption-osxphotos-export-ignore-signature">osxphotos-export command line option</a>
</li>
</ul></li>
<li>
--in-album
<ul>
<li><a href="cli.html#cmdoption-osxphotos-export-in-album">osxphotos-export command line option</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-in-album">osxphotos-query command line option</a>
</li>
</ul></li>
<li>
@@ -590,6 +599,15 @@
<li><a href="cli.html#cmdoption-osxphotos-export-not-hidden">osxphotos-export command line option</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-not-hidden">osxphotos-query command line option</a>
</li>
</ul></li>
<li>
--not-in-album
<ul>
<li><a href="cli.html#cmdoption-osxphotos-export-not-in-album">osxphotos-export command line option</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-not-in-album">osxphotos-query command line option</a>
</li>
</ul></li>
<li>
@@ -1459,6 +1477,8 @@
<li><a href="cli.html#cmdoption-osxphotos-export-ignore-date-modified">--ignore-date-modified</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-export-ignore-signature">--ignore-signature</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-export-in-album">--in-album</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-export-is-reference">--is-reference</a>
</li>
@@ -1495,6 +1515,8 @@
<li><a href="cli.html#cmdoption-osxphotos-export-not-hdr">--not-hdr</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-export-not-hidden">--not-hidden</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-export-not-in-album">--not-in-album</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-export-not-live">--not-live</a>
</li>
@@ -1703,6 +1725,8 @@
<li><a href="cli.html#cmdoption-osxphotos-query-hidden">--hidden</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-i">--ignore-case</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-in-album">--in-album</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-incloud">--incloud</a>
</li>
@@ -1737,6 +1761,8 @@
<li><a href="cli.html#cmdoption-osxphotos-query-not-hdr">--not-hdr</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-not-hidden">--not-hidden</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-not-in-album">--not-in-album</a>
</li>
<li><a href="cli.html#cmdoption-osxphotos-query-not-incloud">--not-incloud</a>
</li>

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Welcome to osxphotoss documentation! &#8212; osxphotos 0.40.7 documentation</title>
<title>Welcome to osxphotoss documentation! &#8212; osxphotos 0.40.8 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>osxphotos &#8212; osxphotos 0.40.7 documentation</title>
<title>osxphotos &#8212; osxphotos 0.40.8 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>

Binary file not shown.

Binary file not shown.

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>osxphotos package &#8212; osxphotos 0.40.7 documentation</title>
<title>osxphotos package &#8212; osxphotos 0.40.8 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Search &#8212; osxphotos 0.40.7 documentation</title>
<title>Search &#8212; osxphotos 0.40.8 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />

File diff suppressed because one or more lines are too long

View File

@@ -1,3 +1,3 @@
""" version info """
__version__ = "0.40.7"
__version__ = "0.40.8"

View File

@@ -403,6 +403,16 @@ def query_options(f):
is_flag=True,
help="Search for photos that were imported as referenced files (not copied into Photos library).",
),
o(
"--in-album",
is_flag=True,
help="Search for photos that are in one or more albums.",
),
o(
"--not-in-album",
is_flag=True,
help="Search for photos that are not in any albums.",
),
]
for o in options[::-1]:
f = o(f)
@@ -907,6 +917,8 @@ def export(
save_config,
is_reference,
beta,
in_album,
not_in_album,
):
"""Export photos from the Photos database.
Export path DEST is required.
@@ -1047,6 +1059,8 @@ def export(
exportdb = cfg.exportdb
beta = cfg.beta
only_new = cfg.only_new
in_album = cfg.in_album
not_in_album = cfg.not_in_album
# config file might have changed verbose
VERBOSE = bool(verbose)
@@ -1080,6 +1094,7 @@ def export(
("shared", "not_shared"),
("has_comment", "no_comment"),
("has_likes", "no_likes"),
("in_album", "not_in_album"),
]
dependent_options = [
("missing", ("download_missing", "use_photos_export")),
@@ -1339,6 +1354,8 @@ def export(
has_likes=has_likes,
no_likes=no_likes,
is_reference=is_reference,
in_album=in_album,
not_in_album=not_in_album,
)
if photos:
@@ -1620,6 +1637,8 @@ def query(
has_likes,
no_likes,
is_reference,
in_album,
not_in_album,
):
"""Query the Photos database using 1 or more search options;
if more than one option is provided, they are treated as "AND"
@@ -1667,6 +1686,7 @@ def query(
(shared, not_shared),
(has_comment, no_comment),
(has_likes, no_likes),
(in_album, not_in_album),
]
# print help if no non-exclusive term or a double exclusive term is given
if any(all(bb) for bb in exclusive) or not any(
@@ -1759,6 +1779,8 @@ def query(
has_likes=has_likes,
no_likes=no_likes,
is_reference=is_reference,
in_album=in_album,
not_in_album=not_in_album,
)
# below needed for to make CliRunner work for testing
@@ -1930,6 +1952,8 @@ def _query(
has_likes=False,
no_likes=False,
is_reference=False,
in_album=False,
not_in_album=False,
):
"""Run a query against PhotosDB to extract the photos based on user supply criteria used by query and export commands
@@ -2162,6 +2186,11 @@ def _query(
if is_reference:
photos = [p for p in photos if p.isreference]
if in_album:
photos = [p for p in photos if p.albums]
elif not_in_album:
photos = [p for p in photos if not p.albums]
return photos

View File

@@ -578,6 +578,29 @@ UUID_IS_REFERENCE = [
"A1DD1F98-2ECD-431F-9AC9-5AFEFE2D3A5C",
]
UUID_IN_ALBUM = [
"F12384F6-CD17-4151-ACBA-AE0E3688539E",
"8E1D7BC9-9321-44F9-8CFB-4083F6B9232A",
"1EB2B765-0765-43BA-A90C-0D0580E6172C",
"E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51",
"A92D9C26-3A50-4197-9388-CB5F7DB9FA91",
"D79B8D77-BFFC-460B-9312-034F2877D35B",
"4D521201-92AC-43E5-8F7C-59BC41C37A96",
"D05A5FE3-15FB-49A1-A15D-AB3DA6F8B068",
"3DD2C897-F19E-4CA6-8C22-B027D5A71907",
]
UUID_NOT_IN_ALBUM = [
"A1DD1F98-2ECD-431F-9AC9-5AFEFE2D3A5C",
"7783E8E6-9CAC-40F3-BE22-81FB7051C266",
"DC99FBDD-7A52-4100-A5BB-344131646C30",
"D1359D09-1373-4F3B-B0E3-1A4DE573E4A3",
"E2078879-A29C-4D6F-BACB-E3BBE6C3EB91",
"6191423D-8DB8-4D4C-92BE-9BBBA308AAC4",
"35329C57-B963-48D6-BB75-6AFF9370CBBC",
"8846E3E6-8AC8-4857-8448-E3D025784410",
]
def modify_file(filename):
""" appends data to a file to modify it """
@@ -882,6 +905,46 @@ def test_query_is_reference():
assert sorted(uuid_got) == sorted(UUID_IS_REFERENCE)
def test_query_in_album():
""" Test query with --in-album """
import json
import os
import os.path
from osxphotos.cli import query
runner = CliRunner()
cwd = os.getcwd()
result = runner.invoke(
query, ["--json", "--db", os.path.join(cwd, PHOTOS_DB_15_7), "--in-album"]
)
assert result.exit_code == 0
# build list of uuids we got from the output JSON
json_got = json.loads(result.output)
uuid_got = [photo["uuid"] for photo in json_got]
assert sorted(uuid_got) == sorted(UUID_IN_ALBUM)
def test_query_not_in_album():
""" Test query with --not-in-album """
import json
import os
import os.path
from osxphotos.cli import query
runner = CliRunner()
cwd = os.getcwd()
result = runner.invoke(
query, ["--json", "--db", os.path.join(cwd, PHOTOS_DB_15_7), "--not-in-album"]
)
assert result.exit_code == 0
# build list of uuids we got from the output JSON
json_got = json.loads(result.output)
uuid_got = [photo["uuid"] for photo in json_got]
assert sorted(uuid_got) == sorted(UUID_NOT_IN_ALBUM)
def test_export():
import glob
import os