From 60ac8116aa04523812221d507aefc777573ee1b7 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 28 Jan 2021 17:03:19 -0800 Subject: [PATCH] Add delete command. --- frontends/etiquette_cli.py | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/frontends/etiquette_cli.py b/frontends/etiquette_cli.py index 52fa653..a7f8d80 100644 --- a/frontends/etiquette_cli.py +++ b/frontends/etiquette_cli.py @@ -179,6 +179,28 @@ def add_remove_tag_argparse(args, action): if args.autoyes or interactive.getpermission('Commit?'): photodb.commit() +def delete_argparse(args): + photodb = find_photodb() + + need_commit = False + if args.photo_id_args or args.photo_search_args: + photos = get_photos_from_args(args) + for photo in photos: + photo.delete() + need_commit = True + + if args.album_id_args or args.album_search_args: + albums = get_albums_from_args(args) + for album in albums: + album.delete() + need_commit = True + + if not need_commit: + return + + if args.autoyes or interactive.getpermission('Commit?'): + photodb.commit() + def digest_directory_argparse(args): directory = pathclass.Path(args.directory) photodb = find_photodb() @@ -386,6 +408,8 @@ Etiquette CLI {remove_tag} +{delete} + {digest} {easybake} @@ -437,6 +461,18 @@ remove_tag: > etiquette_cli.py remove_tag watchlist spongebob*.mp4 '''.strip(), +delete=''' +delete: + Remove photos or albums from the database. + + > etiquette_cli.py delete --photos id id id + > etiquette_cli.py delete --search searchargs + > etiquette_cli.py delete --albums id id id + > etiquette_cli.py delete --album-search searchargs + + See search --help for more info about searchargs. +'''.strip(), + digest=''' digest: Digest a directory, adding new files as Photos into the database. @@ -686,6 +722,10 @@ def main(argv): p_remove_tag.add_argument('--yes', dest='autoyes', action='store_true') p_remove_tag.set_defaults(func=lambda args: add_remove_tag_argparse(args, action='remove')) + p_delete = subparsers.add_parser('delete') + p_delete.add_argument('--yes', dest='autoyes', action='store_true') + p_delete.set_defaults(func=delete_argparse) + p_digest = subparsers.add_parser('digest', aliases=['digest_directory', 'digest-directory']) p_digest.add_argument('directory') p_digest.add_argument('--no_albums', '--no-albums', dest='make_albums', action='store_false', default=True)