Add cli command new_photo.
This commit is contained in:
parent
b52e79f99c
commit
97e14b9917
1 changed files with 81 additions and 0 deletions
|
@ -7,12 +7,15 @@ from voussoirkit import betterhelp
|
||||||
from voussoirkit import interactive
|
from voussoirkit import interactive
|
||||||
from voussoirkit import pathclass
|
from voussoirkit import pathclass
|
||||||
from voussoirkit import pipeable
|
from voussoirkit import pipeable
|
||||||
|
from voussoirkit import ratelimiter
|
||||||
from voussoirkit import spinal
|
from voussoirkit import spinal
|
||||||
from voussoirkit import stringtools
|
from voussoirkit import stringtools
|
||||||
from voussoirkit import vlogging
|
from voussoirkit import vlogging
|
||||||
|
|
||||||
import etiquette
|
import etiquette
|
||||||
|
|
||||||
|
log = vlogging.get_logger(__name__, 'etiquette_cli')
|
||||||
|
|
||||||
photodb = None
|
photodb = None
|
||||||
def load_photodb():
|
def load_photodb():
|
||||||
global photodb
|
global photodb
|
||||||
|
@ -364,6 +367,40 @@ def init_argparse(args):
|
||||||
photodb = etiquette.photodb.PhotoDB(create=True)
|
photodb = etiquette.photodb.PhotoDB(create=True)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def new_photo_argparse(args):
|
||||||
|
load_photodb()
|
||||||
|
|
||||||
|
limiter = ratelimiter.Ratelimiter(allowance=1, period=args.ratelimit)
|
||||||
|
need_commit = False
|
||||||
|
|
||||||
|
with photodb.transaction:
|
||||||
|
photos = []
|
||||||
|
for file in pathclass.glob_many_files(args.globs):
|
||||||
|
try:
|
||||||
|
exists = photodb.get_photo_by_path(file)
|
||||||
|
log.info('%s exists.', file.absolute_path)
|
||||||
|
continue
|
||||||
|
except etiquette.exceptions.NoSuchPhoto:
|
||||||
|
pass
|
||||||
|
limiter.limit()
|
||||||
|
photo = photodb.new_photo(file)
|
||||||
|
photos.append(photo)
|
||||||
|
need_commit = True
|
||||||
|
|
||||||
|
if not need_commit:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if args.make_album or args.album_title:
|
||||||
|
album_title = args.album_title or None
|
||||||
|
album = photodb.new_album(title=album_title)
|
||||||
|
album.add_photos(photos)
|
||||||
|
|
||||||
|
if not (args.autoyes or interactive.getpermission('Commit?')):
|
||||||
|
photodb.rollback()
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
def purge_deleted_files_argparse(args):
|
def purge_deleted_files_argparse(args):
|
||||||
load_photodb()
|
load_photodb()
|
||||||
|
|
||||||
|
@ -1075,6 +1112,50 @@ def main(argv):
|
||||||
|
|
||||||
################################################################################################
|
################################################################################################
|
||||||
|
|
||||||
|
p_new_photo = subparsers.add_parser(
|
||||||
|
'new_photo',
|
||||||
|
aliases=['new-photo', 'new_photos', 'new-photos'],
|
||||||
|
description='''
|
||||||
|
''',
|
||||||
|
)
|
||||||
|
p_new_photo.add_argument(
|
||||||
|
'globs',
|
||||||
|
nargs='+',
|
||||||
|
help='''
|
||||||
|
Make Photos from files that match glob patterns.
|
||||||
|
''',
|
||||||
|
)
|
||||||
|
p_new_photo.add_argument(
|
||||||
|
'--ratelimit',
|
||||||
|
type=float,
|
||||||
|
default=0.25,
|
||||||
|
help='''
|
||||||
|
''',
|
||||||
|
)
|
||||||
|
p_new_photo.add_argument(
|
||||||
|
'--make_album', '--make-album',
|
||||||
|
action='store_true',
|
||||||
|
help='''
|
||||||
|
''',
|
||||||
|
)
|
||||||
|
p_new_photo.add_argument(
|
||||||
|
'--album_title', '--album-title',
|
||||||
|
default=None,
|
||||||
|
help='''
|
||||||
|
''',
|
||||||
|
)
|
||||||
|
p_new_photo.add_argument(
|
||||||
|
'--yes',
|
||||||
|
dest='autoyes',
|
||||||
|
action='store_true',
|
||||||
|
help='''
|
||||||
|
Commit the database without prompting.
|
||||||
|
''',
|
||||||
|
)
|
||||||
|
p_new_photo.set_defaults(func=new_photo_argparse)
|
||||||
|
|
||||||
|
################################################################################################
|
||||||
|
|
||||||
p_purge_deleted_files = subparsers.add_parser(
|
p_purge_deleted_files = subparsers.add_parser(
|
||||||
'purge_deleted_files',
|
'purge_deleted_files',
|
||||||
aliases=['purge-deleted-files'],
|
aliases=['purge-deleted-files'],
|
||||||
|
|
Loading…
Reference in a new issue