mirror of
https://github.com/borgbackup/borg.git
synced 2025-03-14 16:11: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.
(cherry picked from commit 043d794b91
)
This commit is contained in:
parent
51bcba332b
commit
d17553add6
1 changed files with 19 additions and 7 deletions
|
@ -717,11 +717,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
|
||||
"""
|
||||
|
@ -1762,6 +1768,12 @@ class ItemFormatter(BaseFormatter):
|
|||
'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 = {
|
||||
|
@ -1781,11 +1793,6 @@ class ItemFormatter(BaseFormatter):
|
|||
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'
|
||||
|
@ -1863,7 +1870,12 @@ class ItemFormatter(BaseFormatter):
|
|||
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue