CLI now looks for photos library to use if non specified by user

This commit is contained in:
Rhet Turnbull
2020-01-20 08:26:32 -08:00
parent d37e6d9725
commit 50b7e6920a
3 changed files with 32 additions and 27 deletions

View File

@@ -87,7 +87,12 @@ Options:
--db <Photos database path> Specify Photos database path. Path to Photos --db <Photos database path> Specify Photos database path. Path to Photos
library/database can be specified using library/database can be specified using
either --db or directly as PHOTOS_LIBRARY either --db or directly as PHOTOS_LIBRARY
positional argument. positional argument. If neither --db or
PHOTOS_LIBRARY provided, will attempt to
find the library to use in the following
order: 1. last opened library, 2. system
library, 3. ~/Pictures/Photos
Library.photoslibrary
--keyword TEXT Search for keyword(s). --keyword TEXT Search for keyword(s).
--person TEXT Search for person(s). --person TEXT Search for person(s).
--album TEXT Search for album(s). --album TEXT Search for album(s).

View File

@@ -17,39 +17,37 @@ from .utils import create_path_by_date, _copy_file
def get_photos_db(*db_options): def get_photos_db(*db_options):
""" Return path to photos db, select first non-None arg """ Return path to photos db, select first non-None db_options
If no db_options are non-None, try to find library to use in
the following order:
- last library opened
- system library
- ~/Pictures/Photos Library.photoslibrary
- failing above, returns None
""" """
if db_options: if db_options:
for db in db_options: for db in db_options:
if db is not None: if db is not None:
return db return db
# _list_libraries() # if get here, no valid database paths passed, so try to figure out which to use
db = osxphotos.utils.get_last_library_path()
if db is not None:
click.echo(f"Using last opened Photos library: {db}", err=True)
return db
db = osxphotos.utils.get_system_library_path()
if db is not None:
click.echo(f"Using system Photos library: {db}", err=True)
return db
db = os.path.expanduser("~/Pictures/Photos Library.photoslibrary")
if os.path.isdir(db):
click.echo(f"Using Photos library: {db}", err=True)
return db
else:
return None return None
# if get here, no valid database paths passed, so ask user
# _, major, _ = osxphotos.utils._get_os_version()
# last_lib = osxphotos.utils.get_last_library_path()
# if last_lib is not None:
# db = last_lib
# return db
# sys_lib = None
# if int(major) >= 15:
# sys_lib = osxphotos.utils.get_system_library_path()
# if sys_lib is not None:
# db = sys_lib
# return db
# db = os.path.expanduser("~/Pictures/Photos Library.photoslibrary")
# if os.path.isdir(db):
# return db
# else:
# return None ### TODO: put list here
# Click CLI object & context settings # Click CLI object & context settings
class CLI_Obj: class CLI_Obj:
@@ -70,6 +68,8 @@ DB_OPTION = click.option(
"Specify Photos database path. " "Specify Photos database path. "
"Path to Photos library/database can be specified using either --db " "Path to Photos library/database can be specified using either --db "
"or directly as PHOTOS_LIBRARY positional argument. " "or directly as PHOTOS_LIBRARY positional argument. "
"If neither --db or PHOTOS_LIBRARY provided, will attempt to find the library "
"to use in the following order: 1. last opened library, 2. system library, 3. ~/Pictures/Photos Library.photoslibrary"
), ),
type=click.Path(exists=True), type=click.Path(exists=True),
) )

View File

@@ -1,3 +1,3 @@
""" version info """ """ version info """
__version__ = "0.22.4" __version__ = "0.22.5"