From 39451582c4d92c70e7ed91195aee01bf239e677f Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 4 May 2017 11:10:47 -0700 Subject: [PATCH] releasetools: Add a verbose parameter to common.Run(). Caller can optionally specify the verbose flag which overrides OPTIONS.verbose. The command line won't be outputed with verbose=False. This is useful for cases that a) those command lines are less useful (but will spam the output otherwise); b) sensitive info is part of the invocation. 'verbose=False' will be consumed by common.Run() only, instead of being passed to subprocess.Popen(). Test: ota_from_target_files.py on a block based OTA. Change-Id: I7d5b4094d756a60f84f89c6a965e7ccc68e435f8 --- tools/releasetools/blockimgdiff.py | 8 ++++---- tools/releasetools/common.py | 13 +++++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/releasetools/blockimgdiff.py b/tools/releasetools/blockimgdiff.py index e385866f0..b8123c09a 100644 --- a/tools/releasetools/blockimgdiff.py +++ b/tools/releasetools/blockimgdiff.py @@ -41,10 +41,10 @@ def compute_patch(srcfile, tgtfile, imgdiff=False): cmd = ['imgdiff', '-z'] if imgdiff else ['bsdiff'] cmd.extend([srcfile, tgtfile, patchfile]) - # Not using common.Run(), which would otherwise dump all the bsdiff/imgdiff - # commands when OPTIONS.verbose is True - not useful for the case here, since - # they contain temp filenames only. - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + # Don't dump the bsdiff/imgdiff commands, which are not useful for the case + # here, since they contain temp filenames only. + p = common.Run(cmd, verbose=False, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) output, _ = p.communicate() if p.returncode != 0: diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py index e200f9f65..925a5231f 100644 --- a/tools/releasetools/common.py +++ b/tools/releasetools/common.py @@ -107,10 +107,15 @@ class ExternalError(RuntimeError): pass -def Run(args, **kwargs): - """Create and return a subprocess.Popen object, printing the command - line on the terminal if -v was specified.""" - if OPTIONS.verbose: +def Run(args, verbose=None, **kwargs): + """Create and return a subprocess.Popen object. + + Caller can specify if the command line should be printed. The global + OPTIONS.verbose will be used if not specified. + """ + if verbose is None: + verbose = OPTIONS.verbose + if verbose: print(" running: ", " ".join(args)) return subprocess.Popen(args, **kwargs)