summaryrefslogtreecommitdiff
path: root/testing/tools/common.py
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2017-08-15 14:37:58 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-15 20:02:20 +0000
commit0da39e6b62fe7dc0f40d5242325b3b2d5b2c9d96 (patch)
treed7d63a35b983e3c3b8a865c0fc97c9d762e74649 /testing/tools/common.py
parent5f7b8f4038d16d224cb070f08112aba5331bd094 (diff)
downloadpdfium-0da39e6b62fe7dc0f40d5242325b3b2d5b2c9d96.tar.xz
Make errors in called processes more evident and easier to debug.
Also trying to get unicode filenames right again. Change-Id: I501c94921b92b8a8cd6a10441aff1595fc6d878e Reviewed-on: https://pdfium-review.googlesource.com/10630 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'testing/tools/common.py')
-rwxr-xr-xtesting/tools/common.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/testing/tools/common.py b/testing/tools/common.py
index 737169f8d3..fc16004210 100755
--- a/testing/tools/common.py
+++ b/testing/tools/common.py
@@ -3,6 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import datetime
import glob
import os
import re
@@ -26,6 +27,38 @@ def RunCommand(cmd):
except subprocess.CalledProcessError as e:
return e
+
+def RunCommandPropagateErr(cmd, stdout_has_errors=False,
+ exit_status_on_error=None):
+ """Run a command as a subprocess.
+
+ Errors in that subprocess are printed out if it returns an error exit code.
+
+ Args:
+ cmd: Command to run as a list of strings.
+ stdout_has_errors: Whether to print stdout instead of stderr on an error
+ exit.
+ exit_status_on_error: If specified, upon an error in the subprocess the
+ caller script exits immediately with the given status.
+ """
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ output, err = p.communicate()
+
+ if p.returncode:
+ PrintErr('\nError when invoking "%s"' % ' '.join(cmd))
+ if stdout_has_errors:
+ PrintErr(output)
+
+ PrintErr(err)
+
+ if exit_status_on_error is not None:
+ sys.exit(exit_status_on_error)
+
+ return None
+
+ return output
+
+
# RunCommandExtractHashedFiles returns a tuple: (raised_exception, hashed_files)
# It runs the given command. If it fails it will return an exception and None.
# If it succeeds it will return None and the list of processed files extracted
@@ -110,3 +143,14 @@ def GetBooleanGnArg(arg_name, build_dir, verbose=False):
if verbose:
print >> sys.stderr, "Found '%s' for value of %s" % (arg_match_output, arg)
return arg_match_output == 'true'
+
+
+def PrintWithTime(s):
+ """Prints s prepended by a timestamp."""
+ print '[%s] %s' % (datetime.datetime.now().strftime("%Y%m%d %H:%M:%S"),
+ s)
+
+
+def PrintErr(s):
+ """Prints s to stderr."""
+ print >> sys.stderr, s