mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-01 12:45:34 +00:00
Adds archives filters for list
This commit is contained in:
parent
369d0a0881
commit
e0e9edfb42
1 changed files with 27 additions and 24 deletions
|
@ -879,34 +879,38 @@ def write(bytestring):
|
|||
write = sys.stdout.buffer.write
|
||||
|
||||
if args.location.archive:
|
||||
matcher, _ = self.build_matcher(args.excludes, args.paths)
|
||||
with Cache(repository, key, manifest, lock_wait=self.lock_wait) as cache:
|
||||
archive = Archive(repository, key, manifest, args.location.archive, cache=cache,
|
||||
consider_part_files=args.consider_part_files)
|
||||
|
||||
if args.format is not None:
|
||||
format = args.format
|
||||
elif args.short:
|
||||
format = "{path}{NL}"
|
||||
else:
|
||||
format = "{mode} {user:6} {group:6} {size:8} {isomtime} {path}{extra}{NL}"
|
||||
formatter = ItemFormatter(archive, format)
|
||||
|
||||
for item in archive.iter_items(lambda item: matcher.match(item.path)):
|
||||
write(safe_encode(formatter.format_item(item)))
|
||||
return self._list_archive(args, repository, manifest, key, write)
|
||||
else:
|
||||
return self._list_repository(args, manifest, write)
|
||||
|
||||
def _list_archive(self, args, repository, manifest, key, write):
|
||||
matcher, _ = self.build_matcher(args.excludes, args.paths)
|
||||
with Cache(repository, key, manifest, lock_wait=self.lock_wait) as cache:
|
||||
archive = Archive(repository, key, manifest, args.location.archive, cache=cache,
|
||||
consider_part_files=args.consider_part_files)
|
||||
if args.format is not None:
|
||||
format = args.format
|
||||
elif args.short:
|
||||
format = "{archive}{NL}"
|
||||
format = "{path}{NL}"
|
||||
else:
|
||||
format = "{archive:<36} {time} [{id}]{NL}"
|
||||
formatter = ArchiveFormatter(format)
|
||||
format = "{mode} {user:6} {group:6} {size:8} {isomtime} {path}{extra}{NL}"
|
||||
formatter = ItemFormatter(archive, format)
|
||||
|
||||
for archive_info in manifest.archives.list(sort_by='ts'):
|
||||
if args.prefix and not archive_info.name.startswith(args.prefix):
|
||||
continue
|
||||
write(safe_encode(formatter.format_item(archive_info)))
|
||||
for item in archive.iter_items(lambda item: matcher.match(item.path)):
|
||||
write(safe_encode(formatter.format_item(item)))
|
||||
return self.exit_code
|
||||
|
||||
def _list_repository(self, args, manifest, write):
|
||||
if args.format is not None:
|
||||
format = args.format
|
||||
elif args.short:
|
||||
format = "{archive}{NL}"
|
||||
else:
|
||||
format = "{archive:<36} {time} [{id}]{NL}"
|
||||
formatter = ArchiveFormatter(format)
|
||||
|
||||
for archive_info in self._get_filtered_archives(args, manifest):
|
||||
write(safe_encode(formatter.format_item(archive_info)))
|
||||
|
||||
return self.exit_code
|
||||
|
||||
|
@ -2043,8 +2047,6 @@ def build_parser(self, prog=None):
|
|||
subparser.add_argument('--format', '--list-format', dest='format', type=str,
|
||||
help="""specify format for file listing
|
||||
(default: "{mode} {user:6} {group:6} {size:8d} {isomtime} {path}{extra}{NL}")""")
|
||||
subparser.add_argument('-P', '--prefix', dest='prefix', type=prefix_spec,
|
||||
help='only consider archive names starting with this prefix')
|
||||
subparser.add_argument('-e', '--exclude', dest='excludes',
|
||||
type=parse_pattern, action='append',
|
||||
metavar="PATTERN", help='exclude paths matching PATTERN')
|
||||
|
@ -2056,6 +2058,7 @@ def build_parser(self, prog=None):
|
|||
help='repository/archive to list contents of')
|
||||
subparser.add_argument('paths', metavar='PATH', nargs='*', type=str,
|
||||
help='paths to list; patterns are supported')
|
||||
self.add_archives_filters_args(subparser)
|
||||
|
||||
mount_epilog = textwrap.dedent("""
|
||||
This command mounts an archive as a FUSE filesystem. This can be useful for
|
||||
|
|
Loading…
Reference in a new issue