Implement generic CLI options->opcode updates
authorIustin Pop <iustin@google.com>
Tue, 9 Feb 2010 13:02:18 +0000 (14:02 +0100)
committerIustin Pop <iustin@google.com>
Thu, 11 Feb 2010 11:49:27 +0000 (12:49 +0100)
This patch changes SubmitOpCode and SubmitOrSend such that we have a
single function that does generic CLI options to opcode attributes
function. This will allow, once all scripts pass the opts argument to
SubmitOpCode, to pass the debug parameter or the dry-run one to the LUs.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/cli.py

index 0283775..d420361 100644 (file)
@@ -1188,7 +1188,7 @@ def PollJob(job_id, cl=None, feedback_fn=None):
     raise errors.OpExecError(result)
 
 
-def SubmitOpCode(op, cl=None, feedback_fn=None):
+def SubmitOpCode(op, cl=None, feedback_fn=None, opts=None):
   """Legacy function to submit an opcode.
 
   This is just a simple wrapper over the construction of the processor
@@ -1199,6 +1199,8 @@ def SubmitOpCode(op, cl=None, feedback_fn=None):
   if cl is None:
     cl = GetClient()
 
+  SetGenericOpcodeOpts([op], opts)
+
   job_id = SendJob([op], cl)
 
   op_results = PollJob(job_id, cl=cl, feedback_fn=feedback_fn)
@@ -1214,16 +1216,35 @@ def SubmitOrSend(op, opts, cl=None, feedback_fn=None):
   whether to just send the job and print its identifier. It is used in
   order to simplify the implementation of the '--submit' option.
 
-  It will also add the dry-run parameter from the options passed, if true.
+  It will also process the opcodes if we're sending the via SendJob
+  (otherwise SubmitOpCode does it).
 
   """
-  if opts and opts.dry_run:
-    op.dry_run = opts.dry_run
   if opts and opts.submit_only:
-    job_id = SendJob([op], cl=cl)
+    job = [op]
+    SetGenericOpcodeOpts(job, opts)
+    job_id = SendJob(job, cl=cl)
     raise JobSubmittedException(job_id)
   else:
-    return SubmitOpCode(op, cl=cl, feedback_fn=feedback_fn)
+    return SubmitOpCode(op, cl=cl, feedback_fn=feedback_fn, opts=opts)
+
+
+def SetGenericOpcodeOpts(opcode_list, options):
+  """Processor for generic options.
+
+  This function updates the given opcodes based on generic command
+  line options (like debug, dry-run, etc.).
+
+  @param opcode_list: list of opcodes
+  @param options: command line options or None
+  @return: None (in-place modification)
+
+  """
+  if not options:
+    return
+  for op in opcode_list:
+    op.dry_run = options.dry_run
+    op.debug_level = options.debug
 
 
 def GetClient():