mirror of https://github.com/borgbackup/borg.git
Implemented Repository.list()
This commit is contained in:
parent
bbf490bf8b
commit
0d248192e5
|
@ -194,6 +194,9 @@ class RemoteRepository(object):
|
|||
def __len__(self):
|
||||
return self.call('__len__')
|
||||
|
||||
def list(self, limit=None, marker=None):
|
||||
return self.call('list', limit, marker)
|
||||
|
||||
def get(self, id_):
|
||||
for resp in self.get_many([id_]):
|
||||
return resp
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from configparser import RawConfigParser
|
||||
from binascii import hexlify
|
||||
from itertools import islice
|
||||
import errno
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import struct
|
||||
import sys
|
||||
|
@ -292,6 +292,11 @@ class Repository(object):
|
|||
self.index = self.get_read_only_index(self.get_transaction_id())
|
||||
return len(self.index)
|
||||
|
||||
def list(self, limit=None, marker=None):
|
||||
if not self.index:
|
||||
self.index = self.get_read_only_index(self.get_transaction_id())
|
||||
return [id_ for id_, _ in islice(self.index.iteritems(marker=marker), limit)]
|
||||
|
||||
def get(self, id_):
|
||||
if not self.index:
|
||||
self.index = self.get_read_only_index(self.get_transaction_id())
|
||||
|
|
|
@ -87,6 +87,19 @@ class RepositoryTestCase(AtticTestCase):
|
|||
self.repository.delete(b'00000000000000000000000000000000')
|
||||
self.repository.commit()
|
||||
|
||||
def test_list(self):
|
||||
for x in range(100):
|
||||
self.repository.put(('%-32d' % x).encode('ascii'), b'SOMEDATA')
|
||||
all = self.repository.list()
|
||||
self.assert_equal(len(all), 100)
|
||||
first_half = self.repository.list(limit=50)
|
||||
self.assert_equal(len(first_half), 50)
|
||||
self.assert_equal(first_half, all[:50])
|
||||
second_half = self.repository.list(marker=first_half[-1])
|
||||
self.assert_equal(len(second_half), 50)
|
||||
self.assert_equal(second_half, all[50:])
|
||||
self.assert_equal(len(self.repository.list(limit=50)), 50)
|
||||
|
||||
|
||||
class RepositoryCheckTestCase(AtticTestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue