From 83186a655dfc18c870050f612dd5dd1f350002c1 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sat, 23 Nov 2019 14:48:38 -0800 Subject: [PATCH] Changed path() to return absolute path and fixed tests --- README.md | 8 ++++++-- osxphotos/__init__.py | 6 +++--- tests/test_10_12_6.py | 10 ++++++---- tests/test_catalina_10_15_1.py | 5 ++--- tests/test_highsierra.py | 10 ++++++---- tests/test_mojave_10_14_5.py | 10 ++++++---- tests/test_mojave_10_14_6.py | 10 ++++++---- 7 files changed, 35 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 9abaf9cd..863a23a2 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ def main(): print( p.uuid, p.filename(), + p.original_filename(), p.date(), p.description(), p.name(), @@ -286,7 +287,10 @@ PhotosDB.photos() returns a list of PhotoInfo objects. Each PhotoInfo object re Returns the universally unique identifier (uuid) of the photo. This is how Photos keeps track of individual photos within the database. #### `filename()` -Returns the filename of the photo +Returns the filename of the photo on disk + +#### `original_filename()` +Returns the original filename of the photo when it was imported to Photos. Photos 5.0+ renames the photo when it adds the file to the library using UUID. For Photos 4.0 and below, filename() == original_filename() #### `date()` Returns the date of the photo as a datetime.datetime object @@ -307,7 +311,7 @@ Returns a list of albums the photo is contained in Returns a list of the names of the persons in the photo #### `path()` -Returns the path to the photo on disk as a string. Note: this returns the path to the *original* unedited file (see `hasadjustments()`). If the file is missing on disk, path=`None` (see `ismissing()`) +Returns the absolute path to the photo on disk as a string. Note: this returns the path to the *original* unedited file (see `hasadjustments()`). If the file is missing on disk, path=`None` (see `ismissing()`) #### `ismissing()` Returns `True` if the original image file is missing on disk, otherwise `False`. This can occur if the file has been uploaded to iCloud but not yet downloaded to the local library or if the file was deleted or imported from a disk that has been unmounted. Note: this status is set by Photos and osxphotos does not verify that the file path returned by `path()` actually exists. It merely reports what Photos has stored in the library database. diff --git a/osxphotos/__init__.py b/osxphotos/__init__.py index 18bec3e4..47f2d714 100644 --- a/osxphotos/__init__.py +++ b/osxphotos/__init__.py @@ -46,7 +46,7 @@ _PHOTOS_5_VERSION = "6000" _TESTED_OS_VERSIONS = ["12", "13", "14", "15"] # set _debug = True to enable debug output -_debug = False +_debug = True logging.basicConfig( level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(filename)s - %(lineno)d - %(message)s", @@ -155,7 +155,7 @@ class PhotosDB: # TODO: replace os.path with pathlib # TODO: clean this up -- we'll already know library_path - library_path = os.path.dirname(dbfile) + library_path = os.path.dirname(os.path.abspath(dbfile)) (library_path, _) = os.path.split(library_path) if int(self._db_version) < int(_PHOTOS_5_VERSION): masters_path = os.path.join(library_path, "Masters") @@ -1136,7 +1136,7 @@ class PhotoInfo: ) else: photopath = None - logging.debug("WARNING: masterFingerprint null", pformat(self.__info)) + logging.debug(f"WARNING: masterFingerprint null {pformat(self.__info)}") # TODO: fix the logic for isMissing if self.__info["isMissing"] == 1: diff --git a/tests/test_10_12_6.py b/tests/test_10_12_6.py index 13c32157..b25b758b 100644 --- a/tests/test_10_12_6.py +++ b/tests/test_10_12_6.py @@ -116,15 +116,17 @@ def test_attributes(): assert len(photos) == 1 p = photos[0] assert p.keywords() == ["Kids"] + assert p.original_filename() == "Pumkins2.jpg" assert p.filename() == "Pumkins2.jpg" - assert p.date() == datetime.datetime(2018, 9, 28, 16, 7, 7,0,datetime.timezone(datetime.timedelta(seconds=-14400))) + assert p.date() == datetime.datetime( + 2018, 9, 28, 16, 7, 7, 0, datetime.timezone(datetime.timedelta(seconds=-14400)) + ) assert p.description() == "Girl holding pumpkin" assert p.name() == "I found one!" assert p.albums() == ["Pumpkin Farm"] assert p.persons() == ["Katie"] - assert ( - p.path() - == "./tests/Test-10.12.6.photoslibrary/Masters/2019/08/24/20190824-030824/Pumkins2.jpg" + assert p.path().endswith( + "/tests/Test-10.12.6.photoslibrary/Masters/2019/08/24/20190824-030824/Pumkins2.jpg" ) assert p.ismissing() == False diff --git a/tests/test_catalina_10_15_1.py b/tests/test_catalina_10_15_1.py index 9ef2c812..e7190415 100644 --- a/tests/test_catalina_10_15_1.py +++ b/tests/test_catalina_10_15_1.py @@ -125,9 +125,8 @@ def test_attributes(): assert p.name() == "I found one!" assert p.albums() == ["Pumpkin Farm"] assert p.persons() == ["Katie"] - assert ( - p.path() - == "tests/Test-10.15.1.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg" + assert p.path().endswith( + "tests/Test-10.15.1.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg" ) assert p.ismissing() == False diff --git a/tests/test_highsierra.py b/tests/test_highsierra.py index e88712b8..6cd8bb72 100644 --- a/tests/test_highsierra.py +++ b/tests/test_highsierra.py @@ -115,15 +115,17 @@ def test_attributes(): assert len(photos) == 1 p = photos[0] assert p.keywords() == ["Kids"] + assert p.original_filename() == "Pumkins2.jpg" assert p.filename() == "Pumkins2.jpg" - assert p.date() == datetime.datetime(2018, 9, 28, 16, 7, 7,0,datetime.timezone(datetime.timedelta(seconds=-14400))) + assert p.date() == datetime.datetime( + 2018, 9, 28, 16, 7, 7, 0, datetime.timezone(datetime.timedelta(seconds=-14400)) + ) assert p.description() == "Girl holding pumpkin" assert p.name() == "I found one!" assert p.albums() == ["Pumpkin Farm"] assert p.persons() == ["Katie"] - assert ( - p.path() - == "./tests/Test-10.13.6.photoslibrary/Masters/2019/07/26/20190726-203227/Pumkins2.jpg" + assert p.path().endswith( + "/tests/Test-10.13.6.photoslibrary/Masters/2019/07/26/20190726-203227/Pumkins2.jpg" ) assert p.ismissing() == False diff --git a/tests/test_mojave_10_14_5.py b/tests/test_mojave_10_14_5.py index dcd9684d..740b86c8 100644 --- a/tests/test_mojave_10_14_5.py +++ b/tests/test_mojave_10_14_5.py @@ -115,15 +115,17 @@ def test_attributes(): assert len(photos) == 1 p = photos[0] assert p.keywords() == ["Kids"] + assert p.original_filename() == "Pumkins2.jpg" assert p.filename() == "Pumkins2.jpg" - assert p.date() == datetime.datetime(2018, 9, 28, 16, 7, 7,0,datetime.timezone(datetime.timedelta(seconds=-14400))) + assert p.date() == datetime.datetime( + 2018, 9, 28, 16, 7, 7, 0, datetime.timezone(datetime.timedelta(seconds=-14400)) + ) assert p.description() == "Girl holding pumpkin" assert p.name() == "I found one!" assert p.albums() == ["Pumpkin Farm"] assert p.persons() == ["Katie"] - assert ( - p.path() - == "./tests/Test-10.14.5.photoslibrary/Masters/2019/07/27/20190727-131650/Pumkins2.jpg" + assert p.path().endswith( + "/tests/Test-10.14.5.photoslibrary/Masters/2019/07/27/20190727-131650/Pumkins2.jpg" ) assert p.ismissing() == False diff --git a/tests/test_mojave_10_14_6.py b/tests/test_mojave_10_14_6.py index e13efadb..b7697600 100644 --- a/tests/test_mojave_10_14_6.py +++ b/tests/test_mojave_10_14_6.py @@ -115,15 +115,17 @@ def test_attributes(): assert len(photos) == 1 p = photos[0] assert p.keywords() == ["Kids"] + assert p.original_filename() == "Pumkins2.jpg" assert p.filename() == "Pumkins2.jpg" - assert p.date() == datetime.datetime(2018, 9, 28, 16, 7, 7,0,datetime.timezone(datetime.timedelta(seconds=-14400))) + assert p.date() == datetime.datetime( + 2018, 9, 28, 16, 7, 7, 0, datetime.timezone(datetime.timedelta(seconds=-14400)) + ) assert p.description() == "Girl holding pumpkin" assert p.name() == "I found one!" assert p.albums() == ["Pumpkin Farm"] assert p.persons() == ["Katie"] - assert ( - p.path() - == "./tests/Test-10.14.6.photoslibrary/Masters/2019/07/27/20190727-131650/Pumkins2.jpg" + assert p.path().endswith( + "/tests/Test-10.14.6.photoslibrary/Masters/2019/07/27/20190727-131650/Pumkins2.jpg" ) assert p.ismissing() == False