mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +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 abc
|
||||||
import contextlib
|
import contextlib
|
||||||
|
import datetime
|
||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -121,6 +122,12 @@ class BaseBorgRepository(abc.ABC):
|
|||||||
"""Return list of archives in this repository."""
|
"""Return list of archives in this repository."""
|
||||||
archives = privileged.list_repo(
|
archives = privileged.list_repo(
|
||||||
self.borg_path, self._get_encryption_passpharse())['archives']
|
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'],
|
return sorted(archives, key=lambda archive: archive['start'],
|
||||||
reverse=True)
|
reverse=True)
|
||||||
|
|
||||||
|
|||||||
@ -242,14 +242,11 @@ class Schedule:
|
|||||||
|
|
||||||
archive['comment'] = comment
|
archive['comment'] = comment
|
||||||
|
|
||||||
start_time = datetime.strptime(archive['start'],
|
if archive['start'] > now:
|
||||||
'%Y-%m-%dT%H:%M:%S.%f')
|
|
||||||
if start_time > now:
|
|
||||||
# This backup was taken when clock was set in future. Ignore it
|
# This backup was taken when clock was set in future. Ignore it
|
||||||
# to ensure backups continue to be taken.
|
# to ensure backups continue to be taken.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
archive['start'] = start_time
|
|
||||||
scheduled_archives.append(archive)
|
scheduled_archives.append(archive)
|
||||||
|
|
||||||
return scheduled_archives
|
return scheduled_archives
|
||||||
|
|||||||
@ -84,16 +84,12 @@ def _get_archives_from_test_data(data):
|
|||||||
if isinstance(archive_time, str):
|
if isinstance(archive_time, str):
|
||||||
archive_time = datetime.strptime(archive_time,
|
archive_time = datetime.strptime(archive_time,
|
||||||
'%Y-%m-%d %H:%M:%S+0000')
|
'%Y-%m-%d %H:%M:%S+0000')
|
||||||
|
|
||||||
|
comment = json.dumps({'type': 'scheduled', 'periods': item['periods']})
|
||||||
archive = {
|
archive = {
|
||||||
'comment':
|
'comment': comment,
|
||||||
json.dumps({
|
'start': archive_time,
|
||||||
'type': 'scheduled',
|
'name': f'archive-{index}'
|
||||||
'periods': item['periods']
|
|
||||||
}),
|
|
||||||
'start':
|
|
||||||
archive_time.strftime('%Y-%m-%dT%H:%M:%S.%f'),
|
|
||||||
'name':
|
|
||||||
f'archive-{index}'
|
|
||||||
}
|
}
|
||||||
archives.append(archive)
|
archives.append(archive)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user