aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2018-05-26 16:48:34 +0100
committerBryn M. Reeves <bmr@redhat.com>2018-06-20 18:01:21 +0100
commit8c6d69af0b552fab3c371947c694a7f1187054f7 (patch)
tree2f0078f57f43905899349292be8a860b71087048
parent70eae2a8fde8dd6e85306b70dfa8c0228ca54411 (diff)
downloadsos-8c6d69af0b552fab3c371947c694a7f1187054f7.tar.gz
[sos] add __str__ and __repr__ to SoSOptions
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/__init__.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/sos/__init__.py b/sos/__init__.py
index 6b165324..9ec9166a 100644
--- a/sos/__init__.py
+++ b/sos/__init__.py
@@ -94,6 +94,37 @@ class SoSOptions(object):
for arg in _arg_names:
self._copy_opt(arg, src)
+ def __str(self, quote=False, sep=" ", prefix="", suffix=""):
+ """Format a SoSOptions object as a human or machine readable string.
+
+ :param quote: quote option values
+ :param sep: list separator string
+ :param prefix: arbitrary prefix string
+ :param suffix: arbitrary suffix string
+ :param literal: print values as Python literals
+ """
+ fmt = prefix
+ arg_fmt = "=%s" if not quote else "='%s'"
+ for arg in _arg_names:
+ fmt += arg + arg_fmt + sep
+ fmt.strip(sep)
+ fmt += suffix
+ return fmt % (self.all_logs, self.batch, self.build, self.case_id,
+ self.chroot, self.compression_type, self.config_file,
+ self.debug, self.enableplugins, self.experimental,
+ self.label, self.list_plugins, self.list_profiles,
+ self.log_size, self.noplugins, self.noreport,
+ self.onlyplugins, self.plugopts, self.product,
+ self.profiles, self.quiet, self.sysroot, self.tmp_dir,
+ self.usealloptions, self.verbosity, self.verify)
+
+ def __str__(self):
+ return self.__str()
+
+ def __repr__(self):
+ return self.__str(quote=True, sep=", ", prefix="SoSOptions(",
+ suffix=")")
+
def __init__(self, **kwargs):
"""Initialise a new ``SoSOptions`` object from keyword arguments.
@@ -135,7 +166,6 @@ class SoSOptions(object):
:param replace: ``True`` if non-default values should be
overwritten.
"""
-
for arg in _arg_names:
if not hasattr(src, arg):
continue