diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2018-05-27 16:32:01 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2018-06-20 18:01:21 +0100 |
commit | a3f762c525d47c6dddd036ad20480588386c0e79 (patch) | |
tree | 19a47836fc62b1fe99e19bdea0cae876f2291cae | |
parent | 9a1b87750deaa069d4dd4c41056c4a500125af33 (diff) | |
download | sos-a3f762c525d47c6dddd036ad20480588386c0e79.tar.gz |
[sos] reformat sequence types in SoSOptions.__str__()
When formatting a human readable string representation of an
SoSOptions object, convert any sequence types (lists, tuples, or
deques) into a human readable string.
This gives output like:
onlyplugins=foo,bar,baz,qux
Rather than:
onlyplugins=[u'foo', u'bar', u'baz', u'qux']
This is used by --list-presets to produce lists of preset options
in command line notation:
options: --batch, --build, --debug=1, --onlyplugins=kernel,logs,
--verbosity=1
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/__init__.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/sos/__init__.py b/sos/__init__.py index 9526cd69..20fdf448 100644 --- a/sos/__init__.py +++ b/sos/__init__.py @@ -116,7 +116,19 @@ class SoSOptions(object): fmt += arg + arg_fmt + sep fmt.strip(sep) fmt += suffix - return fmt % tuple([getattr(self, arg) for arg in _arg_names]) + + def is_seq(val): + """Return true if val is an instance of a known sequence type. + """ + val_type = type(val) + return val_type is list or val_type is tuple + + if not quote: + # Convert Python source notation for sequences into plain strings + args = [getattr(self, arg) for arg in _arg_names] + args = [",".join(a) if is_seq(a) else a for a in args] + + return fmt % tuple(args) def __str__(self): return self.__str() |