summaryrefslogtreecommitdiffstats
path: root/pyfirstaidkit
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2008-04-22 18:07:55 +0200
committerMartin Sivak <msivak@redhat.com>2008-04-22 18:07:55 +0200
commitd9a16bf880cc2e160cc5d0b2623becbe8807d704 (patch)
tree5fd99a82f7c6d5740635f3d6c40e81ed020a0bdf /pyfirstaidkit
parent0c003591bbc305977924099ad813eb2723cb657d (diff)
downloadfirstaidkit-d9a16bf880cc2e160cc5d0b2623becbe8807d704.tar.gz
firstaidkit-d9a16bf880cc2e160cc5d0b2623becbe8807d704.tar.xz
firstaidkit-d9a16bf880cc2e160cc5d0b2623becbe8807d704.zip
Add ISSUE message to reporting and create SimpleIssue as a parent for Issue class (so everybody can use something simple to report state)
Diffstat (limited to 'pyfirstaidkit')
-rw-r--r--pyfirstaidkit/issue.py69
-rw-r--r--pyfirstaidkit/plugins.py7
-rw-r--r--pyfirstaidkit/reporting.py5
3 files changed, 49 insertions, 32 deletions
diff --git a/pyfirstaidkit/issue.py b/pyfirstaidkit/issue.py
index aa84be5..a02629f 100644
--- a/pyfirstaidkit/issue.py
+++ b/pyfirstaidkit/issue.py
@@ -19,13 +19,48 @@
# the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
# 02139, USA.
-class Issue(object):
+class SimpleIssue(object):
+ def __init__(self, name, description):
+ self.name = name
+ self.description = description
+ self.reset()
+
+ def reset(self):
+ """Reset the object's state"""
+ self._detected = False
+ self._happened = False
+ self._fixed = False
+
+ def __str__(self):
+ s = []
+ if self._fixed:
+ s.append("Fixed")
+ elif self._happened and self._detected:
+ s.append("Detected")
+ elif self._detected:
+ s.append("No problem with")
+ else:
+ s.append("Waiting for check on")
+
+ s.append(self.name)
+
+ if self._happened and self._detected:
+ s.append("--")
+ s.append(self.description)
+
+ return " ".join(s)
+
+ def str(self):
+ return self.__str__()
+
+class Issue(SimpleIssue):
name = "Parent issue"
description = "This happens when you use the wrong object in the issues list"
- def __init__(self, plugin):
+ def __init__(self, plugin, reporting = None):
+ SimpleIssue.__init__(self, self.name, self.description)
self._plugin = plugin
- self.reset()
+ self._reporting = reporting
def detect(self):
"""Detect if this situation happened and store some information about it, so we can fix it
@@ -80,31 +115,3 @@ Return values:
#issue didn't happened or is fixed -> True
return not self._happened or self._fixed
- def reset(self):
- """Reset the object's state"""
- self._detected = False
- self._happened = False
- self._fixed = False
-
- def __str__(self):
- s = []
- if self._fixed:
- s.append("Fixed")
- elif self._happened and self._detected:
- s.append("Detected")
- elif self._detected:
- s.append("No problem with")
- else:
- s.append("Waiting for check on")
-
- s.append(self.name)
-
- if self._happened and self._detected:
- s.append("--")
- s.append(self.description)
-
- return " ".join(s)
-
- def str(self):
- return self.__str__()
-
diff --git a/pyfirstaidkit/plugins.py b/pyfirstaidkit/plugins.py
index 6bef7da..73d1da4 100644
--- a/pyfirstaidkit/plugins.py
+++ b/pyfirstaidkit/plugins.py
@@ -316,7 +316,9 @@ Just fill the issue_tests list with classes describing the tests and let it run.
"""Prepare the issues list"""
for i in self.issue_tests:
self._reporting.info(level = TASK, origin = self, message = "Preparing tests for '%s'" % (i.name,))
- self.tests.append(i(plugin = self))
+ issue = i(plugin = self)
+ self.tests.append(issue)
+ self._reporting.issue(level = TASK, origin = self, issue = issue)
self._result=ReturnSuccess
def diagnose(self):
@@ -327,6 +329,7 @@ Just fill the issue_tests list with classes describing the tests and let it run.
for i in self.tests:
self._reporting.info(level = TASK, origin = self, message = "Investigating '%s'" % (i.name,))
result = result or i.detect()
+ self._reporting.issue(level = TASK, origin = self, issue = i)
if i.happened():
happened = True
self._reporting.info(level = TASK, origin = self, message = i.str())
@@ -348,12 +351,14 @@ Just fill the issue_tests list with classes describing the tests and let it run.
for i in self.tests:
self._reporting.info(level = TASK, origin = self, message = "Fixing '%s'" % (i.name,))
result = result or i.fix()
+ self._reporting.issue(level = TASK, origin = self, issue = i)
if not i.fixed():
fixed = False
continue
i.reset()
if not i.detect() or i.happened():
+ self._reporting.issue(level = TASK, origin = self, issue = i)
fixed = False
if result and fixed:
diff --git a/pyfirstaidkit/reporting.py b/pyfirstaidkit/reporting.py
index 98018f7..203bb1f 100644
--- a/pyfirstaidkit/reporting.py
+++ b/pyfirstaidkit/reporting.py
@@ -38,6 +38,7 @@ ALERT = 4
EXCEPTION = 5
TABLE = 6 #types for arbitrary table-like organized iterables
TREE = 7 #nested iterables organized as tree
+ISSUE = 8 #New issue object was created or changed
QUESTION = 999 #type of message which contains respond-to field
END = 1000 #End of operations, final message
@@ -134,6 +135,10 @@ class Reports(object):
def progress(self, position, maximum, level, origin, importance = logging.INFO):
return self.put((position, maximum), level, origin, PROGRESS, importance = importance)
+ def issue(self, issue, level, origin, importance = logging.INFO):
+ Logger.debug(origin.name+": issue changed state to "+str(issue))
+ return self.put(issue, level, origin, INFO, importance = importance)
+
def info(self, message, level, origin, importance = logging.INFO):
Logger.info(origin.name+": "+message)
return self.put(message, level, origin, INFO, importance = importance)