summaryrefslogtreecommitdiffstats
path: root/firstaidkit
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2008-03-05 14:15:36 +0100
committerMartin Sivak <msivak@redhat.com>2008-03-05 14:15:36 +0100
commitb9e406a6255e2f0f14c966acb492f2d4e8d3da8c (patch)
tree5f61f9abc34145ca14143ad72785d5262da93915 /firstaidkit
parent379616173fb52318300334efdee234a251ad8302 (diff)
downloadfirstaidkit-b9e406a6255e2f0f14c966acb492f2d4e8d3da8c.tar.gz
firstaidkit-b9e406a6255e2f0f14c966acb492f2d4e8d3da8c.tar.xz
firstaidkit-b9e406a6255e2f0f14c966acb492f2d4e8d3da8c.zip
Sanitize the origin/level/importance system
Use reporting when possible (some messages automatically use Logger to avoid duplication) Improve the Output thread to use the new level/importance system
Diffstat (limited to 'firstaidkit')
-rwxr-xr-xfirstaidkit54
1 files changed, 48 insertions, 6 deletions
diff --git a/firstaidkit b/firstaidkit
index c0012f1..2c23c51 100755
--- a/firstaidkit
+++ b/firstaidkit
@@ -16,7 +16,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-import sys, getopt, os
+import sys, getopt, os, pprint, logging
from threading import Thread
from pyfirstaidkit import Tasker
from pyfirstaidkit import Config
@@ -28,18 +28,56 @@ class Flags:
main_help = False
class Output(Thread):
- def __init__(self, queue, *args, **kwargs):
+ def __init__(self, queue, importance = logging.INFO, *args, **kwargs):
+ Thread.__init__(self, *args, **kwargs)
self._running = True
self._queue = queue
- Thread.__init__(self, *args, **kwargs)
+ self._importance = importance
def run(self):
+ levelstack = []
+
while self._running:
message = self._queue.get()
- if message["semantics"]==reporting.END:
+
+ if message["action"]==reporting.END:
self._running = False
continue
- print message
+ elif message["action"]==reporting.QUESTION:
+ print "FIXME: Questions not implemented yet"
+ elif message["action"]==reporting.START:
+ if self._importance<=message["importance"]:
+ print "START: %s (%s)" % (message["origin"].name, message["message"])
+ levelstack.append(message["origin"].name)
+ elif message["action"]==reporting.STOP:
+ if self._importance<=message["importance"]:
+ print "STOP: %s (%s)" % (message["origin"].name, message["message"])
+ if levelstack[-1]!=message["origin"].name:
+ print "WARNING: START/STOP ordering mismatch in stack: "+" / ".join(levelstack)
+ else:
+ levelstack.pop()
+ elif message["action"]==reporting.PROGRESS:
+ if self._importance<=message["importance"]:
+ print "PROGRESS: %d of %d (%s)" % (message["message"][0], message["message"][1], message["origin"].name)
+ elif message["action"]==reporting.INFO:
+ if self._importance<=message["importance"]:
+ print "INFO: %s (%s)" % (message["message"], message["origin"].name)
+ elif message["action"]==reporting.ALERT:
+ if self._importance<=message["importance"]:
+ print "ALERT: %s (%s)" % (message["message"], message["origin"].name)
+ elif message["action"]==reporting.EXCEPTION:
+ print "EXCEPTION: %s (%s)" % (message["message"], message["origin"].name)
+ elif message["action"]==reporting.TABLE:
+ if self._importance<=message["importance"]:
+ print "TABLE %s FROM %s" % (message["title"], message["origin"].name,)
+ pprint.pprint(message["message"])
+ elif message["action"]==reporting.TREE:
+ if self._importance<=message["importance"]:
+ print "TREE %s FROM %s" % (message["title"], message["origin"].name,)
+ pprint.pprint(message["message"])
+ else:
+ print "FIXME: Unknown message action %d!!" % (message["action"],)
+ print message
def usage(name):
print """Usage:
@@ -145,7 +183,11 @@ if __name__=="__main__":
singlerun = Tasker(Config)
- outputThread = Output(singlerun.reporting())
+ if not Config.operation.verbose:
+ outputThread = Output(singlerun.reporting())
+ else:
+ outputThread = Output(singlerun.reporting(), importance = 0)
+
outputThread.start()
try: