From 293ba2d8b9a8303b4dd82c0f71aa3fe3e243c52c Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 9 Feb 2010 14:02:18 +0100 Subject: [PATCH] Implement generic CLI options->opcode updates 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 | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index 02837757e..d420361a8 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -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(): -- GitLab