From 18d3542fbc80eb50afb32ef00c2effd1949e0fa3 Mon Sep 17 00:00:00 2001 From: palto42 <12280188+palto42@users.noreply.github.com> Date: Sun, 3 Nov 2019 09:55:19 +0100 Subject: [PATCH] new verbosity level "-1" for errors --- borgmatic/commands/arguments.py | 14 +++++++------- borgmatic/verbosity.py | 2 ++ tests/integration/commands/test_arguments.py | 17 +++++++++++++++++ tests/unit/test_verbosity.py | 1 + 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/borgmatic/commands/arguments.py b/borgmatic/commands/arguments.py index 92b3752..dd5cbeb 100644 --- a/borgmatic/commands/arguments.py +++ b/borgmatic/commands/arguments.py @@ -138,23 +138,23 @@ def parse_arguments(*unparsed_arguments): '-v', '--verbosity', type=int, - choices=range(0, 3), + choices=range(-1, 3), default=0, - help='Display verbose progress to the console (from none to lots: 0, 1, or 2)', + help='Display verbose progress to the console (from none to lots: 0, 1, or 2) or only errors (-1)', ) global_group.add_argument( '--syslog-verbosity', type=int, - choices=range(0, 3), + choices=range(-1, 3), default=0, - help='Log verbose progress to syslog (from none to lots: 0, 1, or 2). Ignored when console is interactive or --log-file is given', + help='Log verbose progress to syslog (from none to lots: 0, 1, or 2) or only errors (-1). Ignored when console is interactive or --log-file is given', ) global_group.add_argument( '--log-file-verbosity', type=int, - choices=range(0, 3), - default=1, - help='Log verbose progress to log file (from none to lots: 0, 1, or 2). Only used when --log-file is given', + choices=range(-1, 3), + default=0, + help='Log verbose progress to log file (from none to lots: 0, 1, or 2) or only errors (-1). Only used when --log-file is given', ) global_group.add_argument( '--log-file', diff --git a/borgmatic/verbosity.py b/borgmatic/verbosity.py index 300f644..effa3ae 100644 --- a/borgmatic/verbosity.py +++ b/borgmatic/verbosity.py @@ -1,5 +1,6 @@ import logging +VERBOSITY_ERROR = -1 VERBOSITY_WARNING = 0 VERBOSITY_SOME = 1 VERBOSITY_LOTS = 2 @@ -10,6 +11,7 @@ def verbosity_to_log_level(verbosity): Given a borgmatic verbosity value, return the corresponding Python log level. ''' return { + VERBOSITY_ERROR: logging.ERROR, VERBOSITY_WARNING: logging.WARNING, VERBOSITY_SOME: logging.INFO, VERBOSITY_LOTS: logging.DEBUG, diff --git a/tests/integration/commands/test_arguments.py b/tests/integration/commands/test_arguments.py index 527da05..46203d5 100644 --- a/tests/integration/commands/test_arguments.py +++ b/tests/integration/commands/test_arguments.py @@ -15,6 +15,7 @@ def test_parse_arguments_with_no_arguments_uses_defaults(): assert global_arguments.excludes_filename is None assert global_arguments.verbosity == 0 assert global_arguments.syslog_verbosity == 0 + assert global_arguments.log_file_verbosity == 0 def test_parse_arguments_with_multiple_config_paths_parses_as_list(): @@ -26,6 +27,7 @@ def test_parse_arguments_with_multiple_config_paths_parses_as_list(): assert global_arguments.config_paths == ['myconfig', 'otherconfig'] assert global_arguments.verbosity == 0 assert global_arguments.syslog_verbosity == 0 + assert global_arguments.log_file_verbosity == 0 def test_parse_arguments_with_verbosity_overrides_default(): @@ -39,6 +41,7 @@ def test_parse_arguments_with_verbosity_overrides_default(): assert global_arguments.excludes_filename is None assert global_arguments.verbosity == 1 assert global_arguments.syslog_verbosity == 0 + assert global_arguments.log_file_verbosity == 0 def test_parse_arguments_with_syslog_verbosity_overrides_default(): @@ -54,6 +57,20 @@ def test_parse_arguments_with_syslog_verbosity_overrides_default(): assert global_arguments.syslog_verbosity == 2 +def test_parse_arguments_with_log_file_verbosity_overrides_default(): + config_paths = ['default'] + flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths) + + arguments = module.parse_arguments('--log-file-verbosity', '-1') + + global_arguments = arguments['global'] + assert global_arguments.config_paths == config_paths + assert global_arguments.excludes_filename is None + assert global_arguments.verbosity == 0 + assert global_arguments.syslog_verbosity == 0 + assert global_arguments.log_file_verbosity == -1 + + def test_parse_arguments_with_list_json_overrides_default(): arguments = module.parse_arguments('list', '--json') diff --git a/tests/unit/test_verbosity.py b/tests/unit/test_verbosity.py index 9069caa..4392c87 100644 --- a/tests/unit/test_verbosity.py +++ b/tests/unit/test_verbosity.py @@ -17,6 +17,7 @@ def insert_logging_mock(log_level): def test_verbosity_to_log_level_maps_known_verbosity_to_log_level(): assert module.verbosity_to_log_level(module.VERBOSITY_SOME) == logging.INFO assert module.verbosity_to_log_level(module.VERBOSITY_LOTS) == logging.DEBUG + assert module.verbosity_to_log_level(module.VERBOSITY_ERROR) == logging.ERROR def test_verbosity_to_log_level_maps_unknown_verbosity_to_warning_level():