diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2018-05-26 13:25:40 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2018-06-20 18:01:21 +0100 |
commit | f169089fcde06ac0953af81aa2b01e26ac4a9f74 (patch) | |
tree | fea8968655e5524a344e574efb482219eae4f28b | |
parent | 1e33fadeb225bfa14cbbe30e4606d3d79c323abf (diff) | |
download | sos-f169089fcde06ac0953af81aa2b01e26ac4a9f74.tar.gz |
[policies] add PresetDefaults infrastructure
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/policies/__init__.py | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py index 4eef8df0..2ad8b632 100644 --- a/sos/policies/__init__.py +++ b/sos/policies/__init__.py @@ -15,6 +15,7 @@ from sos.utilities import (ImporterHelper, shell_out) from sos.plugins import IndependentPlugin, ExperimentalPlugin from sos import _sos as _ +from sos import SoSOptions from textwrap import fill from six import print_ from six.moves import input @@ -182,6 +183,51 @@ class PackageManager(object): return self.verify_command + " " + verify_packages +class PresetDefaults(object): + """Preset command line defaults. + """ + #: Preset name, used for selection + name = None + #: Human readable preset description + desc = None + #: Notes on preset behaviour + note = None + #: Options set for this preset + opts = SoSOptions() + + #: Flag indicating whether this profile was read from disk + read = False + + def __str__(self): + """Return a human readable string representation of this + ``PresetDefaults`` object. + """ + return ("name=%s desc=%s note=%s opts=(%s)" % + (self.name, self.desc, self.note, str(self.opts))) + + def __repr__(self): + """Return a machine readable string representation of this + ``PresetDefaults`` object. + """ + return ("PresetDefaults(name='%s' desc='%s' note='%s' opts=(%s)" % + (self.name, self.desc, self.note, repr(self.opts))) + + def __init__(self, name="", desc="", note=None, opts=SoSOptions()): + """Initialise a new ``PresetDefaults`` object with the specified + arguments. + + :param name: The name of the new preset + :param desc: A description for the new preset + :param note: Note for the new preset + :param opts: Options set for the new preset + :returns: The newly initialised ``PresetDefaults`` + """ + self.name = name + self.desc = desc + self.note = note + self.opts = opts + + class Policy(object): msg = _("""\ @@ -208,7 +254,7 @@ No changes will be made to system configuration. PATH = "" default_scl_prefix = "" name_pattern = 'legacy' - + presets = {"": PresetDefaults()} _in_container = False _host_sysroot = '/' @@ -467,6 +513,20 @@ No changes will be made to system configuration. _fmt = _fmt + fill(line, width, replace_whitespace=False) + '\n' return _fmt + def find_preset(self, preset): + """Find a preset profile matching the specified preset string. + + :param preset: a string containing a preset profile name. + :returns: a matching ProductProfile. + """ + # FIXME: allow fuzzy matching? + for match in self.presets.keys(): + if match == preset: + return self.presets[match] + + # Return default preset + return self.presets[""] + class GenericPolicy(Policy): """This Policy will be returned if no other policy can be loaded. This |