Add --debug option for command line to override value in constants.py. #153 (#217)

This commit is contained in:
Jaisen Mathai 2017-05-11 23:43:16 -07:00 committed by GitHub
parent a6b805207b
commit bb2b0496f7
2 changed files with 33 additions and 6 deletions

View File

@ -83,10 +83,13 @@ def import_file(_file, destination, album_from_folder, trash, allow_duplicates):
help='After copying files, move the old files to the trash.') help='After copying files, move the old files to the trash.')
@click.option('--allow-duplicates', default=False, is_flag=True, @click.option('--allow-duplicates', default=False, is_flag=True,
help='Import the file even if it\'s already been imported.') help='Import the file even if it\'s already been imported.')
@click.option('--debug', default=False, is_flag=True,
help='Override the value in constants.py with True.')
@click.argument('paths', nargs=-1, type=click.Path()) @click.argument('paths', nargs=-1, type=click.Path())
def _import(destination, source, file, album_from_folder, trash, paths, allow_duplicates): def _import(destination, source, file, album_from_folder, trash, allow_duplicates, debug, paths):
"""Import files or directories by reading their EXIF and organizing them accordingly. """Import files or directories by reading their EXIF and organizing them accordingly.
""" """
constants.debug = debug
has_errors = False has_errors = False
result = Result() result = Result()
@ -122,9 +125,12 @@ def _import(destination, source, file, album_from_folder, trash, paths, allow_du
@click.command('generate-db') @click.command('generate-db')
@click.option('--source', type=click.Path(file_okay=False), @click.option('--source', type=click.Path(file_okay=False),
required=True, help='Source of your photo library.') required=True, help='Source of your photo library.')
def _generate_db(source): @click.option('--debug', default=False, is_flag=True,
help='Override the value in constants.py with True.')
def _generate_db(source, debug):
"""Regenerate the hash.json database which contains all of the sha1 signatures of media files. """Regenerate the hash.json database which contains all of the sha1 signatures of media files.
""" """
constants.debug = debug
result = Result() result = Result()
source = os.path.abspath(os.path.expanduser(source)) source = os.path.abspath(os.path.expanduser(source))
@ -146,7 +152,10 @@ def _generate_db(source):
result.write() result.write()
@click.command('verify') @click.command('verify')
def _verify(): @click.option('--debug', default=False, is_flag=True,
help='Override the value in constants.py with True.')
def _verify(debug):
constants.debug = debug
result = Result() result = Result()
db = Db() db = Db()
for checksum, file_path in db.all(): for checksum, file_path in db.all():
@ -209,11 +218,14 @@ def update_time(media, file_path, time_string):
@click.option('--time', help=('Update the image time. Time should be in ' @click.option('--time', help=('Update the image time. Time should be in '
'YYYY-mm-dd hh:ii:ss or YYYY-mm-dd format.')) 'YYYY-mm-dd hh:ii:ss or YYYY-mm-dd format.'))
@click.option('--title', help='Update the image title.') @click.option('--title', help='Update the image title.')
@click.option('--debug', default=False, is_flag=True,
help='Override the value in constants.py with True.')
@click.argument('paths', nargs=-1, @click.argument('paths', nargs=-1,
required=True) required=True)
def _update(album, location, time, title, paths): def _update(album, location, time, title, paths, debug):
"""Update a file's EXIF. Automatically modifies the file's location and file name accordingly. """Update a file's EXIF. Automatically modifies the file's location and file name accordingly.
""" """
constants.debug = debug
has_errors = False has_errors = False
result = Result() result = Result()
@ -229,8 +241,7 @@ def _update(album, location, time, title, paths):
if not os.path.exists(current_file): if not os.path.exists(current_file):
has_errors = True has_errors = True
result.append((current_file, False)) result.append((current_file, False))
if constants.debug: log.warn('Could not find %s' % current_file)
print('Could not find %s' % current_file)
print('{"source":"%s", "error_msg":"Could not find %s"}' % \ print('{"source":"%s", "error_msg":"Could not find %s"}' % \
(current_file, current_file)) (current_file, current_file))
continue continue

View File

@ -550,3 +550,19 @@ def test_verify_error():
assert origin in result.output, result.output assert origin in result.output, result.output
assert 'Error 1' in result.output, result.output assert 'Error 1' in result.output, result.output
def test_cli_debug_import():
runner = CliRunner()
# import
result = runner.invoke(elodie._import, ['--destination', '/does/not/exist', '/does/not/exist'])
assert "Could not find /does/not/exist\n" not in result.output, result.output
result = runner.invoke(elodie._import, ['--destination', '/does/not/exist', '--debug', '/does/not/exist'])
assert "Could not find /does/not/exist\n" in result.output, result.output
def test_cli_debug_update():
runner = CliRunner()
# update
result = runner.invoke(elodie._update, ['--location', 'foobar', '/does/not/exist'])
assert "Could not find /does/not/exist\n" not in result.output, result.output
result = runner.invoke(elodie._update, ['--location', 'foobar', '--debug', '/does/not/exist'])
assert "Could not find /does/not/exist\n" in result.output, result.output