From 276e51bdcc7fda8231376964f23d182d0ed026a4 Mon Sep 17 00:00:00 2001 From: Michele Tartara Date: Tue, 26 Mar 2013 13:58:53 +0100 Subject: [PATCH] Add the reason trail to the opcodes The reason trail is available for all the opcodes, and as such it is initialized as a generic option. Signed-off-by: Michele Tartara Reviewed-by: Helga Velroyen --- lib/cli.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/cli.py b/lib/cli.py index db211aa..cd19384 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -2199,6 +2199,31 @@ def SubmitOrSend(op, opts, cl=None, feedback_fn=None): return SubmitOpCode(op, cl=cl, feedback_fn=feedback_fn, opts=opts) +def _InitReasonTrail(op, opts): + """Builds the first part of the reason trail + + Builds the initial part of the reason trail, adding the user provided reason + (if it exists) and the name of the command starting the operation. + + @param op: the opcode the reason trail will be added to + @param opts: the command line options selected by the user + + """ + assert len(sys.argv) >= 2 + trail = [] + + if opts.reason: + trail.append((constants.OPCODE_REASON_SRC_USER, + opts.reason, + utils.EpochNano())) + + binary = os.path.basename(sys.argv[0]) + source = "%s:%s" % (constants.OPCODE_REASON_SRC_CLIENT, binary) + command = sys.argv[1] + trail.append((source, command, utils.EpochNano())) + op.reason = trail + + def SetGenericOpcodeOpts(opcode_list, options): """Processor for generic options. @@ -2218,6 +2243,7 @@ def SetGenericOpcodeOpts(opcode_list, options): op.dry_run = options.dry_run if getattr(options, "priority", None) is not None: op.priority = options.priority + _InitReasonTrail(op, options) def GetClient(query=False): -- 1.7.10.4