Made --exiftool and --export-as-hardlink incompatible in CLI to fix #132

This commit is contained in:
Rhet Turnbull
2020-05-16 06:48:23 -07:00
parent cafa483cfc
commit 8e9691d6d7
2 changed files with 40 additions and 6 deletions

View File

@@ -21,7 +21,10 @@ import osxphotos
from ._constants import _EXIF_TOOL_URL, _PHOTOS_4_VERSION, _UNKNOWN_PLACE
from ._version import __version__
from .exiftool import get_exiftool_path
from .photoinfo.template import TEMPLATE_SUBSTITUTIONS, TEMPLATE_SUBSTITUTIONS_MULTI_VALUED
from .photoinfo.template import (
TEMPLATE_SUBSTITUTIONS,
TEMPLATE_SUBSTITUTIONS_MULTI_VALUED,
)
from .utils import _copy_file, create_path_by_date
@@ -89,7 +92,7 @@ class ExportCommand(click.Command):
)
formatter.write("\n")
formatter.write_text(
"The templating system may also be used with the --keyword-template option "
"The templating system may also be used with the --keyword-template option "
+ "to set keywords on export (with --exiftool or --sidecar), "
+ "for example, to set a new keyword in format 'folder/subfolder/album' to "
+ 'preserve the folder/album structure, you can use --keyword-template "{folder_album}"'
@@ -778,6 +781,7 @@ def query(
]
# print help if no non-exclusive term or a double exclusive term is given
if not any(nonexclusive + [b ^ n for b, n in exclusive]):
click.echo("Incompatible query options", err=True)
click.echo(cli.commands["query"].get_help(ctx), err=True)
return
@@ -863,7 +867,8 @@ def query(
@click.option(
"--export-as-hardlink",
is_flag=True,
help="Hardlink files instead of copying them. ",
help="Hardlink files instead of copying them. "
"Cannot be used with --exiftool which creates copies of the files with embedded EXIF data.",
)
@click.option(
"--overwrite",
@@ -961,7 +966,8 @@ def query(
is_flag=True,
help="Use exiftool to write metadata directly to exported photos. "
"To use this option, exiftool must be installed and in the path. "
"exiftool may be installed from https://exiftool.org/",
"exiftool may be installed from https://exiftool.org/. "
"Cannot be used with --export-as-hardlink.",
)
@click.option(
"--directory",
@@ -1082,9 +1088,11 @@ def export(
(selfie, not_selfie),
(panorama, not_panorama),
(export_by_date, directory),
(export_as_hardlink, exiftool),
(any(place), no_place),
]
if any([all(bb) for bb in exclusive]):
click.echo("Incompatible export options",err=True)
click.echo(cli.commands["export"].get_help(ctx), err=True)
return

View File

@@ -243,7 +243,7 @@ def test_export():
assert sorted(files) == sorted(CLI_EXPORT_FILENAMES)
def test_export_using_hardlinks():
def test_export_as_hardlink():
import glob
import os
import os.path
@@ -263,7 +263,7 @@ def test_export_using_hardlinks():
assert sorted(files) == sorted(CLI_EXPORT_FILENAMES)
def test_export_using_hardlinks_samefile():
def test_export_as_hardlink_samefile():
# test that --export-as-hardlink actually creates a hardlink
# src and dest should be same file
import os
@@ -291,7 +291,33 @@ def test_export_using_hardlinks_samefile():
assert os.path.exists(CLI_EXPORT_UUID_FILENAME)
assert os.path.samefile(CLI_EXPORT_UUID_FILENAME, photo.path)
def test_export_using_hardlinks_incompat_options():
# test that error shown if --export-as-hardlink used with --exiftool
import os
import osxphotos
from osxphotos.__main__ import export
runner = CliRunner()
cwd = os.getcwd()
photosdb = osxphotos.PhotosDB(dbfile=CLI_PHOTOS_DB)
photo = photosdb.photos(uuid=[CLI_EXPORT_UUID])[0]
# pylint: disable=not-context-manager
with runner.isolated_filesystem():
result = runner.invoke(
export,
[
os.path.join(cwd, CLI_PHOTOS_DB),
".",
f"--uuid={CLI_EXPORT_UUID}",
"--export-as-hardlink",
"--exiftool",
"-V",
],
)
assert result.exit_code == 0
assert "Incompatible export options" in result.output
def test_export_current_name():
import glob
import os