mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-27 01:39:45 +00:00
refactored --list-format code a bit
note: LF as line ending is enough, python will translate that to CRLF on the platforms (windows) needing CRLF.
This commit is contained in:
parent
b28f4d886b
commit
f7666807cc
1 changed files with 11 additions and 19 deletions
|
@ -442,18 +442,13 @@ def do_list(self, args):
|
|||
for item in archive.iter_items():
|
||||
print(remove_surrogates(item[b'path']))
|
||||
else:
|
||||
long_format = "{mode} {user:6} {group:6} {size:8d} {isomtime} {path}{extra}"
|
||||
user_format = long_format
|
||||
"""use_user_format flag is used to speed up default listing.
|
||||
When user issues format options, listing is a bit slower, but more keys are available and
|
||||
precalculated
|
||||
precalculated.
|
||||
"""
|
||||
use_user_format = False
|
||||
if args.listformat:
|
||||
user_format = args.listformat
|
||||
use_user_format = True
|
||||
|
||||
archive_name = archive.name
|
||||
use_user_format = args.listformat is not None
|
||||
list_format = args.listformat if use_user_format else \
|
||||
"{mode} {user:6} {group:6} {size:8d} {isomtime} {path}{extra}{LF}"
|
||||
|
||||
for item in archive.iter_items():
|
||||
mode = stat.filemode(item[b'mode'])
|
||||
|
@ -464,8 +459,8 @@ def do_list(self, args):
|
|||
size = sum(size for _, size, _ in item[b'chunks'])
|
||||
except KeyError:
|
||||
pass
|
||||
mtime = safe_timestamp(item[b'mtime'])
|
||||
|
||||
mtime = safe_timestamp(item[b'mtime'])
|
||||
if use_user_format:
|
||||
atime = safe_timestamp(item[b'atime'])
|
||||
ctime = safe_timestamp(item[b'ctime'])
|
||||
|
@ -489,6 +484,7 @@ def do_list(self, args):
|
|||
'isomtime': format_time(mtime),
|
||||
'path': remove_surrogates(item[b'path']),
|
||||
'extra': extra,
|
||||
'LF': '\n',
|
||||
}
|
||||
if use_user_format:
|
||||
item_data_advanced = {
|
||||
|
@ -503,20 +499,16 @@ def do_list(self, args):
|
|||
'ctime': ctime,
|
||||
'isoatime': format_time(atime),
|
||||
'atime': atime,
|
||||
'archivename': archive_name,
|
||||
'SPACE': " ",
|
||||
'TAB': "\t",
|
||||
'LF': "\n",
|
||||
'CR': "\r",
|
||||
'archivename': archive.name,
|
||||
'SPACE': ' ',
|
||||
'TAB': '\t',
|
||||
'CR': '\r',
|
||||
'NEWLINE': os.linesep,
|
||||
}
|
||||
item_data.update(item_data_advanced)
|
||||
item_data['formatkeys'] = list(item_data.keys())
|
||||
|
||||
if use_user_format:
|
||||
print(format_line(user_format, item_data), end='')
|
||||
else:
|
||||
print(format_line(user_format, item_data))
|
||||
print(format_line(list_format, item_data), end='')
|
||||
|
||||
else:
|
||||
for archive_info in manifest.list_archive_infos(sort_by='ts'):
|
||||
|
|
Loading…
Reference in a new issue