Forráskód Böngészése

Add "list_details" config option support to new "recreate" action (#303).

Dan Helfman 2 hónapja
szülő
commit
8101e5c56f

+ 10 - 9
borgmatic/borg/recreate.py

@@ -22,24 +22,25 @@ def recreate_archive(
     patterns=None,
     patterns=None,
 ):
 ):
     '''
     '''
-    Given a local or remote repository path, an archive name, a configuration dict,
-    the local Borg version string, an argparse.Namespace of recreate arguments,
-    an argparse.Namespace of global arguments, optional local and remote Borg paths.
-
-    Executes the recreate command with the given arguments.
+    Given a local or remote repository path, an archive name, a configuration dict, the local Borg
+    version string, an argparse.Namespace of recreate arguments, an argparse.Namespace of global
+    arguments, optional local and remote Borg paths, executes the recreate command with the given
+    arguments.
     '''
     '''
-
     lock_wait = config.get('lock_wait', None)
     lock_wait = config.get('lock_wait', None)
     exclude_flags = make_exclude_flags(config)
     exclude_flags = make_exclude_flags(config)
     compression = config.get('compression', None)
     compression = config.get('compression', None)
     chunker_params = config.get('chunker_params', None)
     chunker_params = config.get('chunker_params', None)
-    # Available recompress MODES: 'if-different' (default), 'always', 'never'
+    # Available recompress MODES: "if-different", "always", "never" (default)
     recompress = config.get('recompress', None)
     recompress = config.get('recompress', None)
 
 
     # Write patterns to a temporary file and use that file with --patterns-from.
     # Write patterns to a temporary file and use that file with --patterns-from.
     patterns_file = write_patterns_file(
     patterns_file = write_patterns_file(
         patterns, borgmatic.config.paths.get_working_directory(config)
         patterns, borgmatic.config.paths.get_working_directory(config)
     )
     )
+    list_files = (
+        config.get('list_details') if recreate_arguments.list is None else recreate_arguments.list
+    )
 
 
     recreate_command = (
     recreate_command = (
         (local_path, 'recreate')
         (local_path, 'recreate')
@@ -55,10 +56,10 @@ def recreate_archive(
                 '--filter',
                 '--filter',
                 make_list_filter_flags(local_borg_version, global_arguments.dry_run),
                 make_list_filter_flags(local_borg_version, global_arguments.dry_run),
             )
             )
-            if recreate_arguments.list
+            if list_files
             else ()
             else ()
         )
         )
-        # Flag --target works only for a single archive
+        # Flag --target works only for a single archive.
         + (('--target', recreate_arguments.target) if recreate_arguments.target and archive else ())
         + (('--target', recreate_arguments.target) if recreate_arguments.target and archive else ())
         + (
         + (
             ('--comment', shlex.quote(recreate_arguments.comment))
             ('--comment', shlex.quote(recreate_arguments.comment))

+ 1 - 1
borgmatic/commands/arguments.py

@@ -288,7 +288,7 @@ def parse_arguments_for_actions(unparsed_arguments, action_parsers, global_parse
     )
     )
 
 
 
 
-OMITTED_FLAG_NAMES = {'match_archives', 'progress', 'statistics', 'list_files'}
+OMITTED_FLAG_NAMES = {'match_archives', 'progress', 'statistics', 'list_details'}
 
 
 
 
 def make_argument_description(schema, flag_name):
 def make_argument_description(schema, flag_name):

+ 32 - 12
tests/unit/borg/test_recreate.py

@@ -20,16 +20,6 @@ def insert_execute_command_mock(command, working_directory=None, borg_exit_codes
     ).once()
     ).once()
 
 
 
 
-def mock_dependencies():
-    flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
-    flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
-    flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
-    flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
-    flexmock(module.borgmatic.borg.flags).should_receive(
-        'make_repository_archive_flags'
-    ).and_return(('repo::archive',))
-
-
 def test_recreate_archive_dry_run_skips_execution():
 def test_recreate_archive_dry_run_skips_execution():
     flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
     flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
     flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
     flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
@@ -235,7 +225,7 @@ def test_recreate_with_log_json():
     )
     )
 
 
 
 
-def test_recreate_with_list_filter_flags():
+def test_recreate_archive_favors_list_flag_over_config():
     flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
     flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
     flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
     flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
     flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
     flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
@@ -250,7 +240,7 @@ def test_recreate_with_list_filter_flags():
     module.recreate_archive(
     module.recreate_archive(
         repository='repo',
         repository='repo',
         archive='archive',
         archive='archive',
-        config={},
+        config={'list_details': False},
         local_borg_version='1.2.3',
         local_borg_version='1.2.3',
         recreate_arguments=flexmock(
         recreate_arguments=flexmock(
             list=True,
             list=True,
@@ -265,6 +255,36 @@ def test_recreate_with_list_filter_flags():
     )
     )
 
 
 
 
+def test_recreate_archive_defaults_to_list_config():
+    flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
+    flexmock(module.borgmatic.borg.create).should_receive('write_patterns_file').and_return(None)
+    flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
+    flexmock(module.borgmatic.borg.flags).should_receive(
+        'make_repository_archive_flags'
+    ).and_return(('repo::archive',))
+    flexmock(module).should_receive('make_list_filter_flags').and_return('AME+-')
+    insert_execute_command_mock(
+        ('borg', 'recreate', '--list', '--filter', 'AME+-', 'repo::archive')
+    )
+
+    module.recreate_archive(
+        repository='repo',
+        archive='archive',
+        config={'list_details': True},
+        local_borg_version='1.2.3',
+        recreate_arguments=flexmock(
+            list=None,
+            target=None,
+            comment=None,
+            timestamp=None,
+            match_archives=None,
+        ),
+        global_arguments=flexmock(dry_run=False, log_json=False),
+        local_path='borg',
+        patterns=None,
+    )
+
+
 def test_recreate_with_patterns_from_flag():
 def test_recreate_with_patterns_from_flag():
     flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
     flexmock(module.borgmatic.borg.create).should_receive('make_exclude_flags').and_return(())
     flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')
     flexmock(module.borgmatic.borg.create).should_receive('make_list_filter_flags').and_return('')