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
This commit is contained in:
@ -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()
|
||||
|
||||
|
@ -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__':
|
||||
|
@ -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()
|
||||
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 'Error: ', error
|
||||
print 'Failed to execute: %s\nError: %s' % (' '.join(cmd), stderr)
|
||||
else:
|
||||
print output
|
||||
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
|
||||
|
||||
|
||||
|
@ -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.
|
||||
|
||||
|
Reference in New Issue
Block a user