diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2018-05-27 15:30:57 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2018-06-20 18:01:21 +0100 |
commit | 9a1b87750deaa069d4dd4c41056c4a500125af33 (patch) | |
tree | 53ddc3e0785b164914ba5e13b986a0e946b4275d | |
parent | 691c51247ad2dd416dbe3d1807bfc2f9afd31d63 (diff) | |
download | sos-9a1b87750deaa069d4dd4c41056c4a500125af33.tar.gz |
[sosreport] beautify --list-presets output
Re-format the output of --list-presets to be more compact and
readable: add labels for each field (name, description, notes,
and options), right justify all field labels to 15 chars, and
convert SoSOptions() string representations into command line
argument notation.
logs-only : A preset to only run the logs plugin
opts: all_logs=False, batch=False, build=False, case_id=,
chroot=auto, compression_type=auto, config_file=, debug=False,
enableplugins=[], experimental=False, label=,
list_plugins=False, list_presets=False, list_profiles=False,
log_size=10, noplugins=[], noreport=False, onlyplugins=[],
plugopts=[], preset=, profiles=deque([]), quiet=False,
sysroot=None, tmp_dir=, usealloptions=False, verbosity=0,
verify=False
Vs.:
name: logs-only
description: A preset to only run the logs plugin
options: --onlyplugins=logs
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/sosreport.py | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/sos/sosreport.py b/sos/sosreport.py index 6b5f7dc8..80eb773e 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -860,20 +860,45 @@ class SoSReport(object): for preset in self.policy.presets.keys(): if not preset: continue - preset = self.policy.presets[preset] - self.ui_log.info("%-15s %s" % (preset.name, preset.desc)) + preset = self.policy.find_preset(preset) + self.ui_log.info("%14s %s" % ("name:", preset.name)) + self.ui_log.info("%14s %s" % ("description:", preset.desc)) if preset.note: - self.ui_log.info("%-15s (%s)" % ("", preset.note)) + self.ui_log.info("%14s %s" % ("note:", preset.note)) if self.opts.verbosity > 0: - # Filter out options that do not make sense in presets def filter_opt(opt): + """ Filter out preset options. + """ opt = opt.split("=")[0] if opt in ("add_preset", "del_preset", "desc", "note"): return False return True + + def argify(opt): + """ Convert sos option notation to command line arguments. + """ + arg = "--" + opt + arg = arg.replace("_", "-") + arg = arg.strip("=True") + return arg + + def has_value(opt): + """ Test for null option values. + """ + null_values = ("False", "None", "[]", '""', "''", "0") + (opt_name, opt_value) = opt.split("=") + if opt_name in _arg_defaults: + if opt_value == str(_arg_defaults[opt_name]): + return False + if not opt_value or opt_value in null_values: + return False + return True + opts = str(preset.opts).split() opts = [opt for opt in opts if filter_opt(opt)] - lines = _format_list("%-15s" % "options: ", opts, indent=True) + args = [argify(opt) for opt in opts if has_value(opt)] + options_str = "%14s " % "options:" + lines = _format_list(options_str, args, indent=True, sep=' ') for line in lines: self.ui_log.info(line) self.ui_log.info("") |