diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2018-05-27 16:38:18 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2018-05-29 12:27:54 +0100 |
commit | 996e8dc59d38ad5bc0c60bb03d2ddcac854f96fd (patch) | |
tree | e87ef5e9b50fd1602791c4dbffd6ebcdb54f1b53 | |
parent | 1ec69db8fd4b4f66ede0164f335ce588310acfd1 (diff) | |
download | sos-996e8dc59d38ad5bc0c60bb03d2ddcac854f96fd.tar.gz |
[sosreport] add separator argument to _format_list()
The _format_list() function handles formatting lists as comma-
separated strings, including line wrapping and indentation to
match an outer indentation level.
Add a new 'sep' parameter to allow the list to be separated by
an arbitrary character sequence.
This allows space-separated command line option lists to be
printed by --list-presets.
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/sosreport.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/sos/sosreport.py b/sos/sosreport.py index 028571c9..39b37b58 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -52,7 +52,7 @@ else: fatal_fs_errors = (errno.ENOSPC, errno.EROFS) -def _format_list(first_line, items, indent=False): +def _format_list(first_line, items, indent=False, sep=", "): lines = [] line = first_line if indent: @@ -60,12 +60,12 @@ def _format_list(first_line, items, indent=False): else: newline = "" for item in items: - if len(line) + len(item) + 2 > 72: + if len(line) + len(item) + len(sep) > 72: lines.append(line) line = newline - line = line + item + ', ' - if line[-2:] == ', ': - line = line[:-2] + line = line + item + sep + if line[-len(sep):] == sep: + line = line[:-len(sep)] lines.append(line) return lines |