mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-23 14:41:43 +00:00
archive listing: use iso8601 timestamp format with --json-lines
like yyyy-mm-ddThh:mm:ss - no tz yet, this likely needs more refactoring to tz aware and utc datetime objects everywhere, currently there are naive datetime objects and also localtime at quite some places.
This commit is contained in:
parent
70c7f481fc
commit
09c111bb44
2 changed files with 20 additions and 8 deletions
|
@ -18,7 +18,7 @@
|
|||
|
||||
from .errors import Error
|
||||
from .fs import get_keys_dir
|
||||
from .time import format_time, to_localtime, safe_timestamp, safe_s
|
||||
from .time import format_time, isoformat_time, to_localtime, safe_timestamp, safe_s
|
||||
from .usergroup import uid2user
|
||||
from .. import __version__ as borg_version
|
||||
from .. import __version_tuple__ as borg_version_tuple
|
||||
|
@ -657,6 +657,12 @@ def __init__(self, archive, format, *, json_lines=False):
|
|||
'archiveid': archive.fpr,
|
||||
}
|
||||
static_keys.update(self.FIXED_KEYS)
|
||||
if self.json_lines:
|
||||
self.item_data = {}
|
||||
self.format_item = self.format_item_json
|
||||
self.format_time = self.format_time_json
|
||||
else:
|
||||
self.item_data = static_keys
|
||||
self.format = partial_format(format, static_keys)
|
||||
self.format_keys = {f[1] for f in Formatter().parse(format)}
|
||||
self.call_keys = {
|
||||
|
@ -676,11 +682,6 @@ def __init__(self, archive, format, *, json_lines=False):
|
|||
for hash_function in hashlib.algorithms_guaranteed:
|
||||
self.add_key(hash_function, partial(self.hash_item, hash_function))
|
||||
self.used_call_keys = set(self.call_keys) & self.format_keys
|
||||
if self.json_lines:
|
||||
self.item_data = {}
|
||||
self.format_item = self.format_item_json
|
||||
else:
|
||||
self.item_data = static_keys
|
||||
|
||||
def format_item_json(self, item):
|
||||
return json.dumps(self.get_item_data(item)) + '\n'
|
||||
|
@ -758,7 +759,12 @@ def hash_item(self, hash_function, item):
|
|||
return hash.hexdigest()
|
||||
|
||||
def format_time(self, key, item):
|
||||
return format_time(safe_timestamp(item.get(key) or item.mtime))
|
||||
t = self.time(key, item)
|
||||
return format_time(t)
|
||||
|
||||
def format_time_json(self, key, item):
|
||||
t = self.time(key, item)
|
||||
return isoformat_time(t)
|
||||
|
||||
def time(self, key, item):
|
||||
return safe_timestamp(item.get(key) or item.mtime)
|
||||
|
|
|
@ -87,11 +87,17 @@ def safe_timestamp(item_timestamp_ns):
|
|||
|
||||
|
||||
def format_time(t):
|
||||
"""use ISO-8601 date and time format
|
||||
"""use ISO-8601-like date and time format (human readable, with wkday and blank date/time separator)
|
||||
"""
|
||||
return t.strftime('%a, %Y-%m-%d %H:%M:%S')
|
||||
|
||||
|
||||
def isoformat_time(t):
|
||||
"""use ISO-8601 date and time format (machine readable, no wkday, no microseconds either)
|
||||
"""
|
||||
return t.strftime('%Y-%m-%dT%H:%M:%S') # note: first make all datetime objects tz aware before adding %z here.
|
||||
|
||||
|
||||
def format_timedelta(td):
|
||||
"""Format timedelta in a human friendly format
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue