Added query to cmd_line and added __repr__ and __str__ to osxphotos classes
This commit is contained in:
parent
9db32a51ca
commit
07c9c31a09
@ -10,6 +10,7 @@ from shutil import copyfile
|
|||||||
import pprint
|
import pprint
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
import yaml
|
||||||
import objc
|
import objc
|
||||||
import CoreFoundation
|
import CoreFoundation
|
||||||
from Foundation import *
|
from Foundation import *
|
||||||
@ -18,7 +19,6 @@ from . import _applescript
|
|||||||
|
|
||||||
# from loguru import logger
|
# from loguru import logger
|
||||||
|
|
||||||
# TODO: add get_database_path (full path to db file)
|
|
||||||
# TODO: standardize _ and __ as leading char for private variables
|
# TODO: standardize _ and __ as leading char for private variables
|
||||||
# TODO: fix use of ''' and """
|
# TODO: fix use of ''' and """
|
||||||
# TODO: fix docstrings
|
# TODO: fix docstrings
|
||||||
@ -592,7 +592,8 @@ class PhotosDB:
|
|||||||
photoinfo.append(info)
|
photoinfo.append(info)
|
||||||
return photoinfo
|
return photoinfo
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"osxphotos.PhotosDB(dbfile='{self.get_db_path()}')"
|
||||||
"""
|
"""
|
||||||
Info about a specific photo, contains all the details we know about the photo
|
Info about a specific photo, contains all the details we know about the photo
|
||||||
including keywords, persons, albums, uuid, path, etc.
|
including keywords, persons, albums, uuid, path, etc.
|
||||||
@ -664,6 +665,25 @@ class PhotoInfo:
|
|||||||
def hasadjustments(self):
|
def hasadjustments(self):
|
||||||
return True if self.__info["hasAdjustments"] == 1 else False
|
return True if self.__info["hasAdjustments"] == 1 else False
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"osxphotos.PhotoInfo(db={self.__db}, uuid='{self.__uuid}', info={self.__info})"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
info = {
|
||||||
|
"uuid": self.uuid(),
|
||||||
|
"filename": self.filename(),
|
||||||
|
"date": str(self.date()),
|
||||||
|
"description": self.description(),
|
||||||
|
"name": self.name(),
|
||||||
|
"keywords": self.keywords(),
|
||||||
|
"albums": self.albums(),
|
||||||
|
"persons": self.persons(),
|
||||||
|
"path": self.path(),
|
||||||
|
"ismissing": self.ismissing(),
|
||||||
|
"hasadjustments": self.hasadjustments(),
|
||||||
|
}
|
||||||
|
return yaml.dump(info,sort_keys=False)
|
||||||
|
|
||||||
# compare two PhotoInfo objects for equality
|
# compare two PhotoInfo objects for equality
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if isinstance(other, self.__class__):
|
if isinstance(other, self.__class__):
|
||||||
|
|||||||
@ -12,8 +12,8 @@ class CLI_Obj:
|
|||||||
self.photosdb = osxphotos.PhotosDB(dbfile=db)
|
self.photosdb = osxphotos.PhotosDB(dbfile=db)
|
||||||
self.json = json
|
self.json = json
|
||||||
|
|
||||||
|
CTX_SETTINGS=dict(help_option_names=['-h','--help'])
|
||||||
@click.group()
|
@click.group(context_settings=CTX_SETTINGS)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--db",
|
"--db",
|
||||||
required=False,
|
required=False,
|
||||||
@ -97,7 +97,6 @@ def info(cli_obj):
|
|||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
# @click.option('--delim',default=",",help="")
|
|
||||||
@click.pass_obj
|
@click.pass_obj
|
||||||
def dump(cli_obj):
|
def dump(cli_obj):
|
||||||
""" print list of all photos & associated info from the Photos library """
|
""" print list of all photos & associated info from the Photos library """
|
||||||
@ -164,5 +163,28 @@ def dump(cli_obj):
|
|||||||
csv_writer.writerow(row)
|
csv_writer.writerow(row)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@click.option("--keyword", default=None, multiple=True, help="search for keyword(s)")
|
||||||
|
@click.option("--person", default=None, multiple=True, help="search for person(s)")
|
||||||
|
@click.option("--album", default=None, multiple=True, help="search for album(s)")
|
||||||
|
@click.option("--uuid", default=None, multiple=True, help="search for UUID(s)")
|
||||||
|
@click.pass_obj
|
||||||
|
@click.pass_context
|
||||||
|
def query(ctx, cli_obj, keyword, person, album, uuid):
|
||||||
|
""" query the Photos database using 1 or more search options """
|
||||||
|
photos = cli_obj.photosdb.photos(keywords=keyword, persons=person, albums=album, uuid=uuid)
|
||||||
|
print(photos)
|
||||||
|
pass
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@click.argument('topic', default=None, required=False, nargs=1 )
|
||||||
|
@click.pass_context
|
||||||
|
def help(ctx, topic, **kw):
|
||||||
|
""" print help; for help on commands: help <command> """
|
||||||
|
if topic is None:
|
||||||
|
print(ctx.parent.get_help())
|
||||||
|
else:
|
||||||
|
print(cli.commands[topic].get_help(ctx))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cli()
|
cli()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user