From 1b0a02e12e4ebec15903b6573db9f8b1bb75701d Mon Sep 17 00:00:00 2001 From: "vspasova@webrtc.org" Date: Thu, 30 Aug 2012 12:56:38 +0000 Subject: [PATCH] Fixing a path and Ant invocation issue in build_zxing.py and delete_file issue in helper_functions.py Review URL: https://webrtc-codereview.appspot.com/761006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2688 4adac7df-926f-26a2-2b94-8c16560cd09d --- tools/barcode_tools/barcode_decoder.py | 4 ++-- tools/barcode_tools/barcode_encoder.py | 13 ++++++++---- tools/barcode_tools/build_zxing.py | 28 ++++++++++++++++--------- tools/barcode_tools/helper_functions.py | 16 -------------- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/tools/barcode_tools/barcode_decoder.py b/tools/barcode_tools/barcode_decoder.py index e076758080..b016219789 100755 --- a/tools/barcode_tools/barcode_decoder.py +++ b/tools/barcode_tools/barcode_decoder.py @@ -129,7 +129,7 @@ def _generate_stats_file(stats_file_name, input_directory='.'): if os.path.isfile(barcode_file_name): barcode = _read_barcode_from_text_file(barcode_file_name) - helper_functions.delete_file(barcode_file_name) + os.remove(barcode_file_name) if _check_barcode(barcode): entry += (helper_functions.zero_pad(int(barcode[0:11])) + '\n') @@ -139,7 +139,7 @@ def _generate_stats_file(stats_file_name, input_directory='.'): entry += 'Barcode error\n' stats_file.write(entry) - helper_functions.delete_file(png_frame) + os.remove(png_frame) stats_file.close() diff --git a/tools/barcode_tools/barcode_encoder.py b/tools/barcode_tools/barcode_encoder.py index 4c943b81ea..429866e4fc 100755 --- a/tools/barcode_tools/barcode_encoder.py +++ b/tools/barcode_tools/barcode_encoder.py @@ -110,10 +110,10 @@ def _convert_to_yuv_and_delete(output_directory, file_name, pattern): helper_functions.run_shell_command( command, msg=('Error during PNG to YUV conversion of %s' % file_name)); - helper_functions.delete_file(file_name) + os.remove(file_name) except helper_functions.HelperError, err: print err - return Flase + return False return True @@ -152,7 +152,12 @@ def _add_to_file_and_delete(output_file, file_name): input_file_contents = input_file.read() output_file.write(input_file_contents) input_file.close() - return helper_functions.delete_file(file_name) + try: + os.remove(file_name) + except Exception as e: + sys.stderr.write('Error in deleting file %s' % file_name) + return False + return True def _overlay_barcode_and_base_frames(barcodes_file, base_file, output_file, @@ -346,7 +351,7 @@ def _main(): if not keep_barcodes_yuv_file: # Remove the temporary barcodes YUV file - helper_functions.delete_file(options.barcodes_yuv) + os.remove(options.barcodes_yuv) if __name__ == '__main__': diff --git a/tools/barcode_tools/build_zxing.py b/tools/barcode_tools/build_zxing.py index 0f49c85d6e..62a29efae9 100644 --- a/tools/barcode_tools/build_zxing.py +++ b/tools/barcode_tools/build_zxing.py @@ -7,25 +7,33 @@ # in the file PATENTS. All contributing project authors may # be found in the AUTHORS file in the root of the source tree. +import os import subprocess import sys def run_ant_build_command(path_to_ant_build_file): """Tries to build the passed build file with ant.""" - process = subprocess.Popen([ - 'ant', '-buildfile', '%s' % path_to_ant_build_file], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - output, error = process.communicate() - if process.returncode != 0: - print 'Error: ', error - else: - print output + ant_suffix = '.bat' if 'win32' in sys.platform else '' + cmd = ['ant%s' % ant_suffix, '-buildfile', path_to_ant_build_file] + try: + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + if process.returncode != 0: + print 'Failed to execute: %s\nError: %s' % (' '.join(cmd), stderr) + else: + print stdout + except Exception as e: + print 'Failed to execute: %s\nError: %s' % (' '.join(cmd), e) def _main(): - run_ant_build_command('third_party/zxing/core/build.xml') - run_ant_build_command('third_party/zxing/javase/build.xml') + core_build = os.path.join('third_party', 'zxing', 'core', 'build.xml') + run_ant_build_command(core_build) + + javase_build = os.path.join('third_party', 'zxing', 'javase', 'build.xml') + run_ant_build_command(javase_build) return 0 diff --git a/tools/barcode_tools/helper_functions.py b/tools/barcode_tools/helper_functions.py index cdd0219abe..74ff06452d 100644 --- a/tools/barcode_tools/helper_functions.py +++ b/tools/barcode_tools/helper_functions.py @@ -34,22 +34,6 @@ def zero_pad(number, padding=_DEFAULT_PADDING): return str(number).zfill(padding) -def delete_file(file_name): - """Deletes the file with file_name. - - Args: - file_name(string): The file to be deleted. - Return: - (bool): True on success, False otherwise. - """ - try: - subprocess.check_call(['rm', '%s' % file_name]) - except subprocess.CalledProcessError, err: - sys.stderr.write('Error in deleting file %s' % file_name) - return False - return True - - def run_shell_command(command, msg=None): """Executes a command.