Refactored _query. Still hairy, but less so.

This commit is contained in:
Rhet Turnbull
2020-01-19 19:50:34 -08:00
parent 7150956a48
commit b9dee4995c
2 changed files with 96 additions and 97 deletions

View File

@@ -80,7 +80,8 @@ DB_OPTION = click.option(
DB_ARGUMENT = click.argument("photos_library", nargs=-1, type=click.Path(exists=True)) DB_ARGUMENT = click.argument("photos_library", nargs=-1, type=click.Path(exists=True))
JSON_OPTION = click.option( JSON_OPTION = click.option(
"--json", "json_", "--json",
"json_",
required=False, required=False,
is_flag=True, is_flag=True,
default=False, default=False,
@@ -572,37 +573,37 @@ def query(
return return
photos = _query( photos = _query(
db, db=db,
keyword, keyword=keyword,
person, person=person,
album, album=album,
uuid, uuid=uuid,
title, title=title,
no_title, no_title=no_title,
description, description=description,
no_description, no_description=no_description,
ignore_case, ignore_case=ignore_case,
edited, edited=edited,
external_edit, external_edit=external_edit,
favorite, favorite=favorite,
not_favorite, not_favorite=not_favorite,
hidden, hidden=hidden,
not_hidden, not_hidden=not_hidden,
missing, missing=missing,
not_missing, not_missing=not_missing,
shared, shared=shared,
not_shared, not_shared=not_shared,
isphoto, isphoto=isphoto,
ismovie, ismovie=ismovie,
uti, uti=uti,
burst, burst=burst,
not_burst, not_burst=not_burst,
live, live=live,
not_live, not_live=not_live,
cloudasset, cloudasset=cloudasset,
not_cloudasset, not_cloudasset=not_cloudasset,
incloud, incloud=incloud,
not_incloud, not_incloud=not_incloud,
) )
print_photo_info(photos, cli_obj.json or json_) print_photo_info(photos, cli_obj.json or json_)
@@ -764,37 +765,37 @@ def export(
return return
photos = _query( photos = _query(
db, db=db,
keyword, keyword=keyword,
person, person=person,
album, album=album,
uuid, uuid=uuid,
title, title=title,
no_title, no_title=no_title,
description, description=description,
no_description, no_description=no_description,
ignore_case, ignore_case=ignore_case,
edited, edited=edited,
external_edit, external_edit=external_edit,
favorite, favorite=favorite,
not_favorite, not_favorite=not_favorite,
hidden, hidden=hidden,
not_hidden, not_hidden=not_hidden,
None, # missing -- won't export these but will warn user missing=None, # missing -- won't export these but will warn user
None, # not-missing not_missing=None,
shared, shared=shared,
not_shared, not_shared=not_shared,
isphoto, isphoto=isphoto,
ismovie, ismovie=ismovie,
uti, uti=uti,
burst, burst=burst,
not_burst, not_burst=not_burst,
live, live=live,
not_live, not_live=not_live,
False, # cloudasset cloudasset=False,
False, # not_cloudasset not_cloudasset=False,
False, # incloud incloud=False,
False, # not_incloud not_incloud=False,
) )
if photos: if photos:
@@ -939,45 +940,43 @@ def print_photo_info(photos, json=False):
def _query( def _query(
db, db=None,
keyword, keyword=None,
person, person=None,
album, album=None,
uuid, uuid=None,
title, title=None,
no_title, no_title=None,
description, description=None,
no_description, no_description=None,
ignore_case, ignore_case=None,
edited, edited=None,
external_edit, external_edit=None,
favorite, favorite=None,
not_favorite, not_favorite=None,
hidden, hidden=None,
not_hidden, not_hidden=None,
missing, missing=None,
not_missing, not_missing=None,
shared, shared=None,
not_shared, not_shared=None,
isphoto, isphoto=None,
ismovie, ismovie=None,
uti, uti=None,
burst, burst=None,
not_burst, not_burst=None,
live, live=None,
not_live, not_live=None,
cloudasset, cloudasset=None,
not_cloudasset, not_cloudasset=None,
incloud, incloud=None,
not_incloud, not_incloud=None,
): ):
""" run a query against PhotosDB to extract the photos based on user supply criteria """ """ run a query against PhotosDB to extract the photos based on user supply criteria """
""" used by query and export commands """ """ used by query and export commands """
""" arguments must be passed in same order as query and export """ """ arguments must be passed in same order as query and export """
""" if either is modified, need to ensure all three functions are updated """ """ if either is modified, need to ensure all three functions are updated """
# TODO: this is getting too hairy -- need to change to named args
photosdb = osxphotos.PhotosDB(dbfile=db) photosdb = osxphotos.PhotosDB(dbfile=db)
photos = photosdb.photos( photos = photosdb.photos(
keywords=keyword, keywords=keyword,

View File

@@ -1,3 +1,3 @@
""" version info """ """ version info """
__version__ = "0.22.2" __version__ = "0.22.3"