in curator/snapshotlist.py [0:0]
def _sort_by_age(self, snapshot_list, reverse=True):
"""
Take a list of snapshots and sort them by date.
By default, the youngest are first with ``reverse=True``, but the oldest
can be first by setting ``reverse=False``
"""
# Do the age-based sorting here.
# First, build an temporary dictionary with just snapshot and age
# as the key and value, respectively
temp = {}
for snap in snapshot_list:
if self.age_keyfield in self.snapshot_info[snap]:
# This fixes #1366. Catch None is a potential age value.
if self.snapshot_info[snap][self.age_keyfield]:
temp[snap] = self.snapshot_info[snap][self.age_keyfield]
else:
msg = f' snapshot {snap} has no age'
self.__excludify(True, True, snap, msg)
else:
msg = (
f'{snap} does not have age key "{self.age_keyfield}" '
f'in SnapshotList metadata'
)
self.__excludify(True, True, snap, msg)
# If reverse is True, this will sort so the youngest snapshots are
# first. However, if you want oldest first, set reverse to False.
# Effectively, this should set us up to act on everything older than
# meets the other set criteria.
# It starts as a tuple, but then becomes a list.
sorted_tuple = sorted(temp.items(), key=lambda k: k[1], reverse=reverse)
return [x[0] for x in sorted_tuple]