From 8400246fcecc3515052faa66238036bc2aaaeac5 Mon Sep 17 00:00:00 2001 From: "phoglund@webrtc.org" Date: Mon, 29 Jul 2013 11:01:03 +0000 Subject: [PATCH] Improved error messages when binaries are missing. Also stderr = stdout now. Now that these scripts are called from browser tests, we need to print everything on stdout since the tests will throw away stderr when invoking programs. I chose to assign sys.stderr to sys.stdout. Otherwise I would have missed stuff like parser.error, which print to stderr. The error message will get improved because the old code did not catch the case when the binary was missing, which lead to a very confusing error when that was the case. This gets fixed now. BUG= R=kjellander@webrtc.org Review URL: https://webrtc-codereview.appspot.com/1886004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4416 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/tools/barcode_tools/barcode_decoder.py | 22 +++++++++++++------ webrtc/tools/compare_videos.py | 7 ++++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/webrtc/tools/barcode_tools/barcode_decoder.py b/webrtc/tools/barcode_tools/barcode_decoder.py index f74fe7e30..0bf8b5b41 100755 --- a/webrtc/tools/barcode_tools/barcode_decoder.py +++ b/webrtc/tools/barcode_tools/barcode_decoder.py @@ -14,6 +14,10 @@ import sys import helper_functions +# Chrome browsertests will throw away stderr; avoid that output gets lost. +sys.stderr = sys.stdout + + def convert_yuv_to_png_files(yuv_file_name, yuv_frame_width, yuv_frame_height, output_directory, ffmpeg_dir=None): """Converts a YUV video file into PNG frames. @@ -47,8 +51,10 @@ def convert_yuv_to_png_files(yuv_file_name, yuv_frame_width, yuv_frame_height, helper_functions.run_shell_command( command, fail_msg='Error during YUV to PNG conversion') except helper_functions.HelperError, err: - print >> sys.stderr, 'Error executing command: %s. Error: %s' % (command, - err) + print 'Error executing command: %s. Error: %s' % (command, err) + return False + except OSError: + print ('Did not find %s. Have you installed it?' % ffmpeg_executable) return False return True @@ -101,8 +107,11 @@ def _decode_barcode_in_file(file_name, command_line_decoder): text_file.write(out) text_file.close() except helper_functions.HelperError, err: - print >> sys.stderr, 'Barcode in %s cannot be decoded.' % file_name - print >> sys.stderr, err + print 'Barcode in %s cannot be decoded.' % file_name + print err + return False + except OSError: + print ('Did not find %s. Have you installed it?' % command_line_decoder) return False return True @@ -263,14 +272,13 @@ def _main(): options.yuv_frame_height, output_directory=options.png_working_dir, ffmpeg_dir=options.ffmpeg_dir): - print >> sys.stderr, 'An error occurred converting from YUV to PNG frames.' + print 'An error occurred converting from YUV to PNG frames.' return -1 # Decode the barcodes from the PNG frames. if not decode_frames(input_directory=options.png_working_dir, zxing_dir=options.zxing_dir): - print >> sys.stderr, ('An error occurred decoding barcodes from PNG frames.' - ' Have you built the zxing C++ executable?') + print 'An error occurred decoding barcodes from PNG frames.' return -2 # Generate statistics file. diff --git a/webrtc/tools/compare_videos.py b/webrtc/tools/compare_videos.py index 5308b6291..0e0a4f659 100755 --- a/webrtc/tools/compare_videos.py +++ b/webrtc/tools/compare_videos.py @@ -15,6 +15,9 @@ import sys SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) +# Chrome browsertests will throw away stderr; avoid that output gets lost. +sys.stderr = sys.stdout + def _ParseArgs(): """Registers the command-line options.""" @@ -85,7 +88,7 @@ def main(): barcode_decoder = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr) barcode_decoder.wait() if barcode_decoder.returncode != 0: - print >> sys.stderr, 'Failed to run barcode decoder script.' + print 'Failed to run barcode decoder script.' return 1 # Run frame analyzer to compare the videos and print output. @@ -100,7 +103,7 @@ def main(): frame_analyzer = subprocess.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr) frame_analyzer.wait() if frame_analyzer.returncode != 0: - print >> sys.stderr, 'Failed to run frame analyzer.' + print 'Failed to run frame analyzer.' return 1 return 0