mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-28 02:09:09 +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():
|
for item in archive.iter_items():
|
||||||
print(remove_surrogates(item[b'path']))
|
print(remove_surrogates(item[b'path']))
|
||||||
else:
|
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.
|
"""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
|
When user issues format options, listing is a bit slower, but more keys are available and
|
||||||
precalculated
|
precalculated.
|
||||||
"""
|
"""
|
||||||
use_user_format = False
|
use_user_format = args.listformat is not None
|
||||||
if args.listformat:
|
list_format = args.listformat if use_user_format else \
|
||||||
user_format = args.listformat
|
"{mode} {user:6} {group:6} {size:8d} {isomtime} {path}{extra}{LF}"
|
||||||
use_user_format = True
|
|
||||||
|
|
||||||
archive_name = archive.name
|
|
||||||
|
|
||||||
for item in archive.iter_items():
|
for item in archive.iter_items():
|
||||||
mode = stat.filemode(item[b'mode'])
|
mode = stat.filemode(item[b'mode'])
|
||||||
|
@ -464,8 +459,8 @@ def do_list(self, args):
|
||||||
size = sum(size for _, size, _ in item[b'chunks'])
|
size = sum(size for _, size, _ in item[b'chunks'])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
mtime = safe_timestamp(item[b'mtime'])
|
|
||||||
|
|
||||||
|
mtime = safe_timestamp(item[b'mtime'])
|
||||||
if use_user_format:
|
if use_user_format:
|
||||||
atime = safe_timestamp(item[b'atime'])
|
atime = safe_timestamp(item[b'atime'])
|
||||||
ctime = safe_timestamp(item[b'ctime'])
|
ctime = safe_timestamp(item[b'ctime'])
|
||||||
|
@ -489,6 +484,7 @@ def do_list(self, args):
|
||||||
'isomtime': format_time(mtime),
|
'isomtime': format_time(mtime),
|
||||||
'path': remove_surrogates(item[b'path']),
|
'path': remove_surrogates(item[b'path']),
|
||||||
'extra': extra,
|
'extra': extra,
|
||||||
|
'LF': '\n',
|
||||||
}
|
}
|
||||||
if use_user_format:
|
if use_user_format:
|
||||||
item_data_advanced = {
|
item_data_advanced = {
|
||||||
|
@ -503,20 +499,16 @@ def do_list(self, args):
|
||||||
'ctime': ctime,
|
'ctime': ctime,
|
||||||
'isoatime': format_time(atime),
|
'isoatime': format_time(atime),
|
||||||
'atime': atime,
|
'atime': atime,
|
||||||
'archivename': archive_name,
|
'archivename': archive.name,
|
||||||
'SPACE': " ",
|
'SPACE': ' ',
|
||||||
'TAB': "\t",
|
'TAB': '\t',
|
||||||
'LF': "\n",
|
'CR': '\r',
|
||||||
'CR': "\r",
|
|
||||||
'NEWLINE': os.linesep,
|
'NEWLINE': os.linesep,
|
||||||
}
|
}
|
||||||
item_data.update(item_data_advanced)
|
item_data.update(item_data_advanced)
|
||||||
item_data['formatkeys'] = list(item_data.keys())
|
item_data['formatkeys'] = list(item_data.keys())
|
||||||
|
|
||||||
if use_user_format:
|
print(format_line(list_format, item_data), end='')
|
||||||
print(format_line(user_format, item_data), end='')
|
|
||||||
else:
|
|
||||||
print(format_line(user_format, item_data))
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for archive_info in manifest.list_archive_infos(sort_by='ts'):
|
for archive_info in manifest.list_archive_infos(sort_by='ts'):
|
||||||
|
|
Loading…
Reference in a new issue