Change command line options for log levels
This commit is contained in:
parent
b7435c4eac
commit
836792429f
|
@ -12,11 +12,26 @@ from ordigi.geolocation import GeoLocation
|
|||
from ordigi import utils
|
||||
|
||||
_logger_options = [
|
||||
click.option(
|
||||
'--quiet',
|
||||
'-q',
|
||||
default=False,
|
||||
is_flag=True,
|
||||
help='Log level set to ERROR',
|
||||
),
|
||||
click.option(
|
||||
'--verbose',
|
||||
'-v',
|
||||
default='WARNING',
|
||||
help='Log level [WARNING,INFO,DEBUG,NOTSET]',
|
||||
default=False,
|
||||
is_flag=True,
|
||||
help='Log level set to INFO',
|
||||
),
|
||||
click.option(
|
||||
'--debug',
|
||||
'-d',
|
||||
default=False,
|
||||
is_flag=True,
|
||||
help='Log level set to DEBUG',
|
||||
),
|
||||
]
|
||||
|
||||
|
@ -168,7 +183,7 @@ def _check(**kwargs):
|
|||
"""
|
||||
root = Path(kwargs['path']).expanduser().absolute()
|
||||
|
||||
log_level = log.get_level(kwargs['verbose'])
|
||||
log_level = log.get_level(kwargs['quiet'], kwargs['verbose'], kwargs['debug'])
|
||||
log.console(LOG, level=log_level)
|
||||
|
||||
collection = Collection(root)
|
||||
|
@ -191,7 +206,7 @@ def _check(**kwargs):
|
|||
@add_options(_filter_options)
|
||||
@click.option(
|
||||
'--dedup-regex',
|
||||
'-d',
|
||||
'-D',
|
||||
default=None,
|
||||
multiple=True,
|
||||
help='Regex to match duplicate strings parts',
|
||||
|
@ -218,7 +233,7 @@ def _clean(**kwargs):
|
|||
"""Clean media collection"""
|
||||
|
||||
folders = kwargs['folders']
|
||||
log_level = log.get_level(kwargs['verbose'])
|
||||
log_level = log.get_level(kwargs['quiet'], kwargs['verbose'], kwargs['debug'])
|
||||
log.console(LOG, level=log_level)
|
||||
|
||||
subdirs = kwargs['subdirs']
|
||||
|
@ -268,7 +283,7 @@ def _clean(**kwargs):
|
|||
def _clone(**kwargs):
|
||||
"""Clone media collection to another location"""
|
||||
|
||||
log_level = log.get_level(kwargs['verbose'])
|
||||
log_level = log.get_level(kwargs['quiet'], kwargs['verbose'], kwargs['debug'])
|
||||
log.console(LOG, level=log_level)
|
||||
|
||||
src_path = Path(kwargs['src']).expanduser().absolute()
|
||||
|
@ -321,7 +336,7 @@ def _compare(**kwargs):
|
|||
subdirs = kwargs['subdirs']
|
||||
root = kwargs['collection']
|
||||
|
||||
log_level = log.get_level(kwargs['verbose'])
|
||||
log_level = log.get_level(kwargs['quiet'], kwargs['verbose'], kwargs['debug'])
|
||||
log.console(LOG, level=log_level)
|
||||
paths, root = _get_paths(subdirs, root)
|
||||
|
||||
|
@ -370,7 +385,7 @@ def _compare(**kwargs):
|
|||
def _edit(**kwargs):
|
||||
"""Edit EXIF metadata in files or directories"""
|
||||
|
||||
log_level = log.get_level(kwargs['verbose'])
|
||||
log_level = log.get_level(kwargs['quiet'], kwargs['verbose'], kwargs['debug'])
|
||||
log.console(LOG, level=log_level)
|
||||
|
||||
paths, root = _get_paths(kwargs['subdirs'], kwargs['path'])
|
||||
|
@ -454,7 +469,7 @@ def _init(**kwargs):
|
|||
Init media collection database.
|
||||
"""
|
||||
root = Path(kwargs['path']).expanduser().absolute()
|
||||
log_level = log.get_level(kwargs['verbose'])
|
||||
log_level = log.get_level(kwargs['quiet'], kwargs['verbose'], kwargs['debug'])
|
||||
log.console(LOG, level=log_level)
|
||||
|
||||
collection = Collection(root)
|
||||
|
@ -491,7 +506,7 @@ def _import(**kwargs):
|
|||
"""Sort files or directories by reading their EXIF and organizing them
|
||||
according to ordigi.conf preferences.
|
||||
"""
|
||||
log_level = log.get_level(kwargs['verbose'])
|
||||
log_level = log.get_level(kwargs['quiet'], kwargs['verbose'], kwargs['debug'])
|
||||
log.console(LOG, level=log_level)
|
||||
|
||||
src_paths, root = _get_paths(kwargs['src'], kwargs['dest'])
|
||||
|
@ -547,7 +562,7 @@ def _sort(**kwargs):
|
|||
"""Sort files or directories by reading their EXIF and organizing them
|
||||
according to ordigi.conf preferences.
|
||||
"""
|
||||
log_level = log.get_level(kwargs['verbose'])
|
||||
log_level = log.get_level(kwargs['quiet'], kwargs['verbose'], kwargs['debug'])
|
||||
log.console(LOG, level=log_level)
|
||||
|
||||
paths, root = _get_paths(kwargs['subdirs'], kwargs['dest'])
|
||||
|
@ -598,7 +613,7 @@ def _update(**kwargs):
|
|||
Update media collection database.
|
||||
"""
|
||||
root = Path(kwargs['path']).expanduser().absolute()
|
||||
log_level = log.get_level(kwargs['verbose'])
|
||||
log_level = log.get_level(kwargs['quiet'], kwargs['verbose'], kwargs['debug'])
|
||||
log.console(LOG, level=log_level)
|
||||
|
||||
collection = Collection(root)
|
||||
|
|
|
@ -46,9 +46,16 @@ def file_logger(logger, file, level=30):
|
|||
logger.addHandler(handler)
|
||||
|
||||
|
||||
def get_level(verbose):
|
||||
"""Return int logging level from string"""
|
||||
if verbose.isnumeric():
|
||||
def get_level(quiet=False, verbose=False, debug=False, num=None):
|
||||
"""Return int logging level from command line args"""
|
||||
if num and num.isnumeric():
|
||||
return int(verbose)
|
||||
|
||||
return int(logging.getLevelName(verbose))
|
||||
if debug:
|
||||
return int(logging.getLevelName('DEBUG'))
|
||||
if verbose:
|
||||
return int(logging.getLevelName('INFO'))
|
||||
if quiet:
|
||||
return int(logging.getLevelName('ERROR'))
|
||||
|
||||
return int(logging.getLevelName('WARNING'))
|
||||
|
|
|
@ -27,7 +27,7 @@ class TestOrdigi:
|
|||
def setup_class(cls, sample_files_paths):
|
||||
cls.runner = CliRunner()
|
||||
cls.src_path, cls.file_paths = sample_files_paths
|
||||
cls.logger_options = (('--verbose', 'DEBUG'),)
|
||||
cls.logger_options = ('--debug',)
|
||||
cls.filter_options = (
|
||||
('--ignore-tags', 'CreateDate'),
|
||||
('--ext', 'jpg'),
|
||||
|
@ -82,10 +82,11 @@ class TestOrdigi:
|
|||
|
||||
def test_edit(self, monkeypatch):
|
||||
|
||||
bool_options = ()
|
||||
bool_options = (
|
||||
*self.logger_options,
|
||||
)
|
||||
|
||||
arg_options = (
|
||||
*self.logger_options,
|
||||
*self.filter_options,
|
||||
)
|
||||
|
||||
|
@ -109,6 +110,7 @@ class TestOrdigi:
|
|||
|
||||
def test_sort(self):
|
||||
bool_options = (
|
||||
*self.logger_options,
|
||||
# '--interactive',
|
||||
'--dry-run',
|
||||
'--album-from-folder',
|
||||
|
@ -119,7 +121,6 @@ class TestOrdigi:
|
|||
)
|
||||
|
||||
arg_options = (
|
||||
*self.logger_options,
|
||||
*self.filter_options,
|
||||
('--path-format', '{%Y}/{folder}/{name}.{ext}'),
|
||||
|
||||
|
@ -134,36 +135,29 @@ class TestOrdigi:
|
|||
|
||||
def test_clone(self, tmp_path):
|
||||
|
||||
arg_options = (
|
||||
*self.logger_options,
|
||||
|
||||
)
|
||||
|
||||
paths = (str(self.src_path), str(tmp_path))
|
||||
|
||||
self.assert_cli(cli._init, [str(self.src_path)])
|
||||
self.assert_cli(cli._clone, ['--dry-run', '--verbose', 'DEBUG', *paths])
|
||||
self.assert_cli(cli._clone, ['--dry-run', *self.logger_options, *paths])
|
||||
self.assert_cli(cli._clone, paths)
|
||||
|
||||
|
||||
def assert_init(self):
|
||||
for opt, arg in self.logger_options:
|
||||
self.assert_cli(cli._init, [opt, arg, str(self.src_path)])
|
||||
self.assert_cli(cli._init, [*self.logger_options, str(self.src_path)])
|
||||
|
||||
def assert_update(self):
|
||||
file_path = Path(ORDIGI_PATH, 'samples/test_exif/photo.cr2')
|
||||
dest_path = self.src_path / 'photo_moved.cr2'
|
||||
shutil.copyfile(file_path, dest_path)
|
||||
for opt, arg in self.logger_options:
|
||||
self.assert_cli(cli._update, [opt, arg, str(self.src_path)])
|
||||
self.assert_cli(cli._update, [*self.logger_options, str(self.src_path)])
|
||||
self.assert_cli(cli._update, ['--checksum', str(self.src_path)])
|
||||
|
||||
def assert_check(self):
|
||||
for opt, arg in self.logger_options:
|
||||
self.assert_cli(cli._check, [opt, arg, str(self.src_path)])
|
||||
self.assert_cli(cli._check, [*self.logger_options, str(self.src_path)])
|
||||
|
||||
def assert_clean(self):
|
||||
bool_options = (
|
||||
*self.logger_options,
|
||||
# '--interactive',
|
||||
'--dry-run',
|
||||
'--delete-excluded',
|
||||
|
@ -173,7 +167,6 @@ class TestOrdigi:
|
|||
)
|
||||
|
||||
arg_options = (
|
||||
*self.logger_options,
|
||||
*self.filter_options,
|
||||
('--dedup-regex', r'\d{4}-\d{2}'),
|
||||
)
|
||||
|
@ -194,6 +187,7 @@ class TestOrdigi:
|
|||
|
||||
def test_import(self, tmp_path):
|
||||
bool_options = (
|
||||
*self.logger_options,
|
||||
# '--interactive',
|
||||
'--dry-run',
|
||||
'--album-from-folder',
|
||||
|
@ -204,7 +198,6 @@ class TestOrdigi:
|
|||
)
|
||||
|
||||
arg_options = (
|
||||
*self.logger_options,
|
||||
('--exclude', '.DS_Store'),
|
||||
*self.filter_options,
|
||||
('--path-format', '{%Y}/{folder}/{stem}.{ext}'),
|
||||
|
@ -220,6 +213,7 @@ class TestOrdigi:
|
|||
|
||||
def test_compare(self):
|
||||
bool_options = (
|
||||
*self.logger_options,
|
||||
# '--interactive',
|
||||
'--dry-run',
|
||||
'--find-duplicates',
|
||||
|
@ -227,7 +221,6 @@ class TestOrdigi:
|
|||
)
|
||||
|
||||
arg_options = (
|
||||
*self.logger_options,
|
||||
*self.filter_options,
|
||||
# ('--similar-to', ''),
|
||||
('--similarity', '65'),
|
||||
|
|
Loading…
Reference in New Issue