mirror of https://github.com/borgbackup/borg.git
Adds archives filters for info
This commit is contained in:
parent
f2d4d36cea
commit
369d0a0881
|
@ -913,11 +913,24 @@ class Archiver:
|
||||||
@with_repository(cache=True)
|
@with_repository(cache=True)
|
||||||
def do_info(self, args, repository, manifest, key, cache):
|
def do_info(self, args, repository, manifest, key, cache):
|
||||||
"""Show archive details such as disk space used"""
|
"""Show archive details such as disk space used"""
|
||||||
|
if any((args.location.archive, args.first, args.last, args.prefix)):
|
||||||
|
return self._info_archives(args, repository, manifest, key, cache)
|
||||||
|
else:
|
||||||
|
return self._info_repository(cache)
|
||||||
|
|
||||||
|
def _info_archives(self, args, repository, manifest, key, cache):
|
||||||
def format_cmdline(cmdline):
|
def format_cmdline(cmdline):
|
||||||
return remove_surrogates(' '.join(shlex.quote(x) for x in cmdline))
|
return remove_surrogates(' '.join(shlex.quote(x) for x in cmdline))
|
||||||
|
|
||||||
if args.location.archive:
|
if args.location.archive:
|
||||||
archive = Archive(repository, key, manifest, args.location.archive, cache=cache,
|
archive_names = (args.location.archive,)
|
||||||
|
else:
|
||||||
|
archive_names = tuple(x.name for x in self._get_filtered_archives(args, manifest))
|
||||||
|
if not archive_names:
|
||||||
|
return self.exit_code
|
||||||
|
|
||||||
|
for i, archive_name in enumerate(archive_names, 1):
|
||||||
|
archive = Archive(repository, key, manifest, archive_name, cache=cache,
|
||||||
consider_part_files=args.consider_part_files)
|
consider_part_files=args.consider_part_files)
|
||||||
stats = archive.calc_stats(cache)
|
stats = archive.calc_stats(cache)
|
||||||
print('Archive name: %s' % archive.name)
|
print('Archive name: %s' % archive.name)
|
||||||
|
@ -934,9 +947,15 @@ class Archiver:
|
||||||
print(STATS_HEADER)
|
print(STATS_HEADER)
|
||||||
print(str(stats))
|
print(str(stats))
|
||||||
print(str(cache))
|
print(str(cache))
|
||||||
else:
|
if self.exit_code:
|
||||||
print(STATS_HEADER)
|
break
|
||||||
print(str(cache))
|
if len(archive_names) - i:
|
||||||
|
print()
|
||||||
|
return self.exit_code
|
||||||
|
|
||||||
|
def _info_repository(self, cache):
|
||||||
|
print(STATS_HEADER)
|
||||||
|
print(str(cache))
|
||||||
return self.exit_code
|
return self.exit_code
|
||||||
|
|
||||||
@with_repository(exclusive=True)
|
@with_repository(exclusive=True)
|
||||||
|
@ -2102,6 +2121,7 @@ class Archiver:
|
||||||
subparser.add_argument('location', metavar='REPOSITORY_OR_ARCHIVE',
|
subparser.add_argument('location', metavar='REPOSITORY_OR_ARCHIVE',
|
||||||
type=location_validator(),
|
type=location_validator(),
|
||||||
help='archive or repository to display information about')
|
help='archive or repository to display information about')
|
||||||
|
self.add_archives_filters_args(subparser)
|
||||||
|
|
||||||
break_lock_epilog = textwrap.dedent("""
|
break_lock_epilog = textwrap.dedent("""
|
||||||
This command breaks the repository and cache locks.
|
This command breaks the repository and cache locks.
|
||||||
|
|
|
@ -964,6 +964,8 @@ class ArchiverTestCase(ArchiverTestCaseBase):
|
||||||
assert 'All archives:' in info_repo
|
assert 'All archives:' in info_repo
|
||||||
info_archive = self.cmd('info', self.repository_location + '::test')
|
info_archive = self.cmd('info', self.repository_location + '::test')
|
||||||
assert 'Archive name: test\n' in info_archive
|
assert 'Archive name: test\n' in info_archive
|
||||||
|
info_archive = self.cmd('info', '--first', '1', self.repository_location)
|
||||||
|
assert 'Archive name: test\n' in info_archive
|
||||||
|
|
||||||
def test_comment(self):
|
def test_comment(self):
|
||||||
self.create_regular_file('file1', size=1024 * 80)
|
self.create_regular_file('file1', size=1024 * 80)
|
||||||
|
|
Loading…
Reference in New Issue