From 667c89e32c3f96baeafebc03e83517ea05693b00 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sat, 24 Oct 2020 17:20:46 -0700 Subject: [PATCH] Cleaned up constructor for PhotosDB --- README.md | 2 +- osxphotos/_version.py | 2 +- osxphotos/photosdb/photosdb.py | 31 +++++++------------------------ 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 60b96e30..724aee05 100644 --- a/README.md +++ b/README.md @@ -697,7 +697,7 @@ osxphotos.PhotosDB(dbfile=path) Reads the Photos library database and returns a PhotosDB object. -Pass the path to a Photos library or to a specific database file (e.g. "/Users/smith/Pictures/Photos Library.photoslibrary" or "/Users/smith/Pictures/Photos Library.photoslibrary/database/photos.db"). Normally, it's recommended you pass the path the .photoslibrary folder, not the actual database path. The latter option is provided for debugging -- e.g. for reading a database file if you don't have the entire library. Path to photos library may be passed **either** as first argument **or** as named argument `dbfile`. **Note**: In Photos, users may specify a different library to open by holding down the *option* key while opening Photos.app. See also [get_last_library_path](#get_last_library_path) and [get_system_library_path](#get_system_library_path) +Pass the path to a Photos library or to a specific database file (e.g. "/Users/smith/Pictures/Photos Library.photoslibrary" or "/Users/smith/Pictures/Photos Library.photoslibrary/database/photos.db"). Normally, it's recommended you pass the path the .photoslibrary folder, not the actual database path. **Note**: In Photos, users may specify a different library to open by holding down the *option* key while opening Photos.app. See also [get_last_library_path](#get_last_library_path) and [get_system_library_path](#get_system_library_path) If an invalid path is passed, PhotosDB will raise `FileNotFoundError` exception. diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 505da923..ae0ae717 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,4 +1,4 @@ """ version info """ -__version__ = "0.35.7" +__version__ = "0.35.8" diff --git a/osxphotos/photosdb/photosdb.py b/osxphotos/photosdb/photosdb.py index 3fc5010c..53beac2f 100644 --- a/osxphotos/photosdb/photosdb.py +++ b/osxphotos/photosdb/photosdb.py @@ -68,11 +68,12 @@ class PhotosDB: ) from ._photosdb_process_scoreinfo import _process_scoreinfo - def __init__(self, *dbfile_, dbfile=None): - """ create a new PhotosDB object - path to photos library or database may be specified EITHER as first argument or as named argument dbfile=path - specify full path to photos library or photos.db as first argument - specify path to photos library or photos.db using named argument dbfile=path """ + def __init__(self, dbfile=None): + """ Create a new PhotosDB object. + + Args: + dbfile: specify full path to photos library or photos.db; if None, will attempt to locate last library opened by Photos. + """ # Check OS version system = platform.system() @@ -216,25 +217,7 @@ class PhotosDB: if _debug(): logging.debug(f"dbfile = {dbfile}") - # get the path to photos library database - if dbfile_: - # got a library path as argument - if dbfile: - # shouldn't pass via both *args and dbfile= - raise TypeError( - f"photos database path must be specified as argument or " - f"named parameter dbfile but not both: args: {dbfile_}, dbfile: {dbfile}", - dbfile_, - dbfile, - ) - elif len(dbfile_) == 1: - dbfile = dbfile_[0] - else: - raise TypeError( - f"__init__ takes only a single argument (photos database path): {dbfile_}", - dbfile_, - ) - elif dbfile is None: + if dbfile is None: dbfile = get_last_library_path() if dbfile is None: # get_last_library_path must have failed to find library