Improve cli.SubmitOpCode
authorIustin Pop <iustin@google.com>
Mon, 14 Jul 2008 13:38:14 +0000 (13:38 +0000)
committerIustin Pop <iustin@google.com>
Mon, 14 Jul 2008 13:38:14 +0000 (13:38 +0000)
Currently, the feedback_fn argument to SubmitOpCode is no longer used.
We still need it in burnin, so we re-enable it by making the code call
that function with the msg argument in case feedback_fn is callable. The
patch also modifies burnin to accept the new argument format (msg is not
a triple instead of a string).

The patch also removes the ‘proc’ argument as it's obsolete; instead we
can accept a luxi.Client instance (noone uses this right now).

Reviewed-by: ultrotter

lib/cli.py
tools/burnin

index 34a2bfb..1eab656 100644 (file)
@@ -369,7 +369,7 @@ def AskUser(text, choices=None):
   return answer
 
 
-def SubmitOpCode(op, proc=None, feedback_fn=None):
+def SubmitOpCode(op, cl=None, feedback_fn=None):
   """Legacy function to submit an opcode.
 
   This is just a simple wrapper over the construction of the processor
@@ -377,8 +377,8 @@ def SubmitOpCode(op, proc=None, feedback_fn=None):
   interaction functions.
 
   """
-  # TODO: Fix feedback_fn situation.
-  cl = luxi.Client()
+  if cl is None:
+    cl = luxi.Client()
 
   job_id = cl.SubmitJob([op])
 
@@ -395,7 +395,10 @@ def SubmitOpCode(op, proc=None, feedback_fn=None):
       break
     msg = jobs[0][1]
     if msg is not None and msg != lastmsg:
-      print "%s %s" % (time.ctime(msg[0]), msg[2])
+      if callable(feedback_fn):
+        feedback_fn(msg)
+      else:
+        print "%s %s" % (time.ctime(msg[0]), msg[2])
     lastmsg = msg
     time.sleep(1)
 
index 339a7e2..cfa848a 100755 (executable)
@@ -26,6 +26,7 @@
 import os
 import sys
 import optparse
+import time
 from itertools import izip, islice, cycle
 from cStringIO import StringIO
 
@@ -81,15 +82,14 @@ class Burner(object):
 
   def Feedback(self, msg):
     """Acumulate feedback in our buffer."""
-    self._feed_buf.write(msg)
-    self._feed_buf.write("\n")
+    self._feed_buf.write("%s %s\n" % (time.ctime(msg[0]), msg[2]))
     if self.opts.verbose:
       Log(msg)
 
   def ExecOp(self, op):
     """Execute an opcode and manage the exec buffer."""
     self.ClearFeedbackBuf()
-    return cli.SubmitOpCode(op)
+    return cli.SubmitOpCode(op, feedback_fn=self.Feedback)
 
   def ParseOptions(self):
     """Parses the command line options.