Disable per-file logging by default at verbosity 1; opt-in via new --files option.

This commit is contained in:
Dan Helfman 2020-01-22 20:36:59 +00:00 committed by Gitea
commit 58e0439daf
8 changed files with 57 additions and 25 deletions

3
NEWS
View file

@ -1,5 +1,8 @@
1.4.23.dev0 1.4.23.dev0
* #274: Add ~/.config/borgmatic.d as another configuration directory default. * #274: Add ~/.config/borgmatic.d as another configuration directory default.
* Removed `borg --list --stats` option from `create`and `prune` actions 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 1.4.22
* #276, #285: Disable colored output when "--json" flag is used, so as to produce valid JSON ouput. * #276, #285: Disable colored output when "--json" flag is used, so as to produce valid JSON ouput.

View file

@ -131,6 +131,7 @@ def create_archive(
progress=False, progress=False,
stats=False, stats=False,
json=False, json=False,
files=False,
): ):
''' '''
Given vebosity/dry-run flags, a local or remote repository path, a location config dict, and a Given vebosity/dry-run flags, a local or remote repository path, a location config dict, and a
@ -177,13 +178,13 @@ def create_archive(
+ (('--lock-wait', str(lock_wait)) if lock_wait else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ())
+ ( + (
('--list', '--filter', 'AME-') ('--list', '--filter', 'AME-')
if logger.isEnabledFor(logging.INFO) and not json and not progress if (files or logger.isEnabledFor(logging.DEBUG)) and not json and not progress
else () else ()
) )
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO and not json else ()) + (('--info',) if logger.getEffectiveLevel() == logging.INFO and not json else ())
+ ( + (
('--stats',) ('--stats',)
if not dry_run and (logger.isEnabledFor(logging.INFO) or stats) and not json if (stats or logger.isEnabledFor(logging.DEBUG)) and not json and not dry_run
else () else ()
) )
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) and not json else ()) + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) and not json else ())
@ -207,8 +208,6 @@ def create_archive(
if json: if json:
output_log_level = None output_log_level = None
elif stats:
output_log_level = logging.WARNING
else: else:
output_log_level = logging.INFO output_log_level = logging.INFO

View file

@ -41,6 +41,7 @@ def prune_archives(
local_path='borg', local_path='borg',
remote_path=None, remote_path=None,
stats=False, stats=False,
files=False,
): ):
''' '''
Given dry-run flag, a local or remote repository path, a storage config dict, and a Given dry-run flag, a local or remote repository path, a storage config dict, and a
@ -57,17 +58,13 @@ def prune_archives(
+ (('--remote-path', remote_path) if remote_path else ()) + (('--remote-path', remote_path) if remote_path else ())
+ (('--umask', str(umask)) if umask else ()) + (('--umask', str(umask)) if umask else ())
+ (('--lock-wait', str(lock_wait)) if lock_wait else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ())
+ (('--stats',) if not dry_run and logger.isEnabledFor(logging.INFO) else ()) + (('--stats',) if (stats or logger.isEnabledFor(logging.DEBUG)) and not dry_run else ())
+ (('--info', '--list') if logger.getEffectiveLevel() == logging.INFO else ()) + (('--info',) if logger.getEffectiveLevel() == logging.INFO 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 ()) + (('--dry-run',) if dry_run else ())
+ (('--stats',) if stats else ())
+ (tuple(extra_borg_options.split(' ')) if extra_borg_options else ()) + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
+ (repository,) + (repository,)
) )
execute_command( execute_command(full_command, output_log_level=logging.INFO, error_on_warnings=False)
full_command,
output_log_level=logging.WARNING if stats else logging.INFO,
error_on_warnings=False,
)

View file

