Skip to content

Commit

Permalink
Filter listed paths via "borgmatic list --path" flag (#269).
Browse files Browse the repository at this point in the history
  • Loading branch information
witten committed Dec 8, 2019
1 parent b94999b commit 826e435
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Fix "borgmatic umount" so it only runs Borg once instead of once per repository / configuration
file.
* #253: Mount whole repositories via "borgmatic mount" without any "--archive" flag.
* #269: Filter listed paths via "borgmatic list --path" flag.

1.4.17
* #235: Pass extra options directly to particular Borg commands, handy for Borg options that
Expand Down
3 changes: 2 additions & 1 deletion borgmatic/borg/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ def list_archives(repository, storage_config, list_arguments, local_path='borg',
+ make_flags('remote-path', remote_path)
+ make_flags('lock-wait', lock_wait)
+ make_flags_from_arguments(
list_arguments, excludes=('repository', 'archive', 'successful')
list_arguments, excludes=('repository', 'archive', 'paths', 'successful')
)
+ (
'::'.join((repository, list_arguments.archive))
if list_arguments.archive
else repository,
)
+ (tuple(list_arguments.paths) if list_arguments.paths else ())
)

return execute_command(
Expand Down
7 changes: 7 additions & 0 deletions borgmatic/commands/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,13 @@ def parse_arguments(*unparsed_arguments):
help='Path of repository to list, defaults to the configured repository if there is only one',
)
list_group.add_argument('--archive', help='Name of archive to list')
list_group.add_argument(
'--path',
metavar='PATH',
nargs='+',
dest='paths',
help='Paths to list from archive, defaults to the entire archive',
)
list_group.add_argument(
'--short', default=False, action='store_true', help='Output only archive or path names'
)
Expand Down
41 changes: 28 additions & 13 deletions tests/unit/borg/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_list_archives_calls_borg_with_parameters():
module.list_archives(
repository='repo',
storage_config={},
list_arguments=flexmock(archive=None, json=False, successful=False),
list_arguments=flexmock(archive=None, paths=None, json=False, successful=False),
)


Expand All @@ -31,7 +31,7 @@ def test_list_archives_with_log_info_calls_borg_with_info_parameter():
module.list_archives(
repository='repo',
storage_config={},
list_arguments=flexmock(archive=None, json=False, successful=False),
list_arguments=flexmock(archive=None, paths=None, json=False, successful=False),
)


Expand All @@ -44,7 +44,7 @@ def test_list_archives_with_log_info_and_json_suppresses_most_borg_output():
module.list_archives(
repository='repo',
storage_config={},
list_arguments=flexmock(archive=None, json=True, successful=False),
list_arguments=flexmock(archive=None, paths=None, json=True, successful=False),
)


Expand All @@ -59,7 +59,7 @@ def test_list_archives_with_log_debug_calls_borg_with_debug_parameter():
module.list_archives(
repository='repo',
storage_config={},
list_arguments=flexmock(archive=None, json=False, successful=False),
list_arguments=flexmock(archive=None, paths=None, json=False, successful=False),
)


Expand All @@ -72,7 +72,7 @@ def test_list_archives_with_log_debug_and_json_suppresses_most_borg_output():
module.list_archives(
repository='repo',
storage_config={},
list_arguments=flexmock(archive=None, json=True, successful=False),
list_arguments=flexmock(archive=None, paths=None, json=True, successful=False),
)


Expand All @@ -87,7 +87,7 @@ def test_list_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
module.list_archives(
repository='repo',
storage_config=storage_config,
list_arguments=flexmock(archive=None, json=False, successful=False),
list_arguments=flexmock(archive=None, paths=None, json=False, successful=False),
)


Expand All @@ -100,7 +100,22 @@ def test_list_archives_with_archive_calls_borg_with_archive_parameter():
module.list_archives(
repository='repo',
storage_config=storage_config,
list_arguments=flexmock(archive='archive', json=False, successful=False),
list_arguments=flexmock(archive='archive', paths=None, json=False, successful=False),
)


def test_list_archives_with_path_calls_borg_with_path_parameter():
storage_config = {}
flexmock(module).should_receive('execute_command').with_args(
('borg', 'list', 'repo::archive', 'var/lib'),
output_log_level=logging.WARNING,
error_on_warnings=False,
)

module.list_archives(
repository='repo',
storage_config=storage_config,
list_arguments=flexmock(archive='archive', paths=['var/lib'], json=False, successful=False),
)


Expand All @@ -112,7 +127,7 @@ def test_list_archives_with_local_path_calls_borg_via_local_path():
module.list_archives(
repository='repo',
storage_config={},
list_arguments=flexmock(archive=None, json=False, successful=False),
list_arguments=flexmock(archive=None, paths=None, json=False, successful=False),
local_path='borg1',
)

Expand All @@ -127,7 +142,7 @@ def test_list_archives_with_remote_path_calls_borg_with_remote_path_parameters()
module.list_archives(
repository='repo',
storage_config={},
list_arguments=flexmock(archive=None, json=False, successful=False),
list_arguments=flexmock(archive=None, paths=None, json=False, successful=False),
remote_path='borg1',
)

Expand All @@ -142,7 +157,7 @@ def test_list_archives_with_short_calls_borg_with_short_parameter():
module.list_archives(
repository='repo',
storage_config={},
list_arguments=flexmock(archive=None, json=False, successful=False, short=True),
list_arguments=flexmock(archive=None, paths=None, json=False, successful=False, short=True),
)


Expand Down Expand Up @@ -171,7 +186,7 @@ def test_list_archives_passes_through_arguments_to_borg(argument_name):
repository='repo',
storage_config={},
list_arguments=flexmock(
archive=None, json=False, successful=False, **{argument_name: 'value'}
archive=None, paths=None, json=False, successful=False, **{argument_name: 'value'}
),
)

Expand All @@ -186,7 +201,7 @@ def test_list_archives_with_successful_calls_borg_to_exclude_checkpoints():
module.list_archives(
repository='repo',
storage_config={},
list_arguments=flexmock(archive=None, json=False, successful=True),
list_arguments=flexmock(archive=None, paths=None, json=False, successful=True),
)


Expand All @@ -198,7 +213,7 @@ def test_list_archives_with_json_calls_borg_with_json_parameter():
json_output = module.list_archives(
repository='repo',
storage_config={},
list_arguments=flexmock(archive=None, json=True, successful=False),
list_arguments=flexmock(archive=None, paths=None, json=True, successful=False),
)

assert json_output == '[]'

0 comments on commit 826e435

Please sign in to comment.