mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-23 00:07:38 +00:00
Clean-up helpers.prune_split
This commit is contained in:
parent
13863e64f8
commit
d3ff6ac25d
1 changed files with 10 additions and 11 deletions
|
@ -92,18 +92,17 @@ def write(self):
|
|||
|
||||
|
||||
def prune_split(archives, pattern, n, skip=[]):
|
||||
items = {}
|
||||
last = None
|
||||
keep = []
|
||||
for a in archives:
|
||||
key = to_localtime(a.ts).strftime(pattern)
|
||||
items.setdefault(key, [])
|
||||
items[key].append(a)
|
||||
for key, values in sorted(items.items(), reverse=True):
|
||||
if n:
|
||||
values.sort(key=attrgetter('ts'), reverse=True)
|
||||
if values[0] not in skip:
|
||||
keep.append(values[0])
|
||||
n -= 1
|
||||
if n == 0:
|
||||
return keep
|
||||
for a in sorted(archives, key=attrgetter('ts'), reverse=True):
|
||||
period = a.ts.strftime(pattern)
|
||||
if period != last:
|
||||
last = period
|
||||
if a not in skip:
|
||||
keep.append(a)
|
||||
if len(keep) == n: break
|
||||
return keep
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue