From e98c3fe42912ac16d13675bf14154981089d41ea Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Tue, 16 Jun 2020 22:46:46 -0700 Subject: [PATCH] Added show() to photos_repl.py --- examples/photos_repl.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/examples/photos_repl.py b/examples/photos_repl.py index 52a3c5e6..e41dbaa5 100755 --- a/examples/photos_repl.py +++ b/examples/photos_repl.py @@ -7,6 +7,7 @@ # If you run this using python from command line, do so with -i flag: # python3 -i examples/photos_repl.py +import os import sys import time @@ -17,6 +18,23 @@ import osxphotos from osxphotos.__main__ import get_photos_db, _list_libraries +def show(photo): + """ open image with default image viewer + + Note: This is for debugging only -- it will actually open any filetype which could + be very, very bad. + + Args: + photo: PhotoInfo object or a path to a photo on disk + """ + photopath = photo.path if isinstance(photo, osxphotos.PhotoInfo) else photo + + if not os.path.isfile(photopath): + return f"'{photopath}' does not appear to be a valid photo path" + + os.system(f"open '{photopath}'") + + def main(): db = None