Explorar o código

refactor Archiver._get_filtered_archives -> Archives.list_filtered

it did not belong into Archiver class (did not use "self"), but in into Archives.
Thomas Waldmann %!s(int64=8) %!d(string=hai) anos
pai
achega
694c3978a1
Modificáronse 3 ficheiros con 21 adicións e 22 borrados
  1. 4 19
      src/borg/archiver.py
  2. 2 3
      src/borg/fuse.py
  3. 15 0
      src/borg/helpers.py

+ 4 - 19
src/borg/archiver.py

@@ -783,7 +783,7 @@ class Archiver:
         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 @@ class Archiver:
             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 @@ class Archiver:
             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 @@ class Archiver:
         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 @@ class Archiver:
             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"""

+ 2 - 3
src/borg/fuse.py

@@ -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 @@ class FuseOperations(llfuse.Operations):
                               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)

+ 15 - 0
src/borg/helpers.py

@@ -154,6 +154,21 @@ class Archives(abc.MutableMapping):
             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():