diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2018-05-27 12:14:49 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2018-06-20 18:01:21 +0100 |
commit | f64a94e6a8cf809914c29a4562ee3231a2ef47b7 (patch) | |
tree | b3bc47c572831da1c9749058ee682027aaded87c | |
parent | 464b26e42bee5cbade7b0df0b93aea7d26078a92 (diff) | |
download | sos-f64a94e6a8cf809914c29a4562ee3231a2ef47b7.tar.gz |
[sos] add SoSOptions.dict()
Add a method to convert an SoSOptions() instance into a dict:
the keys of the dictionary are the argument names and the values
are the current option values.
Any argument with a deque() value is converted to a plain list
prior to processing.
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/__init__.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/sos/__init__.py b/sos/__init__.py index ff3153aa..f169f369 100644 --- a/sos/__init__.py +++ b/sos/__init__.py @@ -16,7 +16,6 @@ gettext to internationalize messages. """ import gettext -from collections import deque __version__ = "3.5" @@ -172,4 +171,19 @@ class SoSOptions(object): if replace or not getattr(self, arg): self._copy_opt(arg, src) + def dict(self): + """Return this ``SoSOptions`` option values as a dictionary of + argument name to value mappings. + + :returns: a name:value dictionary of option values. + """ + odict = {} + for arg in _arg_names: + value = getattr(self, arg) + # Do not attempt to store --add-preset <name> in presets + if arg == 'add_preset': + value = None + odict[arg] = value + return odict + # vim: set et ts=4 sw=4 : |