@ -237,6 +237,13 @@ def parse_arguments(*unparsed_arguments):
action='store_true', action='store_true',
help='Display statistics of archive', 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') prune_group.add_argument('-h', '--help', action='help', help='Show this help message and exit')
create_parser = subparsers.add_parser( create_parser = subparsers.add_parser(
@ -261,6 +268,13 @@ def parse_arguments(*unparsed_arguments):
action='store_true', action='store_true',
help='Display statistics of archive', 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( create_group.add_argument(
'--json', dest='json', default=False, action='store_true', help='Output results as JSON' '--json', dest='json', default=False, action='store_true', help='Output results as JSON'
) )

View file

@ -212,6 +212,7 @@ def run_actions(
local_path=local_path, local_path=local_path,
remote_path=remote_path, remote_path=remote_path,
stats=arguments['prune'].stats, stats=arguments['prune'].stats,
files=arguments['prune'].files,
) )
if 'create' in arguments: if 'create' in arguments:
logger.info('{}: Creating archive{}'.format(repository, dry_run_label)) logger.info('{}: Creating archive{}'.format(repository, dry_run_label))
@ -225,6 +226,7 @@ def run_actions(
progress=arguments['create'].progress, progress=arguments['create'].progress,
stats=arguments['create'].stats, stats=arguments['create'].stats,
json=arguments['create'].json, json=arguments['create'].json,
files=arguments['create'].files,
) )
if json_output: if json_output:
yield json.loads(json_output) yield json.loads(json_output)

View file

@ -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(): def test_parse_arguments_with_no_actions_passes_argument_to_relevant_actions():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) 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 'prune' in arguments
assert arguments['prune'].stats assert arguments['prune'].stats
assert arguments['prune'].files
assert 'create' in arguments assert 'create' in arguments
assert arguments['create'].stats assert arguments['create'].stats
assert arguments['create'].files
assert 'check' in arguments 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') 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(): def test_parse_arguments_allows_json_with_list_or_info():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])

View file

@ -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_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( 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, output_log_level=logging.INFO,
error_on_warnings=False, 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_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
('borg', 'create', '--list', '--filter', 'AME-', '--info', '--dry-run') ('borg', 'create', '--info', '--dry-run') + ARCHIVE_WITH_PATHS,
+ ARCHIVE_WITH_PATHS,
output_log_level=logging.INFO, output_log_level=logging.INFO,
error_on_warnings=False, error_on_warnings=False,
) )
@ -850,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('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command').with_args( flexmock(module).should_receive('execute_command').with_args(
('borg', 'create', '--stats') + ARCHIVE_WITH_PATHS, ('borg', 'create', '--stats') + ARCHIVE_WITH_PATHS,
output_log_level=logging.WARNING, output_log_level=logging.INFO,
error_on_warnings=False, 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_pattern_flags').and_return(())
flexmock(module).should_receive('_make_exclude_flags').and_return(()) flexmock(module).should_receive('_make_exclude_flags').and_return(())
flexmock(module).should_receive('execute_command_without_capture').with_args( flexmock(module).should_receive('execute_command_without_capture').with_args(
('borg', 'create', '--info', '--stats', '--progress') + ARCHIVE_WITH_PATHS, ('borg', 'create', '--info', '--progress') + ARCHIVE_WITH_PATHS, error_on_warnings=False
error_on_warnings=False,
) )
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)

View file

@ -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( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS BASE_PRUNE_FLAGS
) )
insert_execute_command_mock( insert_execute_command_mock(PRUNE_COMMAND + ('--info', 'repo'), logging.INFO)
PRUNE_COMMAND + ('--stats', '--info', '--list', 'repo'), logging.INFO
)
insert_logging_mock(logging.INFO) insert_logging_mock(logging.INFO)
module.prune_archives( module.prune_archives(
@ -91,7 +89,7 @@ def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter():
BASE_PRUNE_FLAGS BASE_PRUNE_FLAGS
) )
insert_execute_command_mock( 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) insert_logging_mock(logging.DEBUG)
@ -149,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( flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
BASE_PRUNE_FLAGS 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( module.prune_archives(
dry_run=False, dry_run=False,