mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
backups: Format better when showing archive time delete page
- When archives are listed using list_archives() method, return datetime objects instead of pre-formatted strings. datetime objects can be compared easily and shown in a more human readable format. Tests: - Unit tests pass. - Backups with a future date are ignored when considering recent backup times (when they logged to console). - Most recent scheduled backup times are retrieved correctly (when they logged to console). Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
d423b40239
commit
91270331cc
@ -3,6 +3,7 @@
|
||||
|
||||
import abc
|
||||
import contextlib
|
||||
import datetime
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
@ -121,6 +122,12 @@ class BaseBorgRepository(abc.ABC):
|
||||
"""Return list of archives in this repository."""
|
||||
archives = privileged.list_repo(
|
||||
self.borg_path, self._get_encryption_passpharse())['archives']
|
||||
for archive in archives:
|
||||
archive['time'] = datetime.datetime.strptime(
|
||||
archive['time'], '%Y-%m-%dT%H:%M:%S.%f')
|
||||
archive['start'] = datetime.datetime.strptime(
|
||||
archive['start'], '%Y-%m-%dT%H:%M:%S.%f')
|
||||
|
||||
return sorted(archives, key=lambda archive: archive['start'],
|
||||
reverse=True)
|
||||
|
||||
|
||||
@ -242,14 +242,11 @@ class Schedule:
|
||||
|
||||
archive['comment'] = comment
|
||||
|
||||
start_time = datetime.strptime(archive['start'],
|
||||
'%Y-%m-%dT%H:%M:%S.%f')
|
||||
if start_time > now:
|
||||
if archive['start'] > now:
|
||||
# This backup was taken when clock was set in future. Ignore it
|
||||
# to ensure backups continue to be taken.
|
||||
continue
|
||||
|
||||
archive['start'] = start_time
|
||||
scheduled_archives.append(archive)
|
||||
|
||||
return scheduled_archives
|
||||
|
||||
@ -84,16 +84,12 @@ def _get_archives_from_test_data(data):
|
||||
if isinstance(archive_time, str):
|
||||
archive_time = datetime.strptime(archive_time,
|
||||
'%Y-%m-%d %H:%M:%S+0000')
|
||||
|
||||
comment = json.dumps({'type': 'scheduled', 'periods': item['periods']})
|
||||
archive = {
|
||||
'comment':
|
||||
json.dumps({
|
||||
'type': 'scheduled',
|
||||
'periods': item['periods']
|
||||
}),
|
||||
'start':
|
||||
archive_time.strftime('%Y-%m-%dT%H:%M:%S.%f'),
|
||||
'name':
|
||||
f'archive-{index}'
|
||||
'comment': comment,
|
||||
'start': archive_time,
|
||||
'name': f'archive-{index}'
|
||||
}
|
||||
archives.append(archive)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user