From 5a832181f73e082927c80864f2063e554906b06b Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Thu, 18 Jun 2020 22:16:11 -0700 Subject: [PATCH] Fixed get_last_library_path and get_system_library_path to not raise KeyError --- osxphotos/_version.py | 2 +- osxphotos/utils.py | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/osxphotos/_version.py b/osxphotos/_version.py index c194f9d5..a321e013 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.29.21" +__version__ = "0.29.22" diff --git a/osxphotos/utils.py b/osxphotos/utils.py index fc042e9a..42534c13 100644 --- a/osxphotos/utils.py +++ b/osxphotos/utils.py @@ -149,7 +149,7 @@ def dd_to_dms_str(lat, lon): def get_system_library_path(): """ return the path to the system Photos library as string """ - """ only works on MacOS 10.15+ """ + """ only works on MacOS 10.15 """ """ on earlier versions, returns None """ _, major, _ = _get_os_version() if int(major) < 15: @@ -166,16 +166,10 @@ def get_system_library_path(): with open(plist_file, "rb") as fp: pl = plistload(fp) else: - logging.warning(f"could not find plist file: {str(plist_file)}") + logging.debug(f"could not find plist file: {str(plist_file)}") return None - photospath = pl.get("SystemLibraryPath") - - if photospath is not None: - return photospath - else: - logging.warning("Could not get path to Photos database") - return None + return pl.get("SystemLibraryPath") def get_last_library_path(): @@ -194,7 +188,7 @@ def get_last_library_path(): # get the IPXDefaultLibraryURLBookmark from com.apple.Photos.plist # this is a serialized CFData object - photosurlref = pl["IPXDefaultLibraryURLBookmark"] + photosurlref = pl.get("IPXDefaultLibraryURLBookmark") if photosurlref is not None: # use CFURLCreateByResolvingBookmarkData to de-serialize bookmark data into a CFURLRef