""" Add a file to the database """ import click import os from app.models.sql_factory import search_by_phash, add_phash from app.utils.im_utils import compute_phash_int from app.utils.file_utils import sha256 @click.command() @click.option('-i', '--input', 'opt_fn', required=True, help="File to add (gif/jpg/png)") @click.option('-u', '--upload', 'opt_upload', is_flag=True, help='Whether to upload this file to S3') @click.pass_context def cli(ctx, opt_fn, opt_upload): """ Add a single file """ print('Adding a file...') if not os.path.exists(opt_fn): print("File does not exist") return hash = sha256(opt_fn) phash = compute_phash_int(opt_fn) dir, fn = os.path.split(opt_fn) root, ext = os.path.splitext(fn) add_phash(sha256=hash, phash=phash, ext=ext)