diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2019-08-16 13:06:38 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2019-08-16 14:17:37 +0100 |
commit | c2a2b6579f580baad69dc5b9815a4082c889f3b4 (patch) | |
tree | bc866993dedcc3d00f4a05b7a71b5af5c289c38e | |
parent | 3af7c6843f653760d3010c2f74214706c52e7141 (diff) | |
download | sos-c2a2b6579f580baad69dc5b9815a4082c889f3b4.tar.gz |
[SoSPredicate] make predicate evaluation members public
The predicate values used to evaluate a SoSPredicate are useful
to code outside the class and can be safely read and set by plugin
code: make these members public to allow details of predicate state
to be more easily reported by generic Plugin code.
Related: #1678
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/plugins/__init__.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 66c26470..c550911a 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -106,26 +106,26 @@ class SoSPredicate(object): _owner = None #: Skip all collection? - _dry_run = False + dry_run = False #: Kernel module enablement list - _kmods = [] + kmods = [] #: Services enablement list - _services = [] + services = [] def __str(self, quote=False, prefix="", suffix=""): """Return a string representation of this SoSPredicate with optional prefix, suffix and value quoting. """ quotes = '"%s"' - pstr = "dry_run=%s, " % self._dry_run + pstr = "dry_run=%s, " % self.dry_run - kmods = self._kmods + kmods = self.kmods kmods = [quotes % k for k in kmods] if quote else kmods pstr += "kmods=[%s], " % (",".join(kmods)) - services = self._services + services = self.services services = [quotes % s for s in services] if quote else services pstr += "services=[%s]" % (",".join(services)) @@ -150,25 +150,25 @@ class SoSPredicate(object): """Predicate evaluation hook. """ pvalue = False - for k in self._kmods: + for k in self.kmods: pvalue |= self._owner.is_module_loaded(k) - for s in self._services: + for s in self.services: pvalue |= self._owner.service_is_running(s) # Null predicate? - if not any([self._kmods, self._services, self._dry_run]): + if not any([self.kmods, self.services, self.dry_run]): return True - return pvalue and not self._dry_run + return pvalue and not self.dry_run def __init__(self, owner, dry_run=False, kmods=[], services=[]): """Initialise a new SoSPredicate object. """ self._owner = owner - self._kmods = list(kmods) - self._services = list(services) - self._dry_run = dry_run | self._owner.commons['cmdlineopts'].dry_run + self.kmods = list(kmods) + self.services = list(services) + self.dry_run = dry_run | self._owner.commons['cmdlineopts'].dry_run class SoSCommand(object): |