borg list --prefix=thishostname- REPO, fixes #205

lists only archives with names starting with the given prefix.
This commit is contained in:
Thomas Waldmann 2015-11-06 15:45:49 +01:00
parent a4bb85970d
commit 7da730a8d7
2 changed files with 15 additions and 0 deletions

View File

@ -414,6 +414,8 @@ class Archiver:
remove_surrogates(item[b'path']), extra))
else:
for archive_info in manifest.list_archive_infos(sort_by='ts'):
if args.prefix and not archive_info.name.startswith(args.prefix):
continue
print(format_archive(archive_info))
return self.exit_code
@ -835,9 +837,12 @@ class Archiver:
subparser.add_argument('--short', dest='short',
action='store_true', default=False,
help='only print file/directory names, nothing else')
subparser.add_argument('-p', '--prefix', dest='prefix', type=str,
help='only consider archive names starting with this prefix')
subparser.add_argument('src', metavar='REPOSITORY_OR_ARCHIVE', nargs='?', default='',
type=location_validator(),
help='repository/archive to list contents of')
mount_epilog = textwrap.dedent("""
This command mounts an archive as a FUSE filesystem. This can be useful for
browsing an archive or restoring individual files. Unless the ``--foreground``

View File

@ -675,6 +675,16 @@ class ArchiverTestCase(ArchiverTestCaseBase):
self.assert_in('bar-2015-08-12-10:00', output)
self.assert_in('bar-2015-08-12-20:00', output)
def test_list_prefix(self):
self.cmd('init', self.repository_location)
self.cmd('create', self.repository_location + '::test-1', src_dir)
self.cmd('create', self.repository_location + '::something-else-than-test-1', src_dir)
self.cmd('create', self.repository_location + '::test-2', src_dir)
output = self.cmd('list', '--prefix=test-', self.repository_location)
self.assert_in('test-1', output)
self.assert_in('test-2', output)
self.assert_not_in('something-else', output)
def test_usage(self):
if self.FORK_DEFAULT:
self.cmd(exit_code=0)