From b9dee4995c6d89fadb3d2482374b7098f2ab5ed9 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sun, 19 Jan 2020 19:50:34 -0800 Subject: [PATCH] Refactored _query. Still hairy, but less so. --- osxphotos/__main__.py | 191 +++++++++++++++++++++--------------------- osxphotos/_version.py | 2 +- 2 files changed, 96 insertions(+), 97 deletions(-) diff --git a/osxphotos/__main__.py b/osxphotos/__main__.py index 8e4c9879..f5d989a7 100644 --- a/osxphotos/__main__.py +++ b/osxphotos/__main__.py @@ -80,7 +80,8 @@ DB_OPTION = click.option( DB_ARGUMENT = click.argument("photos_library", nargs=-1, type=click.Path(exists=True)) JSON_OPTION = click.option( - "--json", "json_", + "--json", + "json_", required=False, is_flag=True, default=False, @@ -572,37 +573,37 @@ def query( return photos = _query( - db, - keyword, - person, - album, - uuid, - title, - no_title, - description, - no_description, - ignore_case, - edited, - external_edit, - favorite, - not_favorite, - hidden, - not_hidden, - missing, - not_missing, - shared, - not_shared, - isphoto, - ismovie, - uti, - burst, - not_burst, - live, - not_live, - cloudasset, - not_cloudasset, - incloud, - not_incloud, + db=db, + keyword=keyword, + person=person, + album=album, + uuid=uuid, + title=title, + no_title=no_title, + description=description, + no_description=no_description, + ignore_case=ignore_case, + edited=edited, + external_edit=external_edit, + favorite=favorite, + not_favorite=not_favorite, + hidden=hidden, + not_hidden=not_hidden, + missing=missing, + not_missing=not_missing, + shared=shared, + not_shared=not_shared, + isphoto=isphoto, + ismovie=ismovie, + uti=uti, + burst=burst, + not_burst=not_burst, + live=live, + not_live=not_live, + cloudasset=cloudasset, + not_cloudasset=not_cloudasset, + incloud=incloud, + not_incloud=not_incloud, ) print_photo_info(photos, cli_obj.json or json_) @@ -764,37 +765,37 @@ def export( return photos = _query( - db, - keyword, - person, - album, - uuid, - title, - no_title, - description, - no_description, - ignore_case, - edited, - external_edit, - favorite, - not_favorite, - hidden, - not_hidden, - None, # missing -- won't export these but will warn user - None, # not-missing - shared, - not_shared, - isphoto, - ismovie, - uti, - burst, - not_burst, - live, - not_live, - False, # cloudasset - False, # not_cloudasset - False, # incloud - False, # not_incloud + db=db, + keyword=keyword, + person=person, + album=album, + uuid=uuid, + title=title, + no_title=no_title, + description=description, + no_description=no_description, + ignore_case=ignore_case, + edited=edited, + external_edit=external_edit, + favorite=favorite, + not_favorite=not_favorite, + hidden=hidden, + not_hidden=not_hidden, + missing=None, # missing -- won't export these but will warn user + not_missing=None, + shared=shared, + not_shared=not_shared, + isphoto=isphoto, + ismovie=ismovie, + uti=uti, + burst=burst, + not_burst=not_burst, + live=live, + not_live=not_live, + cloudasset=False, + not_cloudasset=False, + incloud=False, + not_incloud=False, ) if photos: @@ -939,45 +940,43 @@ def print_photo_info(photos, json=False): def _query( - db, - keyword, - person, - album, - uuid, - title, - no_title, - description, - no_description, - ignore_case, - edited, - external_edit, - favorite, - not_favorite, - hidden, - not_hidden, - missing, - not_missing, - shared, - not_shared, - isphoto, - ismovie, - uti, - burst, - not_burst, - live, - not_live, - cloudasset, - not_cloudasset, - incloud, - not_incloud, + db=None, + keyword=None, + person=None, + album=None, + uuid=None, + title=None, + no_title=None, + description=None, + no_description=None, + ignore_case=None, + edited=None, + external_edit=None, + favorite=None, + not_favorite=None, + hidden=None, + not_hidden=None, + missing=None, + not_missing=None, + shared=None, + not_shared=None, + isphoto=None, + ismovie=None, + uti=None, + burst=None, + not_burst=None, + live=None, + not_live=None, + cloudasset=None, + not_cloudasset=None, + incloud=None, + not_incloud=None, ): """ run a query against PhotosDB to extract the photos based on user supply criteria """ """ used by query and export commands """ """ arguments must be passed in same order as query and export """ """ 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) photos = photosdb.photos( keywords=keyword, diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 32d7837e..7ff27590 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.22.2" +__version__ = "0.22.3"