Revert of PyLint fixes for tools-webrtc and webrtc/tools (patchset #3 id:40001 of https://codereview.webrtc.org/2736233003/ )
Reason for revert:
Fails video quality tests in Chrome: http://build.chromium.org/p/chromium.webrtc.fyi/builders/Win10%20Tester/builds/6568
I should have looked more closer at those :(
Original issue's description:
> PyLint fixes for tools-webrtc and webrtc/tools
>
> Fix a lot of errors before bringing in the new config in
> https://codereview.webrtc.org/2737963003/
>
> BUG=webrtc:7303
> NOTRY=True
>
> Review-Url: https://codereview.webrtc.org/2736233003
> Cr-Commit-Position: refs/heads/master@{#17137}
> Committed: https://chromium.googlesource.com/external/webrtc/+/f5318e1f391859c82aaa47b297429e50f41f6b3c
TBR=oprypin@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7303
Review-Url: https://codereview.webrtc.org/2737233003
Cr-Original-Commit-Position: refs/heads/master@{#17142}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 94f4d9effc3fa1ee6a6a48a7bbdef6684defd1dc
diff --git a/examples/androidtests/video_quality_loopback_test.py b/examples/androidtests/video_quality_loopback_test.py
index 7c7ef31..5ef8537 100755
--- a/examples/androidtests/video_quality_loopback_test.py
+++ b/examples/androidtests/video_quality_loopback_test.py
@@ -89,10 +89,10 @@
ffmpeg_path = os.path.join(toolchain_dir, 'linux', 'ffmpeg')
- def ConvertVideo(input_video, output_video):
+ def convert_video(input_video, output_video):
_RunCommand([ffmpeg_path, '-y', '-i', input_video, output_video])
- ConvertVideo(test_video, test_video_yuv)
+ convert_video(test_video, test_video_yuv)
reference_video = os.path.join(SRC_DIR,
'resources', 'reference_video_640x360_30fps.y4m')
@@ -100,7 +100,7 @@
reference_video_yuv = os.path.join(temp_dir,
'reference_video_640x360_30fps.yuv')
- ConvertVideo(reference_video, reference_video_yuv)
+ convert_video(reference_video, reference_video_yuv)
# Run compare script.
compare_script = os.path.join(SRC_DIR, 'webrtc', 'tools',
diff --git a/tools/barcode_tools/barcode_decoder.py b/tools/barcode_tools/barcode_decoder.py
index 41164aa..e615fa8 100755
--- a/tools/barcode_tools/barcode_decoder.py
+++ b/tools/barcode_tools/barcode_decoder.py
@@ -21,7 +21,7 @@
sys.stderr = sys.stdout
-def ConvertYuvToPngFiles(yuv_file_name, yuv_frame_width, yuv_frame_height,
+def convert_yuv_to_png_files(yuv_file_name, yuv_frame_width, yuv_frame_height,
output_directory, ffmpeg_path):
"""Converts a YUV video file into PNG frames.
@@ -61,7 +61,7 @@
return True
-def DecodeFrames(input_directory, zxing_path):
+def decode_frames(input_directory, zxing_path):
"""Decodes the barcodes overlaid in each frame.
The function uses the Zxing command-line tool from the Zxing C++ distribution
@@ -85,11 +85,11 @@
print 'Decoding barcodes from PNG files with %s...' % zxing_path
return helper_functions.perform_action_on_all_files(
directory=input_directory, file_pattern='frame_',
- file_extension='png', start_number=1, action=_DecodeBarcodeInFile,
+ file_extension='png', start_number=1, action=_decode_barcode_in_file,
command_line_decoder=zxing_path)
-def _DecodeBarcodeInFile(file_name, command_line_decoder):
+def _decode_barcode_in_file(file_name, command_line_decoder):
"""Decodes the barcode in the upper left corner of a PNG file.
Args:
@@ -116,7 +116,7 @@
return True
-def _GenerateStatsFile(stats_file_name, input_directory='.'):
+def _generate_stats_file(stats_file_name, input_directory='.'):
"""Generate statistics file.
The function generates a statistics file. The contents of the file are in the
@@ -128,7 +128,7 @@
stats_file = open(stats_file_name, 'w')
print 'Generating stats file: %s' % stats_file_name
- for i in range(1, _CountFramesIn(input_directory=input_directory) + 1):
+ for i in range(1, _count_frames_in(input_directory=input_directory) + 1):
frame_number = helper_functions.zero_pad(i)
barcode_file_name = file_prefix + frame_number + '.txt'
png_frame = file_prefix + frame_number + '.png'
@@ -136,10 +136,10 @@
entry = 'frame_' + entry_frame_number + ' '
if os.path.isfile(barcode_file_name):
- barcode = _ReadBarcodeFromTextFile(barcode_file_name)
+ barcode = _read_barcode_from_text_file(barcode_file_name)
os.remove(barcode_file_name)
- if _CheckBarcode(barcode):
+ if _check_barcode(barcode):
entry += (helper_functions.zero_pad(int(barcode[0:11])) + '\n')
else:
entry += 'Barcode error\n' # Barcode is wrongly detected.
@@ -152,7 +152,7 @@
stats_file.close()
-def _ReadBarcodeFromTextFile(barcode_file_name):
+def _read_barcode_from_text_file(barcode_file_name):
"""Reads the decoded barcode for a .txt file.
Args:
@@ -166,7 +166,7 @@
return barcode
-def _CheckBarcode(barcode):
+def _check_barcode(barcode):
"""Check weather the UPC-A barcode was decoded correctly.
This function calculates the check digit of the provided barcode and compares
@@ -200,7 +200,7 @@
return dsum == int(barcode[11])
-def _CountFramesIn(input_directory='.'):
+def _count_frames_in(input_directory='.'):
"""Calculates the number of frames in the input directory.
The function calculates the number of frames in the input directory. The
@@ -225,7 +225,7 @@
return num - 1
-def _ParseArgs():
+def _parse_args():
"""Registers the command-line options."""
usage = "usage: %prog [options]"
parser = optparse.OptionParser(usage=usage)
@@ -256,7 +256,7 @@
return options
-def main():
+def _main():
"""The main function.
A simple invocation is:
@@ -265,27 +265,27 @@
--yuv_frame_width=640 --yuv_frame_height=480
--stats_file=<path_and_name_to_stats_file>
"""
- options = _ParseArgs()
+ options = _parse_args()
# Convert the overlaid YUV video into a set of PNG frames.
- if not ConvertYuvToPngFiles(options.yuv_file, options.yuv_frame_width,
- options.yuv_frame_height,
- output_directory=options.png_working_dir,
- ffmpeg_path=options.ffmpeg_path):
+ if not convert_yuv_to_png_files(options.yuv_file, options.yuv_frame_width,
+ options.yuv_frame_height,
+ output_directory=options.png_working_dir,
+ ffmpeg_path=options.ffmpeg_path):
print 'An error occurred converting from YUV to PNG frames.'
return -1
# Decode the barcodes from the PNG frames.
- if not DecodeFrames(input_directory=options.png_working_dir,
- zxing_path=options.zxing_path):
+ if not decode_frames(input_directory=options.png_working_dir,
+ zxing_path=options.zxing_path):
print 'An error occurred decoding barcodes from PNG frames.'
return -2
# Generate statistics file.
- _GenerateStatsFile(options.stats_file,
- input_directory=options.png_working_dir)
+ _generate_stats_file(options.stats_file,
+ input_directory=options.png_working_dir)
print 'Completed barcode decoding.'
return 0
if __name__ == '__main__':
- sys.exit(main())
+ sys.exit(_main())
diff --git a/tools/barcode_tools/barcode_encoder.py b/tools/barcode_tools/barcode_encoder.py
index fb8b04d..3a8f354 100755
--- a/tools/barcode_tools/barcode_encoder.py
+++ b/tools/barcode_tools/barcode_encoder.py
@@ -17,9 +17,9 @@
_DEFAULT_BARCODES_FILE = 'barcodes.yuv'
-def GenerateUpcaBarcodes(number_of_barcodes, barcode_width, barcode_height,
- output_directory='.',
- path_to_zxing='zxing-read-only'):
+def generate_upca_barcodes(number_of_barcodes, barcode_width, barcode_height,
+ output_directory='.',
+ path_to_zxing='zxing-read-only'):
"""Generates UPC-A barcodes.
This function generates a number_of_barcodes UPC-A barcodes. The function
@@ -39,7 +39,7 @@
(bool): True if the conversion is successful.
"""
base_file_name = os.path.join(output_directory, "barcode_")
- jars = _FormJarsString(path_to_zxing)
+ jars = _form_jars_string(path_to_zxing)
command_line_encoder = 'com.google.zxing.client.j2se.CommandLineEncoder'
barcode_width = str(barcode_width)
barcode_height = str(barcode_height)
@@ -64,7 +64,7 @@
return not errors
-def ConvertPngToYuvBarcodes(input_directory='.', output_directory='.'):
+def convert_png_to_yuv_barcodes(input_directory='.', output_directory='.'):
"""Converts PNG barcodes to YUV barcode images.
This function reads all the PNG files from the input directory which are in
@@ -79,11 +79,11 @@
(bool): True if the conversion was without errors.
"""
return helper_functions.perform_action_on_all_files(
- input_directory, 'barcode_', 'png', 0, _ConvertToYuvAndDelete,
+ input_directory, 'barcode_', 'png', 0, _convert_to_yuv_and_delete,
output_directory=output_directory, pattern='barcode_')
-def _ConvertToYuvAndDelete(output_directory, file_name, pattern):
+def _convert_to_yuv_and_delete(output_directory, file_name, pattern):
"""Converts a PNG file to a YUV file and deletes the PNG file.
Args:
@@ -116,7 +116,7 @@
return True
-def CombineYuvFramesIntoOneFile(output_file_name, input_directory='.'):
+def combine_yuv_frames_into_one_file(output_file_name, input_directory='.'):
"""Combines several YUV frames into one YUV video file.
The function combines the YUV frames from input_directory into one YUV video
@@ -132,12 +132,12 @@
"""
output_file = open(output_file_name, "wb")
success = helper_functions.perform_action_on_all_files(
- input_directory, 'barcode_', 'yuv', 0, _AddToFileAndDelete,
+ input_directory, 'barcode_', 'yuv', 0, _add_to_file_and_delete,
output_file=output_file)
output_file.close()
return success
-def _AddToFileAndDelete(output_file, file_name):
+def _add_to_file_and_delete(output_file, file_name):
"""Adds the contents of a file to a previously opened file.
Args:
@@ -159,9 +159,9 @@
return True
-def _OverlayBarcodeAndBaseFrames(barcodes_file, base_file, output_file,
- barcodes_component_sizes,
- base_component_sizes):
+def _overlay_barcode_and_base_frames(barcodes_file, base_file, output_file,
+ barcodes_component_sizes,
+ base_component_sizes):
"""Overlays the next YUV frame from a file with a barcode.
Args:
@@ -201,8 +201,8 @@
return True
-def OverlayYuvFiles(barcode_width, barcode_height, base_width, base_height,
- barcodes_file_name, base_file_name, output_file_name):
+def overlay_yuv_files(barcode_width, barcode_height, base_width, base_height,
+ barcodes_file_name, base_file_name, output_file_name):
"""Overlays two YUV files starting from the upper left corner of both.
Args:
@@ -230,17 +230,17 @@
data_left = True
while data_left:
- data_left = _OverlayBarcodeAndBaseFrames(barcodes_file, base_file,
- output_file,
- barcodes_component_sizes,
- base_component_sizes)
+ data_left = _overlay_barcode_and_base_frames(barcodes_file, base_file,
+ output_file,
+ barcodes_component_sizes,
+ base_component_sizes)
barcodes_file.close()
base_file.close()
output_file.close()
-def CalculateFramesNumberFromYuv(yuv_width, yuv_height, file_name):
+def calculate_frames_number_from_yuv(yuv_width, yuv_height, file_name):
"""Calculates the number of frames of a YUV video.
Args:
@@ -258,7 +258,7 @@
return int(file_size/frame_size) # Should be int anyway
-def _FormJarsString(path_to_zxing):
+def _form_jars_string(path_to_zxing):
"""Forms the the Zxing core and javase jars argument.
Args:
@@ -273,7 +273,7 @@
delimiter = ';'
return javase_jar + delimiter + core_jar
-def _ParseArgs():
+def _parse_args():
"""Registers the command-line options."""
usage = "usage: %prog [options]"
parser = optparse.OptionParser(usage=usage)
@@ -320,7 +320,7 @@
return options
-def main():
+def _main():
"""The main function.
A simple invocation will be:
@@ -329,7 +329,7 @@
--base_yuv=<path_and_name_of_base_file>
--output_yuv=<path and name_of_output_file>
"""
- options = _ParseArgs()
+ options = _parse_args()
# The barcodes with will be different than the base frame width only if
# explicitly specified at the command line.
if options.barcode_width == _DEFAULT_BARCODE_WIDTH:
@@ -342,26 +342,26 @@
# Calculate the number of barcodes - it is equal to the number of frames in
# the base file.
- number_of_barcodes = CalculateFramesNumberFromYuv(
+ number_of_barcodes = calculate_frames_number_from_yuv(
options.base_frame_width, options.base_frame_height, options.base_yuv)
script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
zxing_dir = os.path.join(script_dir, 'third_party', 'zxing')
# Generate barcodes - will generate them in PNG.
- GenerateUpcaBarcodes(number_of_barcodes, options.barcode_width,
- options.barcode_height,
- output_directory=options.png_barcodes_output_dir,
- path_to_zxing=zxing_dir)
+ generate_upca_barcodes(number_of_barcodes, options.barcode_width,
+ options.barcode_height,
+ output_directory=options.png_barcodes_output_dir,
+ path_to_zxing=zxing_dir)
# Convert the PNG barcodes to to YUV format.
- ConvertPngToYuvBarcodes(options.png_barcodes_input_dir,
- options.yuv_barcodes_output_dir)
+ convert_png_to_yuv_barcodes(options.png_barcodes_input_dir,
+ options.yuv_barcodes_output_dir)
# Combine the YUV barcodes into one YUV file.
- CombineYuvFramesIntoOneFile(options.barcodes_yuv,
- input_directory=options.yuv_frames_input_dir)
+ combine_yuv_frames_into_one_file(options.barcodes_yuv,
+ input_directory=options.yuv_frames_input_dir)
# Overlay the barcodes over the base file.
- OverlayYuvFiles(options.barcode_width, options.barcode_height,
- options.base_frame_width, options.base_frame_height,
- options.barcodes_yuv, options.base_yuv, options.output_yuv)
+ overlay_yuv_files(options.barcode_width, options.barcode_height,
+ options.base_frame_width, options.base_frame_height,
+ options.barcodes_yuv, options.base_yuv, options.output_yuv)
if not keep_barcodes_yuv_file:
# Remove the temporary barcodes YUV file
@@ -369,4 +369,4 @@
if __name__ == '__main__':
- sys.exit(main())
+ sys.exit(_main())
diff --git a/tools/barcode_tools/build_zxing.py b/tools/barcode_tools/build_zxing.py
index 92696a7..466bd50 100755
--- a/tools/barcode_tools/build_zxing.py
+++ b/tools/barcode_tools/build_zxing.py
@@ -12,7 +12,7 @@
import sys
-def RunAntBuildCommand(path_to_ant_build_file):
+def run_ant_build_command(path_to_ant_build_file):
"""Tries to build the passed build file with ant."""
ant_executable = 'ant'
if sys.platform == 'win32':
@@ -32,13 +32,13 @@
e)
return -1
-def main():
+def _main():
core_build = os.path.join('third_party', 'zxing', 'core', 'build.xml')
- RunAntBuildCommand(core_build)
+ run_ant_build_command(core_build)
javase_build = os.path.join('third_party', 'zxing', 'javase', 'build.xml')
- return RunAntBuildCommand(javase_build)
+ return run_ant_build_command(javase_build)
if __name__ == '__main__':
- sys.exit(main())
+ sys.exit(_main())
diff --git a/tools/barcode_tools/helper_functions.py b/tools/barcode_tools/helper_functions.py
index e27322f..fb9854f 100644
--- a/tools/barcode_tools/helper_functions.py
+++ b/tools/barcode_tools/helper_functions.py
@@ -20,7 +20,7 @@
pass
-def ZeroPad(number, padding=_DEFAULT_PADDING):
+def zero_pad(number, padding=_DEFAULT_PADDING):
"""Converts an int into a zero padded string.
Args:
@@ -35,7 +35,7 @@
return str(number).zfill(padding)
-def RunShellCommand(cmd_list, fail_msg=None):
+def run_shell_command(cmd_list, fail_msg=None):
"""Executes a command.
Args:
@@ -60,8 +60,8 @@
return output.strip()
-def PerformActionOnAllFiles(directory, file_pattern, file_extension,
- start_number, action, **kwargs):
+def perform_action_on_all_files(directory, file_pattern, file_extension,
+ start_number, action, **kwargs):
"""Function that performs a given action on all files matching a pattern.
It is assumed that the files are named file_patternxxxx.file_extension, where
@@ -86,7 +86,7 @@
process_pool = multiprocessing.Pool(processes=multiprocessing.cpu_count())
results = []
while True:
- zero_padded_file_number = ZeroPad(file_number)
+ zero_padded_file_number = zero_pad(file_number)
file_name = file_prefix + zero_padded_file_number + '.' + file_extension
if not os.path.isfile(file_name):
break
diff --git a/tools/barcode_tools/yuv_cropper.py b/tools/barcode_tools/yuv_cropper.py
index 609f07d..c57a90d 100755
--- a/tools/barcode_tools/yuv_cropper.py
+++ b/tools/barcode_tools/yuv_cropper.py
@@ -12,7 +12,7 @@
import sys
-def _CropOneFrame(yuv_file, output_file, component_sizes):
+def _crop_one_frame(yuv_file, output_file, component_sizes):
"""Crops one frame.
This function crops one frame going through all the YUV planes and cropping
@@ -44,7 +44,7 @@
return True
-def CropFrames(yuv_file_name, output_file_name, width, height, crop_height):
+def crop_frames(yuv_file_name, output_file_name, width, height, crop_height):
"""Crops rows of pixels from the top of the YUV frames.
This function goes through all the frames in a video and crops the crop_height
@@ -69,13 +69,13 @@
data_left = True
while data_left:
- data_left = _CropOneFrame(yuv_file, output_file, component_sizes)
+ data_left = _crop_one_frame(yuv_file, output_file, component_sizes)
yuv_file.close()
output_file.close()
-def _ParseArgs():
+def _parse_args():
"""Registers the command-line options."""
usage = "usage: %prog [options]"
parser = optparse.OptionParser(usage=usage)
@@ -101,7 +101,7 @@
return options
-def main():
+def _main():
"""A tool to crop rows of pixels from the top part of a YUV file.
A simple invocation will be:
@@ -109,17 +109,17 @@
--yuv_file=<path_and_name_of_yuv_file>
--output_yuv=<path and name_of_output_file>
"""
- options = _ParseArgs()
+ options = _parse_args()
if os.path.getsize(options.yuv_file) == 0:
sys.stderr.write('Error: The YUV file you have passed has size 0. The '
'produced output will also have size 0.\n')
return -1
- CropFrames(options.yuv_file, options.output_file, options.width,
- options.height, options.crop_height)
+ crop_frames(options.yuv_file, options.output_file, options.width,
+ options.height, options.crop_height)
return 0
if __name__ == '__main__':
- sys.exit(main())
+ sys.exit(_main())