Explorar o código

less detail at v1 + option "--files" for details

palto42 %!s(int64=5) %!d(string=hai) anos
pai
achega
e27ba0d08a

+ 3 - 0
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.

+ 12 - 2
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 ())

+ 11 - 3
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,)
     )

+ 14 - 0
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'
     )

+ 2 - 0
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)

+ 1 - 1
setup.py

@@ -1,6 +1,6 @@
 from setuptools import find_packages, setup
 
-VERSION = '1.4.22.dev0'
+VERSION = '1.4.22.dev0-files'
 
 
 setup(

+ 22 - 1
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'])
 

+ 3 - 5
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)
 

+ 1 - 3
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(