Added --exportdb

This commit is contained in:
Rhet Turnbull
2020-12-22 20:42:48 -08:00
parent f3b7134af1
commit 2a49255277
4 changed files with 114 additions and 5 deletions

View File

@@ -349,9 +349,9 @@ Options:
exiftool command line. See exiftool docs at exiftool command line. See exiftool docs at
https://exiftool.org/exiftool_pod.html for https://exiftool.org/exiftool_pod.html for
full list of options. More than one option full list of options. More than one option
may be specified with by repeating the may be specified by repeating the option,
option, e.g. --exiftool-option '-m' e.g. --exiftool-option '-m' --exiftool-
--exiftool-option '-F'. option '-F'.
--ignore-date-modified If used with --exiftool or --sidecar, will --ignore-date-modified If used with --exiftool or --sidecar, will
ignore the photo modification date and set ignore the photo modification date and set
EXIF:ModifyDate to EXIF:DateTimeOriginal; EXIF:ModifyDate to EXIF:DateTimeOriginal;
@@ -429,6 +429,14 @@ Options:
set. For example, photos which had set. For example, photos which had
previously been exported and were previously been exported and were
subsequently deleted in Photos. subsequently deleted in Photos.
--exportdb EXPORTDB_FILE Specify alternate name for database file
which stores state information for export
and --update. If --exportdb is not
specified, export database will be saved to
'.osxphotos_export.db' in the export
directory. Must be specified as filename
only, not a path, as export database will be
saved in export directory.
--load-config <config file path> --load-config <config file path>
Load options from file as written with Load options from file as written with
--save-config. This allows you to save a --save-config. This allows you to save a

View File

@@ -1476,6 +1476,18 @@ def query(
help="Cleanup export directory by deleting any files which were not included in this export set. " help="Cleanup export directory by deleting any files which were not included in this export set. "
"For example, photos which had previously been exported and were subsequently deleted in Photos.", "For example, photos which had previously been exported and were subsequently deleted in Photos.",
) )
@click.option(
"--exportdb",
metavar="EXPORTDB_FILE",
default=None,
help=(
"Specify alternate name for database file which stores state information for export and --update. "
f"If --exportdb is not specified, export database will be saved to '{OSXPHOTOS_EXPORT_DB}' "
"in the export directory. Must be specified as filename only, not a path, as export database "
"will be saved in export directory."
),
type=click.Path(),
)
@click.option( @click.option(
"--load-config", "--load-config",
required=False, required=False,
@@ -1595,6 +1607,7 @@ def export(
use_photokit, use_photokit,
report, report,
cleanup, cleanup,
exportdb,
load_config, load_config,
save_config, save_config,
): ):
@@ -1724,6 +1737,7 @@ def export(
use_photokit = cfg.use_photokit use_photokit = cfg.use_photokit
report = cfg.report report = cfg.report
cleanup = cfg.cleanup cleanup = cfg.cleanup
exportdb = cfg.exportdb
# config file might have changed verbose # config file might have changed verbose
VERBOSE = bool(verbose) VERBOSE = bool(verbose)
@@ -1854,8 +1868,27 @@ def export(
_list_libraries() _list_libraries()
return return
# sanity check exportdb
if exportdb and exportdb != OSXPHOTOS_EXPORT_DB:
if "/" in exportdb:
click.echo(
click.style(
f"Error: --exportdb must be specified as filename not path; "
+ f"export database will saved in export directory '{dest}'.",
fg=CLI_COLOR_ERROR,
)
)
raise click.Abort()
elif pathlib.Path(pathlib.Path(dest) / OSXPHOTOS_EXPORT_DB).exists():
click.echo(
click.style(
f"Warning: export database is '{exportdb}' but found '{OSXPHOTOS_EXPORT_DB}' in {dest}; using '{exportdb}'",
fg=CLI_COLOR_WARNING,
)
)
# open export database and assign copy/link/unlink functions # open export database and assign copy/link/unlink functions
export_db_path = os.path.join(dest, OSXPHOTOS_EXPORT_DB) export_db_path = os.path.join(dest, exportdb or OSXPHOTOS_EXPORT_DB)
# check that export isn't in the parent or child of a previously exported library # check that export isn't in the parent or child of a previously exported library
other_db_files = find_files_in_branch(dest, OSXPHOTOS_EXPORT_DB) other_db_files = find_files_in_branch(dest, OSXPHOTOS_EXPORT_DB)

View File

@@ -1,5 +1,5 @@
""" version info """ """ version info """
__version__ = "0.38.9" __version__ = "0.38.10"

View File

@@ -4444,3 +4444,71 @@ def test_save_load_config():
assert result.exit_code == 0 assert result.exit_code == 0
assert "Writing exiftool JSON sidecar" in result.output assert "Writing exiftool JSON sidecar" in result.output
assert "Writing XMP sidecar" not in result.output assert "Writing XMP sidecar" not in result.output
def test_export_exportdb():
""" test --exportdb """
import glob
import os
import os.path
import osxphotos
from osxphotos.__main__ import export
import re
runner = CliRunner()
cwd = os.getcwd()
# pylint: disable=not-context-manager
with runner.isolated_filesystem():
result = runner.invoke(
export,
[os.path.join(cwd, CLI_PHOTOS_DB), ".", "-V", "--exportdb", "export.db"],
)
assert result.exit_code == 0
assert re.search(r"Created export database.*export\.db", result.output)
files = glob.glob("*")
assert "export.db" in files
result = runner.invoke(
export,
[
os.path.join(cwd, CLI_PHOTOS_DB),
".",
"-V",
"--exportdb",
"export.db",
"--update",
],
)
assert result.exit_code == 0
assert re.search(r"Using export database.*export\.db", result.output)
# export again w/o --exportdb
result = runner.invoke(export, [os.path.join(cwd, CLI_PHOTOS_DB), ".", "-V"])
assert result.exit_code == 0
assert re.search(
r"Created export database.*\.osxphotos_export\.db", result.output
)
files = glob.glob(".*")
assert ".osxphotos_export.db" in files
# now try again with --exportdb, should generate warning
result = runner.invoke(
export,
[os.path.join(cwd, CLI_PHOTOS_DB), ".", "-V", "--exportdb", "export.db"],
)
assert result.exit_code == 0
assert (
"Warning: export database is 'export.db' but found '.osxphotos_export.db'"
in result.output
)
# specify a path for exportdb, should generate error
result = runner.invoke(
export,
[os.path.join(cwd, CLI_PHOTOS_DB), ".", "-V", "--exportdb", "./export.db"],
)
assert result.exit_code != 0
assert (
"Error: --exportdb must be specified as filename not path" in result.output
)