Split cli.SubmitOpCode in two parts
authorIustin Pop <iustin@google.com>
Thu, 31 Jul 2008 14:52:04 +0000 (14:52 +0000)
committerIustin Pop <iustin@google.com>
Thu, 31 Jul 2008 14:52:04 +0000 (14:52 +0000)
The current SubmitOpCode function is not flexible enough to be used for
submitters that don't want to wait for the job finish.

The patch splits this in two, a SendJob function and a PollJob one, and
the old SubmitOpCode becomes a wrapper. Note that the new SendJob takes
a list of opcodes (and not a single opcode anymore).

Reviewed-by: imsnah

lib/cli.py

index af05684..ca3e299 100644 (file)
@@ -369,18 +369,36 @@ def AskUser(text, choices=None):
   return answer
 
 
-def SubmitOpCode(op, cl=None, feedback_fn=None):
-  """Legacy function to submit an opcode.
+def SendJob(ops, cl=None):
+  """Function to submit an opcode without waiting for the results.
 
-  This is just a simple wrapper over the construction of the processor
-  instance. It should be extended to better handle feedback and
-  interaction functions.
+  @type ops: list
+  @param ops: list of opcodes
+  @type cl: luxi.Client
+  @param cl: the luxi client to use for communicating with the master;
+             if None, a new client will be created
 
   """
   if cl is None:
     cl = GetClient()
 
-  job_id = cl.SubmitJob([op])
+  job_id = cl.SubmitJob(ops)
+
+  return job_id
+
+
+def PollJob(job_id, cl=None):
+  """Function to poll for the result of a job.
+
+  @type job_id: job identified
+  @param job_id: the job to poll for results
+  @type cl: luxi.Client
+  @param cl: the luxi client to use for communicating with the master;
+             if None, a new client will be created
+
+  """
+  if cl is None:
+    cl = GetClient()
 
   lastmsg = None
   while True:
@@ -413,6 +431,22 @@ def SubmitOpCode(op, cl=None, feedback_fn=None):
     raise errors.OpExecError(result)
 
 
+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
+  instance. It should be extended to better handle feedback and
+  interaction functions.
+
+  """
+  if cl is None:
+    cl = GetClient()
+
+  job_id = SendJob([op], cl)
+
+  return PollJob(job_id, cl)
+
+
 def GetClient():
   # TODO: Cache object?
   try: