From 0a1e74d985d176143c36ae98205cfb4275177248 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 31 Jul 2008 14:52:04 +0000
Subject: [PATCH] Split cli.SubmitOpCode in two parts

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 | 46 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 40 insertions(+), 6 deletions(-)

diff --git a/lib/cli.py b/lib/cli.py
index af05684f7..ca3e29985 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -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:
-- 
GitLab