Added PhotosDB() behavior to open last library if no args passed but also added cautionary note to README

This commit is contained in:
Rhet Turnbull
2020-02-01 08:16:20 -08:00
parent 476e094365
commit 46d3c7dbda
2 changed files with 7 additions and 5 deletions

View File

@@ -268,6 +268,7 @@ if __name__ == "__main__":
#### Read a Photos library database #### Read a Photos library database
```python ```python
osxphotos.PhotosDB() # not recommended, see Note below
osxphotos.PhotosDB(path) osxphotos.PhotosDB(path)
osxphotos.PhotosDB(dbfile=path) osxphotos.PhotosDB(dbfile=path)
``` ```
@@ -278,6 +279,8 @@ Pass the path to a Photos library or to a specific database file (e.g. "/Users/s
If an invalid path is passed, PhotosDB will raise `ValueError` exception. If an invalid path is passed, PhotosDB will raise `ValueError` exception.
**Note**: If neither path or dbfile is passed, PhotosDB will use get_last_library_path to open the last opened Photos library. This usually works but is not 100% reliable. It can also lead to loading a different library than expected if the user has held down *option* key when opening Photos to switch libraries. It is therefore recommended you explicitely pass the path to `PhotosDB()`.
Open the default (last opened) Photos library. (E.g. this is the library that would open if the user opened Photos.app) Open the default (last opened) Photos library. (E.g. this is the library that would open if the user opened Photos.app)
```python ```python

View File

@@ -165,11 +165,10 @@ class PhotosDB:
dbfile_, dbfile_,
) )
elif dbfile is None: elif dbfile is None:
raise TypeError( dbfile = get_last_library_path()
f"photos database path must be specified as argument or named parameter dbfile", if dbfile is None:
dbfile_, # get_last_library_path must have failed to find library
dbfile, raise FileNotFoundError("Could not get path to photo library database")
)
if os.path.isdir(dbfile): if os.path.isdir(dbfile):
# passed a directory, assume it's a photoslibrary # passed a directory, assume it's a photoslibrary