Added get_selected() to REPL

This commit is contained in:
Rhet Turnbull
2021-07-02 13:19:15 -07:00
parent 391b0a577b
commit 2e1c91cd67
2 changed files with 17 additions and 1 deletions

View File

@@ -1,3 +1,3 @@
""" version info """
__version__ = "0.42.53"
__version__ = "0.42.54"

View File

@@ -16,6 +16,7 @@ import time
import bitmath
import click
import osxmetadata
import photoscript
import yaml
from rich import pretty
@@ -3900,11 +3901,24 @@ def _load_photos_db(dbpath):
def _get_photos(photosdb):
"""get list of all photos in photosdb"""
photos = photosdb.photos(images=True, movies=True)
photos.extend(photosdb.photos(images=True, movies=True, intrash=True))
return photos
def _get_selected(photosdb):
"""get list of PhotoInfo objects for photos selected in Photos"""
def get_selected():
selected = photoscript.PhotosLibrary().selection
if not selected:
return []
return photosdb.photos(uuid=[p.uuid for p in selected])
return get_selected
@cli.command()
@DB_OPTION
@click.pass_obj
@@ -3925,6 +3939,7 @@ def repl(ctx, cli_obj, db):
# shortcut for helper functions
get_photo = photosdb.get_photo
show = _show_photo
get_selected = _get_selected(photosdb)
print(f"Found {len(photos)} photos in {tictoc:0.2f} seconds")
print("The following variables are defined:")
@@ -3934,6 +3949,7 @@ def repl(ctx, cli_obj, db):
)
print(f"\nThe following functions may be helpful:")
print(f"- get_photo(uuid): return a PhotoInfo object for photo with uuid")
print(f"- get_selected(): return list of PhotoInfo objects for photos selected in Photos")
print(f"- show(photo): open a photo object in the default viewer")
print(
f"- help(object): print help text including list of methods for object; for example, help(PhotosDB)"