From e27ba0d08a0b92b6211a277df40f3b4914a11b56 Mon Sep 17 00:00:00 2001 From: palto42 <12280188+palto42@users.noreply.github.com> Date: Sat, 11 Jan 2020 16:38:07 +0100 Subject: [PATCH 1/4] less detail at v1 + option "--files" for details --- NEWS | 3 +++ borgmatic/borg/create.py | 14 ++++++++++-- borgmatic/borg/prune.py | 14 +++++++++--- borgmatic/commands/arguments.py | 14 ++++++++++++ borgmatic/commands/borgmatic.py | 2 ++ setup.py | 2 +- tests/integration/commands/test_arguments.py | 23 +++++++++++++++++++- tests/unit/borg/test_create.py | 8 +++---- tests/unit/borg/test_prune.py | 4 +--- 9 files changed, 69 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index 0e76bf0..3de4d2e 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +1.4.22.dev0-files + * Removed `borg --list --stats` option from `create`and `prune` actions at verbosity 1 + * New option `--files`to (re-)add the `borg` `--list` and `--stats` at verbosity 1 1.4.22.dev0 * #276: Disable colored output when "--json" flag is used, so as to produce valid JSON ouput. * In "borgmatic --help", don't expand $HOME in listing of default "--config" paths. diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index f582fb7..523ab6e 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -131,6 +131,7 @@ def create_archive( progress=False, stats=False, json=False, + files=False, ): ''' Given vebosity/dry-run flags, a local or remote repository path, a location config dict, and a @@ -177,13 +178,22 @@ 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 + if logger.isEnabledFor(logging.INFO) + and not json + and not progress + and (files or logger.isEnabledFor(logging.DEBUG)) else () ) + (('--info',) if logger.getEffectiveLevel() == logging.INFO and not json else ()) + ( ('--stats',) - if not dry_run and (logger.isEnabledFor(logging.INFO) or stats) and not json + if not dry_run + and ( + (logger.isEnabledFor(logging.INFO) and files) + or logger.isEnabledFor(logging.DEBUG) + or stats + ) + and not json else () ) + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) and not json else ()) diff --git a/borgmatic/borg/prune.py b/borgmatic/borg/prune.py index 2c4811e..5d8610b 100644 --- a/borgmatic/borg/prune.py +++ b/borgmatic/borg/prune.py @@ -41,6 +41,7 @@ def prune_archives( local_path='borg', remote_path=None, stats=False, + files=False, ): ''' Given dry-run flag, a local or remote repository path, a storage config dict, and a @@ -57,11 +58,18 @@ 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.isEnabledFor(logging.INFO) else ()) - + (('--info', '--list') if logger.getEffectiveLevel() == logging.INFO else ()) + + ( + ('--stats',) + if not dry_run + and (logger.isEnabledFor(logging.INFO) and files) + or logger.getEffectiveLevel() == logging.DEBUG + or stats + 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 ()) + (('--dry-run',) if dry_run else ()) - + (('--stats',) if stats else ()) + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ()) + (repository,) ) diff --git a/borgmatic/commands/arguments.py b/borgmatic/commands/arguments.py index 142c3a7..76f25a6 100644 --- a/borgmatic/commands/arguments.py +++ b/borgmatic/commands/arguments.py @@ -237,6 +237,13 @@ def parse_arguments(*unparsed_arguments): action='store_true', help='Display statistics of archive', ) + prune_group.add_argument( + '--files', + dest='files', + default=False, + action='store_true', + help='Show file details and stats at verbosity 1', + ) prune_group.add_argument('-h', '--help', action='help', help='Show this help message and exit') create_parser = subparsers.add_parser( @@ -261,6 +268,13 @@ def parse_arguments(*unparsed_arguments): action='store_true', help='Display statistics of archive', ) + create_group.add_argument( + '--files', + dest='files', + default=False, + action='store_true', + help='Show file details and stats at verbosity 1', + ) create_group.add_argument( '--json', dest='json', default=False, action='store_true', help='Output results as JSON' ) diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 5ad1431..df50bb7 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -212,6 +212,7 @@ def run_actions( local_path=local_path, remote_path=remote_path, stats=arguments['prune'].stats, + files=arguments['prune'].files, ) if 'create' in arguments: logger.info('{}: Creating archive{}'.format(repository, dry_run_label)) @@ -225,6 +226,7 @@ def run_actions( progress=arguments['create'].progress, stats=arguments['create'].stats, json=arguments['create'].json, + files=arguments['create'].files, ) if json_output: yield json.loads(json_output) diff --git a/setup.py b/setup.py index 15dfed5..293849d 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.4.22.dev0' +VERSION = '1.4.22.dev0-files' setup( diff --git a/tests/integration/commands/test_arguments.py b/tests/integration/commands/test_arguments.py index 9c5bb94..46bc380 100644 --- a/tests/integration/commands/test_arguments.py +++ b/tests/integration/commands/test_arguments.py @@ -98,12 +98,14 @@ def test_parse_arguments_with_no_actions_defaults_to_all_actions_enabled(): def test_parse_arguments_with_no_actions_passes_argument_to_relevant_actions(): flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) - arguments = module.parse_arguments('--stats') + arguments = module.parse_arguments('--stats', '--files') assert 'prune' in arguments assert arguments['prune'].stats + assert arguments['prune'].files assert 'create' in arguments assert arguments['create'].stats + assert arguments['create'].files assert 'check' in arguments @@ -423,6 +425,25 @@ def test_parse_arguments_with_stats_flag_but_no_create_or_prune_flag_raises_valu module.parse_arguments('--stats', 'list') +def test_parse_arguments_with_files_and_create_flags_does_not_raise(): + flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) + + module.parse_arguments('--files', 'create', 'list') + + +def test_parse_arguments_with_files_and_prune_flags_does_not_raise(): + flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) + + module.parse_arguments('--files', 'prune', 'list') + + +def test_parse_arguments_with_files_flag_but_no_create_or_prune_or_restore_flag_raises_value_error(): + flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) + + with pytest.raises(SystemExit): + module.parse_arguments('--files', 'list') + + def test_parse_arguments_allows_json_with_list_or_info(): flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) diff --git a/tests/unit/borg/test_create.py b/tests/unit/borg/test_create.py index f904414..5cf8bb4 100644 --- a/tests/unit/borg/test_create.py +++ b/tests/unit/borg/test_create.py @@ -295,7 +295,7 @@ def test_create_archive_with_log_info_calls_borg_with_info_parameter(): flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('execute_command').with_args( - ('borg', 'create', '--list', '--filter', 'AME-', '--info', '--stats') + ARCHIVE_WITH_PATHS, + ('borg', 'create', '--info') + ARCHIVE_WITH_PATHS, output_log_level=logging.INFO, error_on_warnings=False, ) @@ -432,8 +432,7 @@ def test_create_archive_with_dry_run_and_log_info_calls_borg_without_stats_param flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('execute_command').with_args( - ('borg', 'create', '--list', '--filter', 'AME-', '--info', '--dry-run') - + ARCHIVE_WITH_PATHS, + ('borg', 'create', '--info', '--dry-run') + ARCHIVE_WITH_PATHS, output_log_level=logging.INFO, error_on_warnings=False, ) @@ -875,8 +874,7 @@ def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_para flexmock(module).should_receive('_make_pattern_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('execute_command_without_capture').with_args( - ('borg', 'create', '--info', '--stats', '--progress') + ARCHIVE_WITH_PATHS, - error_on_warnings=False, + ('borg', 'create', '--info', '--progress') + ARCHIVE_WITH_PATHS, error_on_warnings=False ) insert_logging_mock(logging.INFO) diff --git a/tests/unit/borg/test_prune.py b/tests/unit/borg/test_prune.py index b2b4785..07ef41e 100644 --- a/tests/unit/borg/test_prune.py +++ b/tests/unit/borg/test_prune.py @@ -75,9 +75,7 @@ def test_prune_archives_with_log_info_calls_borg_with_info_parameter(): flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( BASE_PRUNE_FLAGS ) - insert_execute_command_mock( - PRUNE_COMMAND + ('--stats', '--info', '--list', 'repo'), logging.INFO - ) + insert_execute_command_mock(PRUNE_COMMAND + ('--info', 'repo'), logging.INFO) insert_logging_mock(logging.INFO) module.prune_archives( From e108526babd27fa46edb4ad49863e8b30e354e5e Mon Sep 17 00:00:00 2001 From: palto42 <12280188+palto42@users.noreply.github.com> Date: Sat, 18 Jan 2020 14:38:59 +0100 Subject: [PATCH 2/4] disable --stats by default --- borgmatic/borg/create.py | 10 ++-------- borgmatic/borg/prune.py | 9 ++++----- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index 523ab6e..09039be 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -187,13 +187,7 @@ def create_archive( + (('--info',) if logger.getEffectiveLevel() == logging.INFO and not json else ()) + ( ('--stats',) - if not dry_run - and ( - (logger.isEnabledFor(logging.INFO) and files) - or logger.isEnabledFor(logging.DEBUG) - or stats - ) - and not json + if not dry_run and (logger.isEnabledFor(logging.DEBUG) or stats) and not json else () ) + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) and not json else ()) @@ -217,7 +211,7 @@ def create_archive( if json: output_log_level = None - elif stats: + 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 5d8610b..f3f17c0 100644 --- a/borgmatic/borg/prune.py +++ b/borgmatic/borg/prune.py @@ -60,10 +60,7 @@ def prune_archives( + (('--lock-wait', str(lock_wait)) if lock_wait else ()) + ( ('--stats',) - if not dry_run - and (logger.isEnabledFor(logging.INFO) and files) - or logger.getEffectiveLevel() == logging.DEBUG - or stats + if not dry_run and logger.getEffectiveLevel() == logging.DEBUG or stats else () ) + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ()) @@ -76,6 +73,8 @@ def prune_archives( execute_command( full_command, - output_log_level=logging.WARNING if stats else logging.INFO, + output_log_level=logging.WARNING + if (stats and logger.getEffectiveLevel() == logging.WARNING) + else logging.INFO, error_on_warnings=False, ) From 83632448be386d13cff73d621bed23b023ddcc8f Mon Sep 17 00:00:00 2001 From: palto42 <12280188+palto42@users.noreply.github.com> Date: Sat, 18 Jan 2020 14:57:50 +0100 Subject: [PATCH 3/4] updated NEWS for mod. --stats & new --files opt. --- NEWS | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 3de4d2e..7d37574 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ 1.4.22.dev0-files * Removed `borg --list --stats` option from `create`and `prune` actions at verbosity 1 - * New option `--files`to (re-)add the `borg` `--list` and `--stats` at verbosity 1 + * The `--stats` now always requires to use the `borgmatic --stats` option to be enabled. + * New option `--files` to (re-)add the `borg` `--list` at verbosity 1 + 1.4.22.dev0 * #276: Disable colored output when "--json" flag is used, so as to produce valid JSON ouput. * In "borgmatic --help", don't expand $HOME in listing of default "--config" paths. 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 4/4] 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 09039be..dd383ca 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 f3f17c0..d68a12d 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 5cf8bb4..4b74df7 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 07ef41e..1694e4e 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,