From 75b5e7254eb858629087d3bcc760ce221539bfea Mon Sep 17 00:00:00 2001 From: palto42 <12280188+palto42@users.noreply.github.com> Date: Wed, 22 Jan 2020 19:03:26 +0100 Subject: [PATCH] changes as per comments in PR #283 --- borgmatic/borg/create.py | 9 ++------- borgmatic/borg/prune.py | 18 ++++-------------- tests/unit/borg/test_create.py | 2 +- tests/unit/borg/test_prune.py | 4 ++-- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index 09039bea..dd383ca2 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -178,16 +178,13 @@ def create_archive( + (('--lock-wait', str(lock_wait)) if lock_wait else ()) + ( ('--list', '--filter', 'AME-') - if logger.isEnabledFor(logging.INFO) - and not json - and not progress - and (files or logger.isEnabledFor(logging.DEBUG)) + if (files or logger.isEnabledFor(logging.DEBUG)) and not json and not progress else () ) + (('--info',) if logger.getEffectiveLevel() == logging.INFO and not json else ()) + ( ('--stats',) - if not dry_run and (logger.isEnabledFor(logging.DEBUG) or stats) and not json + if (stats or logger.isEnabledFor(logging.DEBUG)) and not json and not dry_run else () ) + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) and not json else ()) @@ -211,8 +208,6 @@ def create_archive( if json: output_log_level = None - elif stats and logger.getEffectiveLevel() == logging.WARNING: - output_log_level = logging.WARNING else: output_log_level = logging.INFO diff --git a/borgmatic/borg/prune.py b/borgmatic/borg/prune.py index f3f17c0c..d68a12d3 100644 --- a/borgmatic/borg/prune.py +++ b/borgmatic/borg/prune.py @@ -58,23 +58,13 @@ def prune_archives( + (('--remote-path', remote_path) if remote_path else ()) + (('--umask', str(umask)) if umask else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ()) - + ( - ('--stats',) - if not dry_run and logger.getEffectiveLevel() == logging.DEBUG or stats - else () - ) + + (('--stats',) if (stats or logger.isEnabledFor(logging.DEBUG)) and not dry_run else ()) + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ()) - + (('--list',) if logger.getEffectiveLevel() == logging.INFO and files else ()) - + (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + + (('--list',) if files or logger.isEnabledFor(logging.DEBUG) else ()) + + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) + (('--dry-run',) if dry_run else ()) + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ()) + (repository,) ) - execute_command( - full_command, - output_log_level=logging.WARNING - if (stats and logger.getEffectiveLevel() == logging.WARNING) - else logging.INFO, - error_on_warnings=False, - ) + execute_command(full_command, output_log_level=logging.INFO, error_on_warnings=False) diff --git a/tests/unit/borg/test_create.py b/tests/unit/borg/test_create.py index 5cf8bb45..4b74df76 100644 --- a/tests/unit/borg/test_create.py +++ b/tests/unit/borg/test_create.py @@ -849,7 +849,7 @@ def test_create_archive_with_stats_calls_borg_with_stats_parameter(): flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('execute_command').with_args( ('borg', 'create', '--stats') + ARCHIVE_WITH_PATHS, - output_log_level=logging.WARNING, + output_log_level=logging.INFO, error_on_warnings=False, ) diff --git a/tests/unit/borg/test_prune.py b/tests/unit/borg/test_prune.py index 07ef41ec..1694e4e8 100644 --- a/tests/unit/borg/test_prune.py +++ b/tests/unit/borg/test_prune.py @@ -89,7 +89,7 @@ def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter(): BASE_PRUNE_FLAGS ) insert_execute_command_mock( - PRUNE_COMMAND + ('--stats', '--debug', '--list', '--show-rc', 'repo'), logging.INFO + PRUNE_COMMAND + ('--stats', '--list', '--debug', '--show-rc', 'repo'), logging.INFO ) insert_logging_mock(logging.DEBUG) @@ -147,7 +147,7 @@ def test_prune_archives_with_stats_calls_borg_with_stats_parameter(): flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( BASE_PRUNE_FLAGS ) - insert_execute_command_mock(PRUNE_COMMAND + ('--stats', 'repo'), logging.WARNING) + insert_execute_command_mock(PRUNE_COMMAND + ('--stats', 'repo'), logging.INFO) module.prune_archives( dry_run=False,