mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-24 15:12:00 +00:00
refactor Archiver._get_filtered_archives -> Archives.list_filtered
it did not belong into Archiver class (did not use "self"), but in into Archives.
This commit is contained in:
parent
26e6ac4fea
commit
694c3978a1
3 changed files with 21 additions and 22 deletions
|
@ -783,7 +783,7 @@ def _delete_archives(self, args, repository):
|
|||
if args.location.archive:
|
||||
archive_names = (args.location.archive,)
|
||||
else:
|
||||
archive_names = tuple(x.name for x in self._get_filtered_archives(args, manifest))
|
||||
archive_names = tuple(x.name for x in manifest.archives.list_filtered(args))
|
||||
if not archive_names:
|
||||
return self.exit_code
|
||||
|
||||
|
@ -853,7 +853,7 @@ def do_mount(self, args, repository, manifest, key):
|
|||
return self.exit_code
|
||||
|
||||
with cache_if_remote(repository) as cached_repo:
|
||||
operations = FuseOperations(key, repository, manifest, args, cached_repo, archiver=self)
|
||||
operations = FuseOperations(key, repository, manifest, args, cached_repo)
|
||||
logger.info("Mounting filesystem")
|
||||
try:
|
||||
operations.mount(args.mountpoint, args.options, args.foreground)
|
||||
|
@ -904,7 +904,7 @@ def _list_repository(self, args, manifest, write):
|
|||
format = "{archive:<36} {time} [{id}]{NL}"
|
||||
formatter = ArchiveFormatter(format)
|
||||
|
||||
for archive_info in self._get_filtered_archives(args, manifest):
|
||||
for archive_info in manifest.archives.list_filtered(args):
|
||||
write(safe_encode(formatter.format_item(archive_info)))
|
||||
|
||||
return self.exit_code
|
||||
|
@ -924,7 +924,7 @@ def format_cmdline(cmdline):
|
|||
if args.location.archive:
|
||||
archive_names = (args.location.archive,)
|
||||
else:
|
||||
archive_names = tuple(x.name for x in self._get_filtered_archives(args, manifest))
|
||||
archive_names = tuple(x.name for x in manifest.archives.list_filtered(args))
|
||||
if not archive_names:
|
||||
return self.exit_code
|
||||
|
||||
|
@ -2626,21 +2626,6 @@ def run(self, args):
|
|||
logger.warning("Using a pure-python msgpack! This will result in lower performance.")
|
||||
return args.func(args)
|
||||
|
||||
def _get_filtered_archives(self, args, manifest):
|
||||
if args.location.archive:
|
||||
raise Error('The options --first, --last and --prefix can only be used on repository targets.')
|
||||
|
||||
archives = manifest.archives.list(prefix=args.prefix)
|
||||
|
||||
for sortkey in reversed(args.sort_by.split(',')):
|
||||
archives.sort(key=attrgetter(sortkey))
|
||||
if args.last:
|
||||
archives.reverse()
|
||||
|
||||
n = args.first or args.last or len(archives)
|
||||
|
||||
return archives[:n]
|
||||
|
||||
|
||||
def sig_info_handler(sig_no, stack): # pragma: no cover
|
||||
"""search the stack for infos about the currently processed file and print them"""
|
||||
|
|
|
@ -58,9 +58,8 @@ class FuseOperations(llfuse.Operations):
|
|||
allow_damaged_files = False
|
||||
versions = False
|
||||
|
||||
def __init__(self, key, repository, manifest, args, cached_repo, archiver):
|
||||
def __init__(self, key, repository, manifest, args, cached_repo):
|
||||
super().__init__()
|
||||
self.archiver = archiver
|
||||
self.repository_uncached = repository
|
||||
self.repository = cached_repo
|
||||
self.args = args
|
||||
|
@ -85,7 +84,7 @@ def _create_filesystem(self):
|
|||
consider_part_files=self.args.consider_part_files)
|
||||
self.process_archive(archive)
|
||||
else:
|
||||
archive_names = (x.name for x in self.archiver._get_filtered_archives(self.args, self.manifest))
|
||||
archive_names = (x.name for x in self.manifest.archives.list_filtered(self.args))
|
||||
for name in archive_names:
|
||||
archive = Archive(self.repository_uncached, self.key, self.manifest, name,
|
||||
consider_part_files=self.args.consider_part_files)
|
||||
|
|
|
@ -154,6 +154,21 @@ def list(self, sort_by=None, reverse=False, prefix=''):
|
|||
archives.reverse()
|
||||
return archives
|
||||
|
||||
def list_filtered(self, args):
|
||||
"""
|
||||
get a filtered list of archives, considering --first/last/prefix/sort
|
||||
"""
|
||||
if args.location.archive:
|
||||
raise Error('The options --first, --last and --prefix can only be used on repository targets.')
|
||||
archives = self.list(prefix=args.prefix)
|
||||
for sortkey in reversed(args.sort_by.split(',')):
|
||||
archives.sort(key=attrgetter(sortkey))
|
||||
if args.last:
|
||||
archives.reverse()
|
||||
n = args.first or args.last or len(archives)
|
||||
return archives[:n]
|
||||
|
||||
|
||||
def set_raw_dict(self, d):
|
||||
"""set the dict we get from the msgpack unpacker"""
|
||||
for k, v in d.items():
|
||||
|
|
Loading…
Reference in a new issue