From 3d21dadf4102e9101e48a0c6f739a544f7f9d9de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horst=20H=C3=B6ck?= <6313998+hhoeck@users.noreply.github.com> Date: Mon, 28 Sep 2020 21:49:31 +0200 Subject: [PATCH 1/8] Update exiftool.py Solve "Param --exiftool ruins --touch-file #222" --- osxphotos/exiftool.py | 1 + 1 file changed, 1 insertion(+) diff --git a/osxphotos/exiftool.py b/osxphotos/exiftool.py index 6e4fdbd0..b54ac9d6 100644 --- a/osxphotos/exiftool.py +++ b/osxphotos/exiftool.py @@ -98,6 +98,7 @@ class _ExifToolProc: "-", # read from stdin "-common_args", # specifies args common to all commands subsequently run "-n", # no print conversion (e.g. print tag values in machine readable format) + "-P", # Preserve file modification date/time (possible interfere w/ --touch-file) "-G", # print group name for each tag ], stdin=subprocess.PIPE, From c939df717159e8b97955c0b267327cd56a9ed56c Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Mon, 28 Sep 2020 21:23:47 -0700 Subject: [PATCH 2/8] Fixed bug related to issue #222 --- osxphotos/photoinfo/_photoinfo_export.py | 11 ++++------- tests/test_cli.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/osxphotos/photoinfo/_photoinfo_export.py b/osxphotos/photoinfo/_photoinfo_export.py index 627a8908..0a7c16eb 100644 --- a/osxphotos/photoinfo/_photoinfo_export.py +++ b/osxphotos/photoinfo/_photoinfo_export.py @@ -683,9 +683,6 @@ def export2( f"Error exporting photo {self.uuid} to {dest} with use_photos_export" ) - # export metadata - info = export_db.get_info_for_uuid(self.uuid) - if sidecar_json: logging.debug("writing exiftool_json_sidecar") sidecar_filename = dest.parent / pathlib.Path(f"{dest.stem}{dest.suffix}.json") @@ -797,9 +794,9 @@ def export2( if touch_file: for exif_file in exif_files_updated: - touched_files.append(exported_file) + touched_files.append(exif_file) ts = int(self.date.timestamp()) - fileutil.utime(exported_file, (ts, ts)) + fileutil.utime(exif_file, (ts, ts)) touched_files = list(set(touched_files)) @@ -1121,7 +1118,7 @@ def _xmp_sidecar( use_persons_as_keywords=False, keyword_template=None, description_template=None, - extension=None + extension=None, ): """ returns string for XMP sidecar use_albums_as_keywords: treat album names as keywords @@ -1134,7 +1131,7 @@ def _xmp_sidecar( if extension is None: extension = pathlib.Path(self.original_filename) extension = extension.suffix[1:] if extension.suffix else None - + if description_template is not None: description = self.render_template( description_template, expand_inplace=True, inplace_sep=", " diff --git a/tests/test_cli.py b/tests/test_cli.py index 51097278..e2aa6674 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -183,9 +183,9 @@ CLI_EXPORTED_FILENAME_TEMPLATE_FILENAMES2 = [ ] CLI_EXPORTED_FILENAME_TEMPLATE_FILENAMES_PATHSEP = [ -"2018-10 - Sponsion, Museum, Frühstück, Römermuseum/IMG_4547.jpg", -"Folder1/SubFolder2/AlbumInFolder/IMG_4547.jpg", -"2019-10:11 Paris Clermont/IMG_4547.jpg", + "2018-10 - Sponsion, Museum, Frühstück, Römermuseum/IMG_4547.jpg", + "Folder1/SubFolder2/AlbumInFolder/IMG_4547.jpg", + "2019-10:11 Paris Clermont/IMG_4547.jpg", ] CLI_EXPORT_UUID = "D79B8D77-BFFC-460B-9312-034F2877D35B" @@ -354,6 +354,7 @@ CLI_EXPORT_UUID_FROM_FILE_FILENAMES = [ "wedding_edited.jpeg", ] + # determine if exiftool installed so exiftool tests can be skipped try: exiftool = get_exiftool_path() @@ -398,7 +399,6 @@ def setup_touch_tests(): CLI_EXPORT_BY_DATE_TOUCH_UUID ) for photo in photos: - logging.warning(photo.path) ts = int(photo.date.timestamp()) if photo.path is not None: os.utime(photo.path, (ts, ts)) @@ -1826,6 +1826,7 @@ def test_export_filename_template_2(): files = glob.glob("*.*") assert sorted(files) == sorted(CLI_EXPORTED_FILENAME_TEMPLATE_FILENAMES2) + def test_export_filename_template_pathsep_in_name(): """ export photos using filename template with folder_album and "/" in album name """ import locale @@ -1850,7 +1851,7 @@ def test_export_filename_template_pathsep_in_name(): "--directory", "{folder_album,None}", "--uuid", - CLI_EXPORT_UUID_STATUE + CLI_EXPORT_UUID_STATUE, ], ) assert result.exit_code == 0 @@ -1858,6 +1859,7 @@ def test_export_filename_template_pathsep_in_name(): # assert fname in result.output assert pathlib.Path(fname).is_file() + def test_export_filename_template_3(): """ test --filename with invalid template """ import glob @@ -2951,7 +2953,7 @@ def test_export_touch_files_update(): @pytest.mark.skipif(exiftool is None, reason="exiftool not installed") def test_export_touch_files_exiftool_update(): - """ test complex export scenario with --update, --exiftol, and --touch-files """ + """ test complex export scenario with --update, --exiftool, and --touch-files """ import os import pathlib import time From 6883fec2b2236d892b88327e1b4e9da1237f7dea Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Mon, 28 Sep 2020 21:33:58 -0700 Subject: [PATCH 3/8] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ae1af577..b453d632 100644 --- a/README.md +++ b/README.md @@ -1880,6 +1880,7 @@ Thank-you to the following people who have contributed to improving osxphotos! - [grundsch](https://github.com/grundsch) - [Ag Primatic](https://github.com/agprimatic) - [Daniel M. Drucker](https://github.com/dmd) +- [Horst Höck](https://github.com/hhoeck) ## Known Bugs From 62d54cc0beabd0141545608184d4b2c658eedf0f Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Mon, 28 Sep 2020 21:35:17 -0700 Subject: [PATCH 4/8] Version bump for bug fix --- osxphotos/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 36c84a5b..9f1ee03b 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.34.2" +__version__ = "0.34.3" From 08725fd27fcd64d80ddc9543dad6bbe5a5ca4098 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Mon, 28 Sep 2020 21:38:51 -0700 Subject: [PATCH 5/8] Updated CHANGELOG.md --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 670852f8..eebcf3e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ 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.34.3](https://github.com/RhetTbull/osxphotos/compare/v0.34.2...v0.34.3) + +> 29 September 2020 + +- Update exiftool.py to preserve file modification time, thanks to @hhoeck [`#223`](https://github.com/RhetTbull/osxphotos/pull/223) +- Added tests for 10.15.6 [`432da7f`](https://github.com/RhetTbull/osxphotos/commit/432da7f139a5e4b37eeb358f4ede45314407f8e5) +- Fixed bug related to issue #222 [`c939df7`](https://github.com/RhetTbull/osxphotos/commit/c939df717159e8b97955c0b267327cd56a9ed56c) +- Version bump for bug fix [`62d54cc`](https://github.com/RhetTbull/osxphotos/commit/62d54cc0beabd0141545608184d4b2c658eedf0f) +- Update README.md [`6883fec`](https://github.com/RhetTbull/osxphotos/commit/6883fec2b2236d892b88327e1b4e9da1237f7dea) +- Update exiftool.py [`3d21dad`](https://github.com/RhetTbull/osxphotos/commit/3d21dadf4102e9101e48a0c6f739a544f7f9d9de) + #### [v0.34.2](https://github.com/RhetTbull/osxphotos/compare/v0.34.1...v0.34.2) > 14 September 2020 From 42a6373f8ded6800ff3e8ff970123c49868402c0 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Tue, 6 Oct 2020 06:22:17 -0700 Subject: [PATCH 6/8] Fix for issue #230 --- osxphotos/_version.py | 2 +- osxphotos/photosdb/photosdb.py | 3 ++- tests/test_cli.py | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 9f1ee03b..56ed4915 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.34.3" +__version__ = "0.34.4" diff --git a/osxphotos/photosdb/photosdb.py b/osxphotos/photosdb/photosdb.py index 144898ae..0b21e3e6 100644 --- a/osxphotos/photosdb/photosdb.py +++ b/osxphotos/photosdb/photosdb.py @@ -1296,11 +1296,12 @@ class PhotosDB: # get the place info that matches the RKPlace modelIDs for this photo # (place_ids), sort by area (element 3 of the place_data tuple in places) + # area could be None so assume 0 if it is (issue #230) place_names = [ pname for pname in sorted( [places[p] for p in places if p in place_ids], - key=lambda place: place[3], + key=lambda place: place[3] if place[3] is not None else 0, ) ] diff --git a/tests/test_cli.py b/tests/test_cli.py index e2aa6674..5d040914 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2951,7 +2951,8 @@ def test_export_touch_files_update(): ) -@pytest.mark.skipif(exiftool is None, reason="exiftool not installed") +@pytest.mark.skip("TODO: This fails on some machines but not all") +# @pytest.mark.skipif(exiftool is None, reason="exiftool not installed") def test_export_touch_files_exiftool_update(): """ test complex export scenario with --update, --exiftool, and --touch-files """ import os From 95157360193e9bb4fae54fe30a43ace3090481ab Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Tue, 6 Oct 2020 06:31:10 -0700 Subject: [PATCH 7/8] version bump --- osxphotos/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 56ed4915..ba0d8927 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.34.4" +__version__ = "0.34.5" From 0dd05b8cc14187593c08729b764b401cbf5073a0 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Wed, 7 Oct 2020 06:14:16 -0700 Subject: [PATCH 8/8] Updated tests, closes #231 --- tests/test_cli.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 5d040914..91e7e3d4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -194,8 +194,8 @@ CLI_EXPORT_UUID_STATUE = "3DD2C897-F19E-4CA6-8C22-B027D5A71907" CLI_EXPORT_UUID_FILENAME = "Pumkins2.jpg" CLI_EXPORT_BY_DATE_TOUCH_UUID = [ - "1EB2B765-0765-43BA-A90C-0D0580E6172C", - "F12384F6-CD17-4151-ACBA-AE0E3688539E", + "1EB2B765-0765-43BA-A90C-0D0580E6172C", # Pumpkins3.jpg + "F12384F6-CD17-4151-ACBA-AE0E3688539E", # Pumkins1.jpg ] CLI_EXPORT_BY_DATE_TOUCH_TIMES = [1538165373, 1538163349] CLI_EXPORT_BY_DATE_NEED_TOUCH = [ @@ -363,9 +363,9 @@ except: def touch_all_photos_in_db(dbpath): - """ touch date on all photos in a library + """touch date on all photos in a library helper function for --touch-file tests - + Args: dbpath: path to photos library to touch """ @@ -393,8 +393,10 @@ def setup_touch_tests(): import logging import osxphotos + # touch all photos so they do not match PhotoInfo.date touch_all_photos_in_db(PHOTOS_DB_TOUCH) + # adjust a couple of the photos so they're file times *are* correct photos = osxphotos.PhotosDB(PHOTOS_DB_TOUCH).photos_by_uuid( CLI_EXPORT_BY_DATE_TOUCH_UUID ) @@ -2951,8 +2953,8 @@ def test_export_touch_files_update(): ) -@pytest.mark.skip("TODO: This fails on some machines but not all") -# @pytest.mark.skipif(exiftool is None, reason="exiftool not installed") +# @pytest.mark.skip("TODO: This fails on some machines but not all") +@pytest.mark.skipif(exiftool is None, reason="exiftool not installed") def test_export_touch_files_exiftool_update(): """ test complex export scenario with --update, --exiftool, and --touch-files """ import os @@ -3056,14 +3058,10 @@ def test_export_touch_files_exiftool_update(): ) assert result.exit_code == 0 assert ( - "Exported: 0 photos, updated: 0 photos, skipped: 16 photos, updated EXIF data: 0 photos, touched date: 16 photos" + "Exported: 0 photos, updated: 0 photos, skipped: 16 photos, updated EXIF data: 0 photos, touched date: 14 photos" in result.output ) - for fname, mtime in zip(CLI_EXPORT_BY_DATE, CLI_EXPORT_BY_DATE_TOUCH_TIMES): - st = os.stat(fname) - assert int(st.st_mtime) != int(mtime) - # --update --touch-file --exiftool result = runner.invoke( export, @@ -3078,7 +3076,7 @@ def test_export_touch_files_exiftool_update(): ) assert result.exit_code == 0 assert ( - "Exported: 0 photos, updated: 0 photos, skipped: 16 photos, updated EXIF data: 0 photos, touched date: 16 photos" + "Exported: 0 photos, updated: 0 photos, skipped: 16 photos, updated EXIF data: 0 photos, touched date: 14 photos" in result.output )